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. Default = TRUE. See https://seethedatablog.wordpress.com/ for detail and credits.
- ref
SpatVector (geometry: polygons). Providing the geographic gazetteer. Can be any SpatVector (geometry: polygons), 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.
Examples
x <- data.frame(species = letters[1:10],
decimalLongitude = c(runif(99, -180, 180), -47.882778),
decimalLatitude = c(runif(99, -90, 90), -15.793889))
cc_cap(x)
#> Testing country capitals
#> Removed 1 records.
#> species decimalLongitude decimalLatitude
#> 1 a -92.607638 -5.996438
#> 2 b 40.522113 -79.465774
#> 3 c 90.034228 28.152831
#> 4 d 168.826082 -6.102938
#> 5 e -88.646816 87.270836
#> 6 f 84.612043 -74.918801
#> 7 g 161.079393 53.944504
#> 8 h -105.999107 1.444920
#> 9 i -14.320395 32.169190
#> 10 j -29.318435 -15.529752
#> 11 a -91.570891 42.614363
#> 12 b 83.934840 11.859488
#> 13 c -50.800478 68.165959
#> 14 d 36.828912 70.440573
#> 15 e 98.865911 -81.716130
#> 16 f 104.178390 -12.525012
#> 17 g -130.364324 -72.671931
#> 18 h 35.830367 14.861063
#> 19 i -172.800437 74.504034
#> 20 j -78.353906 -32.869328
#> 21 a -28.520564 -12.974163
#> 22 b 142.774080 -29.942270
#> 23 c -150.258230 -51.044604
#> 24 d -17.232478 68.234378
#> 25 e -53.494199 -83.896729
#> 26 f 44.371627 60.133687
#> 27 g -27.951247 20.217304
#> 28 h 7.944481 -20.271514
#> 29 i -58.472099 -60.812561
#> 30 j 152.063770 -68.833307
#> 31 a -49.674430 77.502218
#> 32 b 176.282705 -29.865387
#> 33 c 131.010041 24.255692
#> 34 d -5.265711 82.161322
#> 35 e -9.349644 38.193836
#> 36 f 149.794170 -66.540099
#> 37 g 173.407071 -49.399314
#> 38 h 68.839542 -51.625032
#> 39 i -74.081901 47.592418
#> 40 j -168.568974 86.129046
#> 41 a -21.825690 44.295348
#> 42 b -46.165425 68.824765
#> 43 c 76.101985 -19.305533
#> 44 d -113.398005 42.743804
#> 45 e -93.555205 -84.001891
#> 46 f -15.660688 -32.982976
#> 47 g 119.583447 -44.799649
#> 48 h 69.642734 55.112691
#> 49 i -45.852325 -33.420531
#> 50 j -35.978601 49.761147
#> 51 a 162.920229 9.204813
#> 52 b 160.386271 25.689020
#> 53 c -39.727795 -83.910295
#> 54 d -138.677488 -51.085238
#> 55 e 178.920689 37.279186
#> 56 f -17.066374 15.858207
#> 57 g 19.543498 -56.697273
#> 58 h -157.698082 86.308834
#> 59 i -139.723475 -17.425260
#> 60 j -151.234216 10.174405
#> 61 a -60.833642 86.013284
#> 62 b 142.730275 71.824574
#> 63 c -109.051807 71.970611
#> 64 d 68.428210 9.383669
#> 65 e 151.990032 -87.959266
#> 66 f -47.973758 -17.595455
#> 67 g 173.648633 -61.683285
#> 68 h 44.092239 -7.168434
#> 69 i -140.550874 -33.837434
#> 70 j -54.838974 75.700651
#> 71 a -13.986059 4.968147
#> 72 b -48.431900 -52.003847
#> 73 c 43.119921 30.173858
#> 74 d 93.970538 59.463413
#> 75 e 23.879300 -21.749635
#> 76 f -139.755584 82.288063
#> 77 g -53.706688 -48.162050
#> 78 h 43.569205 46.819935
#> 79 i 127.297826 -61.919684
#> 80 j 102.560446 -27.509373
#> 81 a 111.888282 -81.181955
#> 82 b 120.200644 -74.236000
#> 83 c 55.048343 53.943526
#> 84 d 95.791186 78.925373
#> 85 e 117.720641 35.080123
#> 86 f -28.267533 -73.148819
#> 87 g -37.023769 7.032676
#> 88 h -126.236356 -84.210832
#> 89 i -32.304128 88.205064
#> 90 j -166.763776 9.504552
#> 91 a 149.640678 -3.607304
#> 92 b -67.428145 -80.296232
#> 93 c 50.902892 73.568669
#> 94 d 67.355528 86.761693
#> 95 e 84.288962 89.141497
#> 96 f 71.767170 -45.934631
#> 97 g 172.745542 -40.745723
#> 98 h -54.904414 7.774398
#> 99 i -130.963728 12.493447
cc_cap(x, value = "flagged")
#> Testing country capitals
#> Flagged 1 records.
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [13] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [25] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [37] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [49] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [61] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [73] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [85] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [97] TRUE TRUE TRUE FALSE