r – 溶解hexmap多边形形状文件

我试图通过unionSpatialPolygons或聚合函数溶解内部多边形来生成六边形图表的轮廓.我得到了不溶解的流浪十六进制……一个显示问题的虚拟示例:

# 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)

《r – 溶解hexmap多边形形状文件》

# 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)

《r – 溶解hexmap多边形形状文件》

使用我实际使用的shapefile(不是英国)我得到更多的迷路六边形 – 有些完整 – 有些不是.

最佳答案 Roger Bivand建议的解决方案(通过电子邮件交换):

 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包中).

《r – 溶解hexmap多边形形状文件》

点赞