Closed edgagnon closed 5 years ago
Hi,
this is related to the internal structure of the reference dataset, which needs to be identical to the structure of the naturalearth medium resolution. You can easily fix this if you adapt the column names of your reference. If you use the latest version of CoordinateCleaner (2.0-6), just rename the column with the ISO-3 values by "iso_a3_eh" (you seem to be using an older version, where it is "iso_a3").
#This gets the high resolution map
library(raster)
library(CoordinateCleaner)
# Reference data
getData("countries")->world
# Renaming the column
names(world)[names(world) == "ISO"] <- "iso_a3_eh"
# Simulate some data
dat <- data.frame(species = rep("Adansonia digitata",2),
decimalLongitude = c(12, 18.3),
decimalLatitude = c(55.5, 59.4),
countryCode = rep("DNK", 2))
# Now working
flags <- clean_coordinates(x = dat, lon = "decimalLongitude", lat = "decimalLatitude",
countries = "countryCode",
species = "species",
tests = c("capitals", "centroids", "equal","gbif", "institutions",
"zeros", "countries"),
country_ref=world)
Cheers
Hello, I've been trying to use different maps than the ones from the rnaturalearth package, to determine whether my species fall within the correct country. I have been trying to use a higher resolution map from the Raster package, getData("countries"), but it's been failing.
Here is an example of what I've been trying to do, based on your tutorials:
This gets the high resolution map
library(raster) getData("countries")->world
Here I follow your example, until I get to the clean_coordinate function, and call this map to check for
dat <- data.frame(dat) flags <- clean_coordinates(x = dat, lon = "decimalLongitude", lat = "decimalLatitude", countries = "countryCode", species = "species", tests = c("capitals", "centroids", "equal","gbif", "institutions", "zeros", "countries"), country_ref=world) # most test are on by default
Testing coordinate validity
Flagged 0 records.
Testing equal lat/lon
Flagged 9 records.
Testing zero coordinates
Flagged 7 records.
Testing country capitals
Flagged 13 records.
Testing country centroids
Flagged 11 records.
Testing country identity
Error in
[.data.frame
(sp::over(x = dat, y = ref), , "iso_a3") :undefined columns selected
When I check the source code, I think the error is coming from the fact that in the object "world", whatever is indicated as iso_a3 is named as something else. I could be wrong.
I've been getting different type of issues trying it out with data(wlrd_simpl), as well as the rnaturalearthhires package (iso_a3 is in capital letters for those maps). Anyways, it looks like your function only works with the maps from the rnaturalearth package, which i find a bit frustrating.
If you can think of an easy way of fixing this, would be appreciated.