Closed philiptsoares closed 2 years ago
I have the same problem.
Hello Moroti. In my analysis I ended up solving the problem by opening the species distribution shapes with the rgdalmaptools :: readShapePoly function. I did the test with other shapes and the data extraction worked correctly with rgdal :: readOGR. But the shape I used didn't work. Follow the codes to try to run your case there.
library(raster) library(maptools) library(rgdal) library(letsR) library(dplyr)
anura <- readShapePoly("ANURA.shp") ## Shape amphibia -IUCN head(anura)
anura@data <- anura@data %>% # # select specific data in shape of anura select("BINOMIAL", "PRESENCE", "ORIGIN", "SEASONAL") head(anura)
shape <- readOGR("Neotropico.shp") plot(shape)
sq_grid <- readOGR("sq_grid.shp") plot(sq_grid)
projection(anura) <- projection(shape) anura
projection(sq_grid) <- projection(shape) sq_grid
resu_sq <- lets.presab.grid(anura, sq_grid , sample.unit = "FID")
rich_plus1 <- rowSums(resu_sq$PAM) + 1 colfunc <- colorRampPalette(c("#fff5f0", "#fb6a4a", "#67000d")) colors <- c("white", colfunc(max(rich_plus1))) plot(resu_sq$grid, border = "gray40", col = colors[rich_plus1])
Good job! Hug.
I'm also having this problem. I tried opening just one of the files (species distributions) using the "readShapePoly" function, and after both files (species distribution and the map with grids), but in both attempts I had this error.
Hi Bruno.
I'm working with some IUCN data and would like to extract the information for cell grids. However, when I use the "lets.presab.grid" function it starts to run and after a while this error is returned:
How to proceed?
Follow used commands
Packages
library(rgdal) library(letsR)
Import shape - Grid Hexagonal
grid_hex <- readOGR("hex_grid_neo.shp") ## 2000 features plot(grid_hex) summary(grid_hex)
Import IUCN maps of Amphibian
amphi <- readOGR("AMPHIBIANS.shp") ## Shape amphibio Neotropical region summary(amphi)
Create grid - SpatialPolygonsDataFrame
Georref Grid Hexagonal
crs(grid_hex) <- CRS("+proj=longlat +datum=WGS84") grid_hex
Create a dataframe and display default rownames
( p.df <- data.frame( ID=1:length(grid_hex)) ) rownames(p.df)
Extract polygon ID's
( pid <- sapply(slot(grid_hex, "polygons"), function(x) slot(x, "ID")) )
Create dataframe with correct rownames
( p.df <- data.frame( ID=1:length(grid_hex), row.names = pid) )
Try coersion again and check class
g <- SpatialPolygonsDataFrame(grid_hex, p.df) class(g)
Create shape Anfíbios - SpatialPolygonsDataFrame
Georref Grid Hexagonal
crs(amphi) <- CRS("+proj=longlat +datum=WGS84") amphi
Create a dataframe and display default rownames
( p.df <- data.frame( ID=1:length(amphi)) ) rownames(p.df)
Extract polygon ID's
( pid <- sapply(slot(amphi, "polygons"), function(x) slot(x, "ID")) )
Create dataframe with correct rownames
( p.df <- data.frame( ID=1:length(amphi), row.names = pid) )
Try coersion again and check class
amphi_p <- SpatialPolygonsDataFrame(amphi, p.df) class(amphi_p)
Extract data from shape IUCN
resu <- lets.presab.grid(amphi_p, g , sample.unit = "ID")
Hug.