找到多边形的质心

时间:2019-01-25 21:18:25

标签: r

遵循以下问题:gCentroid shifting centroid towards concentration of points,但形状更复杂。

使用此SpatialPointsDataFrame,我使用gCentroid计算了中心,但是将其放置在形状之外。

# c. = [dput'd data from link]
poly <- SpatialPolygons(Srl = list(Polygons( srl = list(Polygon(coords = coordinates(c.))), ID = 1)))
plot(poly)
axis(1)
axis(2)
points(rgeos::gCentroid(poly)) 

enter image description here 如何返回落入内部指定形状的中心点的坐标?

编辑:正如在注释中针对此类形状所指出的那样,中心位于边界之外。我认为我所寻找的东西最好被描述为“质量中心”。 enter image description here

1 个答案:

答案 0 :(得分:0)

我发现this软件包似乎可以解决问题。相关方法:https://blog.mapbox.com/a-new-algorithm-for-finding-a-visual-center-of-a-polygon-7c77e6492fbc

poly <- SpatialPolygons(Srl = list(Polygons( srl = list(Polygon(coords = coordinates(c.))), ID = 1)))
plot(poly)
axis(1)
axis(2)
points(rgeos::gCentroid(c.)) 

p <- polylabelr::poi(xx$long, xx$lat, precision = 0.01)
points(p)

enter image description here