Is there a better way for handling SpatialPolygons that cross the antimeridian (date line)?

試著忘記壹切 提交于 2019-12-06 14:55:16

You're right, it's the current year and there is a solution for your problem. The sf-package has the function st_wrap_dateline(), which is exactly what you need.

library(dismo)
library(sf)


locations <- SpatialPoints(coords=cbind(c(50,0,0,0, 175, -170), c(10, 30, 50, 70,0,-10)), proj4string = CRS("+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0"))
buffr <- circles(p = locations, d = 1500000, lonlat=TRUE, dissolve=FALSE)

buffr2 <- as(buffr@polygons, Class = "sf") %>%
            st_wrap_dateline(options = c("WRAPDATELINE=YES")) %>%
             st_union()


plot(wrld_simpl, border="grey50")
plot(buffr2, add=TRUE, border="red", lwd=2)
points(locations, pch=19, col="blue")

st_wrap_dateline converts the polygons which cross the international date line, or "antimeridian", into MULTIPOLYGON. And that's about it.

Does that solve your problem? At least it shortens the way quite a bit, to get where you are now. ^^

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!