on-internet
← Community

sf: Write Lat/Long from geometry into separate column and keep ID column

Stack Overflow ·

I have a df with polygon ID's from a shapefile and their centre-points in a geometry column: # A tibble: 3 x 2 ID geometry <dbl> <POINT [°]> 1 1 (117.2 31.8) 2 2 (116.4 40.1) 3 4 (117.9 26) I want to put the latitude/longitude values into separate columns, so I do: library(sf) centres<- as.data.frame(st_coordinates(df)) This new 'centres' dataframe has the lat&long values, but misses the ID column. How can I preserve it, or is there another way to get the lat&long values into separate columns from the geometry column whilst keeping the ID in the same df? dput for the dataframe is: df <- struct

Comments

Sign in or sign up to comment and upvote.

No comments yet.