Learn R Programming

CoordinateCleaner (version 3.0.1)

cc_coun: Identify Coordinates Outside their Reported Country

Description

Removes or flags mismatches between geographic coordinates and additional country information (usually this information is reliably reported with specimens). Such a mismatch can occur for example, if latitude and longitude are switched.

Usage

cc_coun(
  x,
  lon = "decimalLongitude",
  lat = "decimalLatitude",
  iso3 = "countrycode",
  value = "clean",
  ref = NULL,
  ref_col = "iso_a3",
  verbose = TRUE,
  buffer = NULL
)

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”.

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”.

iso3

a character string. The column with the country assignment of each record in three letter ISO code. Default = “countrycode”.

value

character string. Defining the output value. See value.

ref

SpatVector (geometry: polygons). Providing the geographic gazetteer. Can be any SpatVector (geometry: polygons), but the structure must be identical to rnaturalearth::ne_countries(scale = "medium", returnclass = "sf"). Default = rnaturalearth::ne_countries(scale = "medium", returnclass = "sf")

ref_col

the column name in the reference dataset, containing the relevant ISO codes for matching. Default is to "iso_a3_eh" which refers to the ISO-3 codes in the reference dataset. See notes.

verbose

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

buffer

numeric. Units are in meters. If provided, a buffer is created around each country polygon.

See Also

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

Examples

Run this code

if (FALSE) {
x <- data.frame(species = letters[1:10],
                decimalLongitude = runif(100, -20, 30),
                decimalLatitude = runif(100, 35,60),
                countrycode = "RUS")

cc_coun(x, value = "flagged")#non-terrestrial records are flagged as wrong.
}

Run the code above in your browser using DataLab