是否可以使用软件包$ keyids = $ xpath-> evaluate ('/ html / body // div [@ class = "offers-table-row"] / @ data-offer');
$ regios = $ xpath-> evaluate ('/ html / body // div [@ class = "offers-table-row"] / @ data-region');
$ editions = $ xpath-> evaluate ('/ html / body // div [@ class = "offers-table-row"] / @ data-edition');
$ prices = $ xpath-> evaluate ('/ html / body // div [@ class = "offers-table-row"] / @ data-price');
$ affnames = $ xpath-> evaluate ('/ html / body // div [contains (@class, "offers-merchant")] / @ title');
$ title = $ xpath-> evaluate ('// meta [@property = "og: title"] / @ content');
从R中的多边形中移除孔?我也会对包含其他软件包的解决方案感兴趣。
这是一个有两个孔的多边形的例子。
sf
这是数字:
library(sf)
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pts = list(outer, hole1, hole2)
(pl1 = st_polygon(pts))
# POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1),(5 5, 5 6, 6 6, 6 5, 5 5))
答案 0 :(得分:2)
在https://github.com/r-spatial/sf/issues/609#issuecomment-357426716之后, 这可能有效:
library(sf)
outer = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
pts = list(outer, hole1, hole2)
pl1 = st_polygon(pts)
plot(pl1)
pl2 <- st_multipolygon(lapply(pl1, function(x) pl1[1]))
plot(pl2)
由reprex package(v0.2.1)于2018-10-05创建
答案 1 :(得分:1)
软件包nngeo
引入了一个功能,以在@lbusett回答此问题后(并在说明中引用他,做得很好)。
因此您可以使用:
nngeo::st_remove_holes(your_sf_object)
答案 2 :(得分:1)
sfheaders::sf_remove_holes()
也可以做到这一点
sfheaders::sf_remove_holes(pl1)
POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))