2017-06-01 147 views
0

如何獲得必須位於這些多邊形中的多邊形的中心點?對於很多不是凸多邊形的情況,獲取質心將落在多邊形之外。如何獲得多邊形的中心點,必然在這些多邊形(R,sp)中

理想情況下,多邊形在R中是SpatialPolygons,中心點也將作爲sp對象返回。

+0

你有什麼「中心點」的準則,如果心是不是你想?不難,但質心是定義的中心 – Phil

回答

3

您可以使用spatDataManagement packageGetCentralPoints。 這是從網上其他地方的this answer派生而來的。

執行的例子將返回:

plot(woods[1:5,]) 
# the centroids 
plot(GetCentroids(woods[1:5,]),add=T) 
# the central points guaranteed to be in the polygons 
plot(GetCentralPoints(woods[1:5,]),add=T,col="blue") 
legend("bottomright",legend=c("Centroids","Central points"),col=c("black","blue"),pch="+") 

你得到(注意底部多邊形)

enter image description here