如何在R的sf包中沿直线裁剪EPSG:4326非投影空间多边形?
R语言sf包按笛卡尔平面裁剪十进制度坐标多边形问题
我正尝试使用sf包将空间多边形分配给由十进制度坐标定义的不等尺寸框,示例代码如下:
library(sf) #> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1 library(dplyr) #> #> Attaching package: 'dplyr' #> The following objects are masked from 'package:stats': #> #> filter, lag #> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union library(spData) #> To access larger datasets in this package, install the spDataLarge #> package with: `install.packages('spDataLarge', #> repos='https://nowosad.github.io/drat/', type='source')` x <- world plot(st_geometry(x), xlim = c(60,180), ylim = c(0, 60)) matrix(c(60, 0, 180, 0, 180, 30, 60, 30, 60, 0), byrow = TRUE, ncol = 2) %>% list() %>% st_polygon() %>% st_sfc() %>% st_set_crs(4326) %>% plot(add = T, border = "red", col = NA, lwd = 3) matrix(c(60, 30, 120, 30, 120, 60, 60, 60, 60, 30), byrow = TRUE, ncol = 2) %>% list() %>% st_polygon() %>% st_sfc() %>% st_set_crs(4326) %>% plot(add = T, border = "blue", col = NA, lwd = 3)

我希望将蓝色和红色框内的内容裁剪/拆分为独立对象。使用st_crop函数时我发现,裁剪是沿着与x的底层多边形边缘重合的曲线进行的,示例代码如下:
crop1 <- st_crop(x, xmin = 60, xmax = 180, ymin = 0, ymax = 30) #> Warning: attribute variables are assumed to be spatially constant throughout all #> geometries crop2 <- st_crop(x, xmin = 60, xmax = 120, ymin = 30, ymax = 60) #> Warning: attribute variables are assumed to be spatially constant throughout all #> geometries plot(st_geometry(x), xlim = c(60,180), ylim = c(0, 60)) plot(st_geometry(crop1), border = "red", col = NA, add = TRUE) plot(st_geometry(crop2), border = "blue", col = NA, add = TRUE)

看起来坐标并未按平面处理,而是可能在裁剪前被投影了。此外也可以通过在裁剪前为底层多边形添加节点降低曲率,但若仅将经纬度值视为笛卡尔坐标进行裁剪,这种方法就显得过于复杂。
请问sf中是否存在简便方法,能假设十进制度多边形为笛卡尔坐标(即沿直线)完成裁剪?我主要关注尺寸不均的多边形裁剪后出现重叠的问题。
补充说明
sp和rgeos包似乎不存在该问题,示例代码如下:
library(sf) #> Linking to GEOS 3.8.1, GDAL 3.2.1, PROJ 7.2.1 library(sp) library(rgeos) #> rgeos version: 0.5-7, (SVN revision (unknown)) #> GEOS runtime version: 3.9.1-CAPI-1.14.2 #> GEOS using OverlayNG #> Linking to sp version: 1.4-5 #> Polygon checking: TRUE library(spData) #> To access larger datasets in this package, install the spDataLarge #> package with: `install.packages('spDataLarge', #> repos='https://nowosad.github.io/drat/', type='source')` y <- as_Spatial(world) rect1 <- matrix(c(60, 0, 180, 0, 180, 30, 60, 30, 60, 0), byrow = TRUE, ncol = 2) %>% list() %>% st_polygon() %>% st_sfc() %>% st_set_crs(4326) %>% as_Spatial() rect2 <- matrix(c(60, 30, 120, 30, 120, 60, 60, 60, 60, 30), byrow = TRUE, ncol = 2) %>% list() %>% st_polygon() %>% st_sfc() %>% st_set_crs(4326) %>% as_Spatial() sp::plot(y, xlim = c(60,180), ylim = c(0, 60)) sp::plot(rgeos::gIntersection(y, rect1, byid = TRUE), add = TRUE, border = "red", col = NA) sp::plot(rgeos::gIntersection(y, rect2, byid = TRUE), add = TRUE, border = "blue", col = NA)

内容的提问来源于stack exchange,提问作者Mikko
相关产品推荐
相关产品推荐

