gpt4 book ai didi

r - 解散 hexmap 多边形形状文件

转载 作者:行者123 更新时间:2023-12-04 10:45:41 24 4
gpt4 key购买 nike

我试图通过 unionSpatialPolygons 溶解内部多边形来生成六边形 map 的轮廓。或 aggregate职能。我得到了不溶解的杂散十六进制......一个显示问题的虚拟示例:

# 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(不适用于英国),我得到了更多的杂散六边形——有些是完整的——有些则不是。

最佳答案

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)

即避免 assign_polygons()在 hexmapr 中使用 1) spsample生成形状位置和 2) HexPoints2SpatialPolygons用于六边形网格(均在 sp 包中)。

enter image description here

关于r - 解散 hexmap 多边形形状文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47670683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com