Uses spatial comparison to determine which country polygons the locations fall into and returns the country code strings for those polygons.
Specification of countryCodes
limits spatial searching to the
specified countries and greatly improves performance.
If allData = TRUE
, additional data is returned.
getCountryCode(
longitude = NULL,
latitude = NULL,
datasetName = "SimpleCountriesEEZ",
countryCodes = NULL,
allData = FALSE,
useBuffering = FALSE
)
Vector of longitudes in decimal degrees East.
Vector of latitudes in decimal degrees North.
Name of spatial dataset to use.
Vector of ISO 3166-1 alpha-2 country codes.
Logical specifying whether a full dataframe should be returned.
Logical flag specifying the use of location buffering to find the nearest polygon if no target polygon is found.
Vector of ISO-3166-1 alpha-2 country codes.
http://www.naturalearthdata.com/downloads/10m-cultural-vectors/
SimpleCountries
getSpatialData
library(MazamaSpatialUtils)
longitude <- seq(0, 50)
latitude <- seq(0, 50)
getCountryCode(longitude, latitude)
#> [1] NA NA NA "NG" "NG" "NG" "NG" "NG" "NG" "NG" "NG" "NG" "NG" "NG" "TD"
#> [16] "TD" "TD" "TD" "TD" "TD" "TD" "TD" "LY" "LY" "LY" "LY" "EG" "EG" "EG" "EG"
#> [31] "EG" "EG" "EG" "CY" "CY" "SY" "TR" "TR" "TR" "TR" "TR" "TR" "GE" "GE" "RU"
#> [46] "RU" "RU" "RU" "KZ" "KZ" "KZ"