解散六边形地图多边形形状文件

4

我正在尝试使用unionSpatialPolygonsaggregate函数通过溶解内部多边形来为六边形地图制作大纲。我得到了一些不会溶解的杂散六边形...这是一个虚拟示例来展示问题:

# grab a dummy example shape file
library(raster)
g <- getData(name = "GADM", country = "GBR", level = 2)
# par(mar = rep(0,4))
# plot(g)

# create a hexagonal cartogram
# library(devtools)
# install_github("sassalley/hexmapr")    
library(hexmapr)
h <- calculate_cell_size(shape = g, seed = 1,
                         shape_details = get_shape_details(g), 
                         learning_rate = 0.03, grid_type = 'hexagonal')
i <- assign_polygons(shape = g, new_polygons = h)
par(mar = rep(0,4))
plot(i)

enter image description here

# dissolve the polygons to get coastline
library(maptools)
j <- unionSpatialPolygons(SpP = i, IDs = rep(1, length(i)))
par(mar = rep(0,4))
plot(j)

# same result with aggregate in the raster package
k <- aggregate(x = i)
par(mar = rep(0,4))
plot(k)

enter image description here

使用实际的shapefile(不是英国的)时,我会得到更多的杂散六边形 - 有些是完整的,有些则不是。


这两个杂散的多边形与两个海湾的内陆极端重合,北部的是爱尔兰海,南部的是布里斯托尔海峡。因此,这些海岸线区域可能存在一些故障。我不熟悉 hexmapr - 是否可以缩小六边形的大小并比较结果? - Stuart Allen
@StuartAllen 我认为你是对的。j中两个都是漏洞。 - guyabel
1个回答

2
罗杰·比万德(通过电子邮件交流)提出的建议解决方案:
 g1 <- spTransform(x = g, CRSobj = CRS("+init=epsg:27700"))
 # cellsize from calculate_cell_size() above
 h1 <- spsample(x = g1, type="hexagonal", cellsize=38309) 
 i2 <- HexPoints2SpatialPolygons(hex = h1) 
 j2 <- unionSpatialPolygons(SpP = i2, IDs = rep(1, length(i2)))
 plot(j2)

即避免在hexmapr中使用assign_polygons()函数,而改用以下两种方式:1)使用spsample生成形状位置,2)使用HexPoints2SpatialPolygons创建六边形网格(均在sp包中)。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接