ropensci / CoordinateCleaner

Automated flagging of common spatial and temporal errors in biological and palaeontological collection data, for the use in conservation, ecology and palaeontology.
https://docs.ropensci.org/CoordinateCleaner/
79 stars 21 forks source link

error from "countries" test in clean_coordinates #49

Closed noraheaphy closed 4 years ago

noraheaphy commented 4 years ago

Hello! I've been using this package in my research for almost a year, and it's a life saver, thank you so very much for creating it and making it accessible!

I'm using the clean_coordinates function on data downloaded manually from GBIF, and I'm getting the following error when testing country identity. I've run this code on this dataset without any problems over the past couple days, and I wondered if you any insight into whether this is a problem on my end, or if it could possibly be a problem with the update from yesterday?

Testing country identity x[i, ] is invalid Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_lower_td, unaryUnion_if_byid_false, : TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point 78.719726559999998 31.887646480000001 at 78.719726559999998 31.887646480000001 In addition: Warning messages: 1: In RGEOSUnaryPredFunc(spgeom, byid, "rgeos_isvalid") : Ring Self-intersection at or near point 78.719726559999998 31.887646480000001 2: In rgeos::gIntersection(x[i, ], y, byid = TRUE, drop_lower_td = TRUE) : Invalid objects found; consider using set_RGEOS_CheckValidity(2L)

I've attached a data file and code for reproducibility. I'm running: R version 4.0.2 (2020-06-22) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Catalina 10.15.6

coordcleaner_error_data_08-19-2020.xlsx

# set up
rm(list = ls()) # clear environment
setwd("") # set working directory
# load packages
library(tidyverse)
library(CoordinateCleaner)
library(countrycode)
library(ggplot2)

# load in Anacampserotaceae locality data
# open in Excel and save as CSV first, GitHub only allows .xlsx to be uploaded
anacamps <- read.csv("coordcleaner_error_data_08-19-2020.csv", header = TRUE, sep = ",", 
                     na.strings = "")

# flag problems
anacamps <- data.frame(anacamps)
flags <- clean_coordinates(x = anacamps, lon = "decimalLongitude", lat = "decimalLatitude",
                           countries = "countryCode", 
                           species = "species",
                           tests = c("capitals", "centroids", "equal","gbif", "institutions",
                                     "zeros", "countries", "seas"))
azizka commented 4 years ago

Hi!

Great that you think CoordinateCleaner is helpful!

Thanks for the detailed example. Not entirely sure yet why you get this problem this issue should be fixed with version 2.0-17. Your code is working for me on windows machine. Could you try and install the latest version from github and try again?

library(devtools)
install_github("ropensci/CoordinateCleaner")

Thanks!

noraheaphy commented 4 years ago

That worked for me! I must not have been pulling down the most recent version. Thank you!