eems
eems copied to clipboard
Error (rgeos):
Hello,
I am receiving the following error:
"The habitat geometry is not a valid ring (a ring is both simple and closed) Let the habitat be the rectangle defined by (xmin, ymin) and (xmax, yxmax) where xmin, xmax = range(longitude) and ymin, ymax = range(latitude). Plotting posterior probability trace"
I have checked my outer.txt and the first and last lat long are the same. (attached) outer.txt
Here is my script:
## Check that the current directory contains the rEEMSplots source directory (from GitHub)
if (file.exists("./rEEMSplots/")) {
install.packages("rEEMSplots", repos=NULL, type="source")
} else {
stop("Move to the directory that contains the rEEMSplots source to install the package.")
}
extdata_path <- ("/Users/joshuahallas/Documents/unr/projects/thamnophis_population/th_elegans/ELTE_subset/eems/rEEMSplots/results")
eems_results_elegans <- file.path(extdata_path, c("EL_25apr_Indiv97-nSites10121-EEMS-nDemes600-chain1",
"EL_25apr_Indiv97-nSites10121-EEMS-nDemes600-chain2",
"EL_25apr_Indiv97-nSites10121-EEMS-nDemes600-chain3"))
eems_results_terrestris <- file.path(extdata_path, c("TE_29apr_Indiv90-nSites10121-EEMS-nDemes600-chain1",
"TE_29apr_Indiv90-nSites10121-EEMS-nDemes600-chain2",
"TE_29apr_Indiv90-nSites10121-EEMS-nDemes600-chain3"))
name_figures <- file.path(path.expand("~"), "/Users/joshuahallas/Documents/unr/projects/thamnophis_population/th_elegans/ELTE_subset/eems/rEEMSplots/results")
library("rEEMSplots")
library("rworldmap")
library("rworldxtra")
library("rgdal")
library("Rcpp")
library("RcppEigen")
library("raster")
library("rgeos")
library("sp")
projection_none <- "+proj=longlat +datum=WGS84"
projection_mercator <- "+proj=merc +datum=WGS84"
eems.plots(mcmcpath = eems_results_elegans,
plotpath = paste0(name_figures, "-elegans_geographic-map"),
longlat = F,
plot.width = 11,
plot.height = 11,
projection.in = projection_none,
projection.out = projection_mercator,
add.map = TRUE,
col.map = "black",
lwd.map = 2,
add.grid = FALSE,
col.grid = "gray90",
lwd.grid = 2,
add.outline = TRUE,
col.outline = "black",
lwd.outline = 5,
add.demes = TRUE,
col.demes = "black",
pch.demes = 5,
min.cex.demes = 0.5,
max.cex.demes = 1.5)
I have rerun older analyses and I received no error. I have also been able to run the current data using the function make_eems_plots from reemsplots2 and received no error. I am unable to figure out the issue. Any suggestions? Thank you for your time.
I'm pretty sure it's an issue with how dense the outer
points are.
I pruned them by rounding and then dropping duplicates (from ~1500 pts to ~150 pts). The coarse habitat is then a valid ring. outer-coarse.txt
Here are the three lines of code to check whether a geometry is a valid ring or not.
x <- outer[, 1]
y <- outer[, 2]
l <- readWKT(paste("LINESTRING(", paste(paste(x, y), collapse = ", "), ")"))
rgeos::gIsRing(l, byid = FALSE)