I’d like to add the latitude and the longitude of all polygons’ centroids to the dataframe of a SpatialPolygonsDataFrame. However, since I’m not sure how to extract the polygons id when using gCentroid, I’m not sure how to do the merge (see 3rd line of code below). Is someone able to help me with this? Thanks a lot!
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.
