R 通过非空间维度进行总结可防止去除未溶解的斑点
溶解内部边界后保留残余斑点或碎屑。当溶解/聚合过程中包含非空间维度(时间)时,包装R 通过非空间维度进行总结可防止去除未溶解的斑点,r,dplyr,geospatial,sf,R,Dplyr,Geospatial,Sf,溶解内部边界后保留残余斑点或碎屑。当溶解/聚合过程中包含非空间维度(时间)时,包装rmapshaper无法去除斑点。是否可以移除斑点(使用或不使用rmapshaper),希望不单独溶解和聚合,然后合并结果 library(sf) library(dplyr) library(rmapshaper) #download file "shape.txt" from Pastebin link above shape <- dget("shape.txt"
rmapshaper
无法去除斑点。是否可以移除斑点(使用或不使用rmapshaper
),希望不单独溶解和聚合,然后合并结果
library(sf)
library(dplyr)
library(rmapshaper)
#download file "shape.txt" from Pastebin link above
shape <- dget("shape.txt")
class(shape)
[1] "sf" "data.frame"
plot(shape$geometry)
库(sf)
图书馆(dplyr)
图书馆(rmapshaper)
#从上面的Pastebin链接下载文件“shape.txt”
形状%summary(count=sum(count))%%>%ungroup()
#无年份合计
shape2%group_by(a1)%%>%summary(count=sum(count))%%>%ungroup()
#结果包含斑点
绘图(形状1$geometry)
绘图(形状2$geometry)
#删除斑点:不成功
shape1首先:您的示例中按年份分组感觉不正确。这些区域看起来像行政单位,最终会得到两个相互重叠的汇总多边形
在理想情况下,我可能会将几何体对象与年度数据分离
但说到这里,我将把你的例子当作玩具例子,意在展示一个问题,而不是让它本身有意义
考虑这段代码:由于斑点很小,可以通过将原始多边形缓冲10个单位,然后以相同的数量取消缓冲最终多边形,来移除它们(或者避免首先创建它们)
library(sf)
library(dplyr)
#download file "shape.txt" from Pastebin link above
shape <- dget("shape.txt")
# buffer & unbuffer
shape2 <- shape %>%
st_buffer(10) %>% # first create a small buffer ...
group_by(a1, year) %>%
summarise(count=sum(count)) %>%
ungroup() %>%
st_buffer(-10) # ... and then remove it to preserve area
plot(shape2$geometry)
库(sf)
图书馆(dplyr)
#从上面的Pastebin链接下载文件“shape.txt”
形状%#首先创建一个小缓冲区。。。
组别(a1,年份)%>%
汇总(计数=总和(计数))%>%
解组()%>%
st_缓冲区(-10)#。。。然后将其移除以保留该区域
绘图(形状2$geometry)
最后,您将看到两个多边形相互重叠,没有斑点。这是一个玩具示例,您是正确的。我应该在绘图
说明中选择一年。话虽如此,在我看来,将形状和年份存储在同一张表中比单独存储更为节省,以避免每次绘图前都必须合并。这也是非正统的吗?@syre-也许我应该写一些意想不到的东西;我无意冒犯,我也不主张任何正统的圣杯。我希望缓冲方法能解决你的问题/这才是最重要的…@Jindra_Lacko无意冒犯;只是想了解正确的数据结构。所以我应该写次优的而不是非正统的:)
#remove specks: unsuccessful
shape1 <- ms_filter_islands(shape1, min_area=1000000)
plot(shape1$geometry)
#remove specks: successful
shape2 <- ms_filter_islands(shape2, min_area=1000000)
plot(shape2$geometry)
library(sf)
library(dplyr)
#download file "shape.txt" from Pastebin link above
shape <- dget("shape.txt")
# buffer & unbuffer
shape2 <- shape %>%
st_buffer(10) %>% # first create a small buffer ...
group_by(a1, year) %>%
summarise(count=sum(count)) %>%
ungroup() %>%
st_buffer(-10) # ... and then remove it to preserve area
plot(shape2$geometry)