Flags coordinates that are inconsistent with the stated country name
Source:R/jbd_coordCountryInconsistent.R
      jbd_coordCountryInconsistent.RdCompares stated country name in an occurrence record with record's coordinates using
rnaturalearth data. The prefix, jbd_ is meant
to distinguish this function from the original bdc::bdc_coordinates_country_inconsistent().
This functions will preferably use the countryCode and country_suggested columns
generated by bdc::bdc_country_standardized(); please run it on your dataset prior to running
this function.
Usage
jbd_coordCountryInconsistent(
  data = NULL,
  lon = "decimalLongitude",
  lat = "decimalLatitude",
  scale = 50,
  pointBuffer = 0.01,
  stepSize = 1e+06,
  mc.cores = 1
)Arguments
- data
- A data frame or tibble. Occurrence records as input. 
- lon
- Character. The name of the column to use as longitude. Default = "decimalLongitude". 
- lat
- Character. The name of the column to use as latitude. Default = "decimalLatitude". 
- scale
- Numeric or character. To be passed to - rnaturalearth::ne_countries()'s scale. Scale of map to return, one of 110, 50, 10 or "small", "medium", "large". Smaller values return higher-resolution maps.
- pointBuffer
- Numeric. Amount to buffer points, in decimal degrees. If the point is outside of a country, but within this point buffer, it will not be flagged. Default = 0.01. 
- stepSize
- Numeric. The number of occurrences to process in each chunk. Default = 1000000. 
- mc.cores
- Numeric. If > 1, the st_intersects function will run in parallel using mclapply using the number of cores specified. If = 1 then it will be run using a serial loop. NOTE: Windows machines must use a value of 1 (see ?parallel::mclapply). Additionally, be aware that each thread can use large chunks of memory. Default = 1. 
Examples
if(requireNamespace("rnaturalearthdata")){
beesRaw_out <- jbd_coordCountryInconsistent(
  data = BeeBDC::beesRaw,
  lon = "decimalLongitude",
  lat = "decimalLatitude",
  scale = 50,
  pointBuffer = 0.01)
} # END if require
#> No '.coordinates_outOfRange' column found, running bdc_coordinates_outOfRange...
#> 
#> bdc_coordinates_outOfRange:
#> Flagged 0 records.
#> One column was added to the database.
#> No '.coordinates_empty' column found, running bdc_coordinates_empty
#> 
#> bdc_coordinates_empty:
#> Flagged 23 records.
#> One column was added to the database.
#> No 'country_suggested' column found, adding an empty (NA) placeholder. This column can be added by running bdc::bdc_country_standardized() on the input data.
#> No 'countryCode' column found, adding an empty (NA) placeholder. This column can be added by running bdc::bdc_country_standardized() on the input data.
#>  - Downloading naturalearth map...
#> Spherical geometry (s2) switched off
#>  - Extracting initial country names without buffer...
#>  - Buffering naturalearth map by pointBuffer...
#> dist is assumed to be in decimal degrees (arc_degrees).
#>  - Extracting FAILED country names WITH buffer...
#> 
#> jbd_coordinates_country_inconsistent:
#> Flagged 2 records.
#> The column, '.coordinates_country_inconsistent', was added to the database.
#>  - Completed in 1.22 secs