Created
March 28, 2015 16:05
-
-
Save jhollist/286917bca858a4412610 to your computer and use it in GitHub Desktop.
Error when more complex sp passed to spocc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
devtools::install_github('jhollist/quickmapr') | |
devtools::install_github('ropensci/spocc') | |
install.packages('rgeos') | |
library("quickmapr") | |
library("spocc") | |
library("rgeos") | |
data(lake) | |
## sp bbox to poly | |
bbox_to_sp <- function(sp) { | |
bbox <- bbox(sp) | |
x <- c(bbox[1, 1], bbox[1, 1], bbox[1, 2], bbox[1, 2], bbox[1, 1]) | |
y <- c(bbox[2, 1], bbox[2, 2], bbox[2, 2], bbox[2, 1], bbox[2, 1]) | |
p <- Polygon(cbind(x, y)) | |
ps <- Polygons(list(p), "p1") | |
sp <- SpatialPolygons(list(ps), 1L, proj4string = CRS(proj4string(sp))) | |
return(sp) | |
} | |
lake_100m <- gBuffer(lake, width = 100) | |
lake_1000m <- gBuffer(lake, width = 1000) | |
lake_100m_dd <- spTransform(lake_100m, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) | |
lake_1000m_dd <- spTransform(lake_1000m, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) | |
lake_dd <- spTransform(lake, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")) | |
lake_bbox_dd <- bbox_to_sp(lake_dd) | |
qmap(lake_bbox_dd, lake_1000m_dd, lake_100m_dd, lake_dd) | |
occ(geometry = lake_bbox_dd) | |
occ(geometry = lake_100m_dd) #Connection reset by peer | |
occ(geometry = lake_1000m_dd) #replacement has length zero |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment