Ich habe ein Polygon Shape-Datei (herunterladbare here), von dem ich enthaltend ein data.frame
mit 3 Spalten erstellen möchten:Erhalten Datenrahmen mit Polygonen id und Centroid (lat long) Informationen von Shape-Datei
- Polygon-ID
- Centroid Breite
- Centroid Longitude
Aus dieser Antwort here, ich weiß es seine ganz einfach, diese Informationen zu erhalten, wie ein Formal Class SpatialPoints
Objekt. Und wenn ich dieses Objekt in einen data.frame umwandle, verliere ich die 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)
Irgendeine Idee, wie man die ID-Info behält?