【发布时间】:2020-07-04 10:27:30
【问题描述】:
我想将所有多边形质心的纬度和经度添加到 SpatialPolygonsDataFrame 的数据框中。但是,由于我不确定在使用 gCentroid 时如何提取多边形 id,因此我不确定如何进行合并(参见下面的第 3 行代码)。有人能帮我解决这个问题吗?非常感谢!
library(tidyverse)
library(rgeos)
ETH <- getData("GADM", country = "ETH", level = 3) # example of SpatialPolygonsDataFrame
cent <- as.data.frame(gCentroid(ETH, byid=TRUE)) # extraction of the coordinates of the polygons' centroids
ETH@data <- ETH@data %>% left_join(cent, by=?) # Here, I am not sure how to add the coordinates of the polygons' centroids to the dataframe.
【问题讨论】: