This function flags geographic coordinates within a reference country. A spatial buffer can be added to the reference country to ensure that records in mangroves, marshes, estuaries, and records with low coordinate precision are not flagged as invalid.

bdc_coordinates_country_inconsistent(
  data,
  country_name,
  country = "country_suggested",
  lat = "decimalLatitude",
  lon = "decimalLongitude",
  dist = 0.1
)

Arguments

data

data.frame. Containing longitude and latitude. Coordinates must be expressed in decimal degrees and WGS84.

country_name

character string. Name of the country or countries to be considered.

country

character string. The column name with the country assignment of each record. It is recommended use a column with corrected and homogenized country names. Default = "country_suggested".

lat

character string. The column name with the latitude coordinates. Default = "decimalLatitude".

lon

character string. The column name with the longitude coordinates. Default = "decimalLongitude".

dist

numeric. The distance in decimal degrees used to created a buffer around the country. Default = 0.1 (~11 km at the equator).

Value

A data.frame containing the column '.coordinates_country_inconsistent'. Compliant (TRUE) if coordinates fall within the boundaries plus a specified distance (if 'dist' is supplied) of 'country_name'; otherwise "FALSE", including records whose country is missing or is not one of 'country_name' (see Details).

Details

Multiple countries can be informed, but they are tested separately. The distance reported in the argument 'dist' is used to create a buffer around the reference country. Records within the reference country or at a specified distance from the coastline of the reference country (i.e., records within the buffer) are flagged as valid (TRUE). Note that records within the buffer but in other countries are flagged as invalid (FALSE). Records with invalid (e.g., NA or empty) and out-of-range coordinates are not tested and returned as TRUE.

Only records whose country matches one of country_name are tested. Records assigned to another country, or with no country (NA or empty), are flagged as invalid (FALSE), even when their coordinates fall within the reference country. To test records without a country name, fill it from their coordinates first with bdc_country_from_coordinates().

Examples

if (FALSE) { # \dontrun{
x <- data.frame(
  country = c("Brazil", "Brazil", "Bolivia", "Argentina", "Peru"),
  decimalLongitude = c(-40.6003, -39.6, -77.689288, NA, -76.352930),
  decimalLatitude = c(-19.9358, -13.016667, -20.5243, -35.345940, -11.851872)
)

bdc_coordinates_country_inconsistent(
  data = x,
  country_name = c("Brazil", "Peru", "Argentina"),
  country = "country",
  lon = "decimalLongitude",
  lat = "decimalLatitude",
  dist = 0.1
)
} # }