convert geometry from a .shp file into a new df with the id column from the .shp file and x and y coordinates in r in r

main.r
# Load necessary libraries
library(sf)

# Read the .shp file
shapefile <- st_read("your_shapefile.shp")

# Extract the coordinates
coordinates <- st_coordinates(shapefile)

# Create a new data frame with id and x y coordinates
data_df <- data.frame(id = shapefile$id, x = coordinates[, 1], y = coordinates[, 2])
312 chars
12 lines

related categories

gistlibby LogSnag