Issues with writing a dataframe to a shapefile

I suspect that there is an issue with your data. It somehow seems to have acquired a Z dimension (height). This is not supported by the shp format (it is positively ancient - based on dBASE file format, a leading database in the MS DOS era).

When testing the shapefile writing feature with a data frame of fake data (North Carolina is the Iris of spatial data) I get no funny messages, and the output is saved in point format (as expected).

library(sf)
library(tidyverse)

points <- data.frame(name = c("Raleigh", "Greensboro", "Wilmington"),
                     x = c(-78.633333, -79.819444, -77.912222),
                     y = c(35.766667, 36.08, 34.223333)) %>% 
  st_as_sf(coords = c("x", "y"), crs = 4326) %>% 
  st_transform(2264) # a feety CRS, just for the heck of it...

st_write(points, "sample_shapefile.shp")

1 Like