Skip to contents

Removes or flags records within a certain radius around country capitals. Poorly geo-referenced occurrence records in biological databases are often erroneously geo-referenced to capitals.

Usage

cc_cap(
  x,
  lon = "decimallongitude",
  lat = "decimallatitude",
  species = "species",
  buffer = 10000,
  geod = TRUE,
  ref = NULL,
  verify = FALSE,
  value = "clean",
  verbose = TRUE
)

Arguments

x

data.frame. Containing geographical coordinates and species names.

lon

character string. The column with the longitude coordinates. Default = “decimallongitude”.

lat

character string. The column with the latitude coordinates. Default = “decimallatitude”.

species

character string. The column with the species identity. Only required if verify = TRUE.

buffer

The buffer around each capital coordinate (the centre of the city), where records should be flagged as problematic. Units depend on geod. Default = 10 kilometres.

geod

logical. If TRUE the radius around each capital is calculated based on a sphere, buffer is in meters and independent of latitude. If FALSE the radius is calculated assuming planar coordinates and varies slightly with latitude, in this case buffer is in degrees. Default = TRUE. See https://seethedatablog.wordpress.com/ for detail and credits.

ref

SpatialPointsDataFrame. Providing the geographic gazetteer. Can be any SpatialPointsDataFrame, but the structure must be identical to countryref. Default = countryref.

verify

logical. If TRUE records are only flagged if they are the only record in a given species flagged close to a given reference. If FALSE, the distance is the only criterion

value

character string. Defining the output value. See value.

verbose

logical. If TRUE reports the name of the test and the number of records flagged.

Value

Depending on the ‘value’ argument, either a data.frame

containing the records considered correct by the test (“clean”) or a logical vector (“flagged”), with TRUE = test passed and FALSE = test failed/potentially problematic . Default = “clean”.

Note

See https://ropensci.github.io/CoordinateCleaner/ for more details and tutorials.

See also

Other Coordinates: cc_cen(), cc_coun(), cc_dupl(), cc_equ(), cc_gbif(), cc_inst(), cc_iucn(), cc_outl(), cc_sea(), cc_urb(), cc_val(), cc_zero()

Examples


x <- data.frame(species = letters[1:10], 
                decimallongitude = runif(100, -180, 180), 
                decimallatitude = runif(100, -90,90))

cc_cap(x)
#> Testing country capitals
#> Removed 0 records.
#>     species decimallongitude decimallatitude
#> 1         a       130.598152     -53.5625313
#> 2         b        -7.029613     -88.8441041
#> 3         c        40.306636      45.7979496
#> 4         d       177.087661      58.2112314
#> 5         e        27.017149     -48.1496593
#> 6         f       177.036960      46.0878979
#> 7         g       -83.278309     -43.1236190
#> 8         h        69.613065     -75.0306081
#> 9         i       141.876266     -82.3772927
#> 10        j      -116.733658      68.3997894
#> 11        a        14.705996     -10.7627747
#> 12        b      -132.192692      38.5557331
#> 13        c       -59.234198      67.2892694
#> 14        d      -100.775744     -89.7308427
#> 15        e       153.880183     -38.6406224
#> 16        f        74.760758      42.9598550
#> 17        g       -81.448348      63.4115978
#> 18        h        20.011729      87.8391584
#> 19        i       -75.741761     -34.2478881
#> 20        j       112.990750      52.8829687
#> 21        a        81.805461     -85.9516089
#> 22        b       -35.157623     -56.2446269
#> 23        c       132.744031      42.3945971
#> 24        d       -39.920522     -22.9097037
#> 25        e        70.551068      51.5402860
#> 26        f       -84.833681      56.6617511
#> 27        g        96.907936     -82.6038318
#> 28        h       -41.592077      18.6247396
#> 29        i       -77.489299     -39.1263494
#> 30        j      -119.905618     -46.2926296
#> 31        a      -105.523912      -9.9072769
#> 32        b      -127.148990      20.2487969
#> 33        c        48.240420      11.9546451
#> 34        d        10.846654      28.4632870
#> 35        e      -114.783553      55.5180408
#> 36        f       -39.226539      14.6253024
#> 37        g        85.701585      34.0953174
#> 38        h      -134.589907     -34.3421685
#> 39        i       146.033785     -10.9893034
#> 40        j      -135.149861      20.9706037
#> 41        a       166.378801     -27.3879876
#> 42        b       102.545615       6.3709695
#> 43        c        41.600750      65.2677749
#> 44        d      -165.439328      78.5859378
#> 45        e       153.470107      13.0890271
#> 46        f        41.270826     -26.6374363
#> 47        g        98.618769     -12.4844048
#> 48        h      -129.137593      -7.7895008
#> 49        i        99.311564     -19.0026846
#> 50        j       153.704068     -41.9324982
#> 51        a       -76.067514      -6.1317321
#> 52        b       171.851992     -28.9861717
#> 53        c        35.709439      16.8744371
#> 54        d        46.164498     -68.1182139
#> 55        e       -68.084173     -89.4538394
#> 56        f       -96.774031      -7.6440439
#> 57        g       151.508670      56.2716765
#> 58        h       161.745642      15.0282230
#> 59        i       176.523619      59.6024311
#> 60        j        36.383901      87.2565670
#> 61        a       -25.803044      69.5313806
#> 62        b        34.127613     -50.1576536
#> 63        c        -1.641263     -56.9921824
#> 64        d        89.603812      63.4444321
#> 65        e       113.985291      -0.0722344
#> 66        f        47.942680      85.6516235
#> 67        g       -75.358567      74.3506676
#> 68        h       -23.693901      31.7516960
#> 69        i      -160.451776      63.7323145
#> 70        j       -45.138146      56.4882394
#> 71        a       -36.519212      42.1955911
#> 72        b         2.981604      58.7121455
#> 73        c       166.913033      -8.5266048
#> 74        d      -129.995662     -27.7428102
#> 75        e      -103.438977     -80.7760740
#> 76        f        18.328308     -70.9442356
#> 77        g      -169.136250      29.1842748
#> 78        h       -70.857180      36.8828364
#> 79        i       175.437445      25.2791784
#> 80        j       -69.264349      41.5779763
#> 81        a      -147.490866       0.4426015
#> 82        b        80.075221      25.2258545
#> 83        c       115.176848       7.4257117
#> 84        d      -150.493627     -46.6059027
#> 85        e      -121.698279     -75.0056638
#> 86        f       -11.504510       0.1902900
#> 87        g       123.118028     -26.8328663
#> 88        h        93.461048     -25.9695779
#> 89        i       143.833574      62.6536190
#> 90        j        58.527603      77.0283763
#> 91        a       120.786684     -18.5805093
#> 92        b       -24.436508       6.0610409
#> 93        c       161.950213      -1.5611306
#> 94        d       -36.867876      40.1193254
#> 95        e       109.242497      10.6642354
#> 96        f       164.430161     -84.6113214
#> 97        g       -37.966638      73.9046077
#> 98        h      -159.265873      -2.7712655
#> 99        i      -149.539700      15.7999622
#> 100       j       -53.513992      84.0743730
cc_cap(x, value = "flagged")
#> Testing country capitals
#> Flagged 0 records.
#>    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96 
#> TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE 
#>   97   98   99  100 
#> TRUE TRUE TRUE TRUE