I have a polygon shapefile (downloadable here) from which I want to create a data.frame
with 3 columns containing:
- Polygon id
- Centroid latitude
- Centroid Longitude
From this answer here, I know it its quite easy to get this information as a Formal Class SpatialPoints
object. And when I convert this object to a data.frame I loose the id information.
# Load Shapefile
Legislative_areas <- readOGR(dsn = 'C:/Users/.../Downloads/Legislative2010UTM', layer ='Legislative2010UTM')
# Get centroids
cent <- gCentroid(Legislative_areas, byid=TRUE)
# Convert to data.frame, but loose id info
cent <- as.data.frame(cent)
Any idea on how to keep the id info?