CoordinateCleaner
CoordinateCleaner copied to clipboard
Error in h(simpleError(msg, call)) : error in evaluating the argument 'obj' in selecting a method for function 'coordinates':
Same problem here. I just used the example given for Panthera leo (https://ropensci.github.io/CoordinateCleaner/articles/Cleaning_GBIF_data_with_CoordinateCleaner.html) and got the same error message:
library(countrycode)
library(CoordinateCleaner)
library(dplyr)
library(ggplot2)
library(rgbif)
library(sp)
#obtain data from GBIF via rgbif
dat <- occ_search(scientificName = "Panthera leo", limit = 5000, hasCoordinate = T)
dat <- dat$data
names(dat) #a lot of columns
#select columns of interest
dat <- dat %>%
dplyr::select(species, decimalLongitude, decimalLatitude, countryCode, individualCount,
gbifID, family, taxonRank, coordinateUncertaintyInMeters, year,
basisOfRecord, institutionCode, datasetName)
remove records without coordinates
dat <- dat%>%
filter(!is.na(decimalLongitude))%>%
filter(!is.na(decimalLatitude))
#to avoid specifying it in each function
names(dat)[2:3] <- c("decimallongitude", "decimallatitude")
clean <- dat%>%
cc_val()%>%
cc_equ()%>%
cc_cap()%>%
cc_cen()%>%
cc_coun(iso3 = "countryCode")%>%
cc_gbif()%>%
cc_inst()%>%
cc_sea()%>%
cc_zero()%>%
cc_outl()%>%
cc_dupl()
Testing duplicates Testing zero coordinates Testing sea coordinates Testing biodiversity institutions Testing GBIF headquarters, flagging records around Copenhagen Testing country centroids Testing country capitals Testing equal lat/lon Testing coordinate validity Removed 0 records. Removed 6 records. Removed 22 records. Removed 7 records. Testing country identity Removed 4618 records. Error in h(simpleError(msg, call)) : error in evaluating the argument 'obj' in selecting a method for function 'coordinates': cannot derive coordinates from non-numeric matrix In addition: Warning message: In wkt(obj) : CRS object has no comment
Originally posted by @jammah in https://github.com/ropensci/CoordinateCleaner/issues/56#issuecomment-803475370
Hi, I suspect this could be because the country test removed all records. If so, this may happen if the country information is coded in ISO-3, CoordianteCleaner needs ISO-3. Try to include the following line that is further up in the tutorial in your pipeline:
dat$countryCode <- countrycode(dat$countryCode, origin = 'iso2c', destination = 'iso3c')
Does this fix the issue?
Yes, you are right. Now it works perfectly!! It fixed the issue!
Many thanks for your help!