Uses spatial comparison to determine which country polygons the locations fall into and returns the country name for those polygons.

Specification of countryCodes limits spatial searching to the specified countries and greatly improves performance.

If allData = TRUE, additional data is returned.

getCountryName(
  longitude = NULL,
  latitude = NULL,
  datasetName = "SimpleCountriesEEZ",
  countryCodes = NULL,
  allData = FALSE,
  useBuffering = FALSE
)

Arguments

longitude

Vector of longitudes in decimal degrees East.

latitude

Vector of latitudes in decimal degrees North.

datasetName

Name of spatial dataset to use.

countryCodes

Vector of ISO 3166-1 alpha-2 country codes.

allData

Logical specifying whether a full dataframe should be returned.

useBuffering

Logical flag specifying the use of location buffering to find the nearest polygon if no target polygon is found.

Value

Vector of English language country names.

See also

SimpleCountries

getSpatialData

Examples

library(MazamaSpatialUtils)

longitude <- seq(0, 50)
latitude <- seq(0, 50)

getCountryName(longitude, latitude)
#>  [1] NA           NA           NA           "Nigeria"    "Nigeria"   
#>  [6] "Nigeria"    "Nigeria"    "Nigeria"    "Nigeria"    "Nigeria"   
#> [11] "Nigeria"    "Nigeria"    "Nigeria"    "Nigeria"    "Chad"      
#> [16] "Chad"       "Chad"       "Chad"       "Chad"       "Chad"      
#> [21] "Chad"       "Chad"       "Libya"      "Libya"      "Libya"     
#> [26] "Libya"      "Egypt"      "Egypt"      "Egypt"      "Egypt"     
#> [31] "Egypt"      "Egypt"      "Egypt"      "Cyprus"     "Cyprus"    
#> [36] "Syria"      "Turkey"     "Turkey"     "Turkey"     "Turkey"    
#> [41] "Turkey"     "Turkey"     "Georgia"    "Georgia"    "Russia"    
#> [46] "Russia"     "Russia"     "Russia"     "Kazakhstan" "Kazakhstan"
#> [51] "Kazakhstan"