[R] Save spatial data in a csv file
Roger Bivand
Roger@B|v@nd @end|ng |rom nhh@no
Thu Dec 5 12:46:47 CET 2024
As Hasan suggested, much more information is needed. It would be very helpful to know the class of nyc_ct_geo, and how it was created. It is possibly an sf object from the print output.
>From this, assuming that it is an sf object, the geometries are polygons, not points, so need to be converted to text, best WKT (well-known text) to write to CSV. It is then best to use the appropriate function from sf with a CSV driver - minimal example:
library(sf)
nc <- st_read(system.file("gpkg/nc.gpkg", package="sf"))
tf <- tempfile(fileext=".csv")
st_write(nc_geom, tf, driver="CSV", layer_options=c("GEOMETRY=AS_WKT"))
file.show(tf)
With more than 2000 polygon objects in your case, this is hardly a sensible way to write geometries to file, and depends on the person receiving the file having software that can convert WKT back to geometries. For more details on the CSV driver for st_write, please see https://gdal.org/en/stable/drivers/vector/csv.html#vector-csv
Maybe following up on the R-sig-geo list would be helpful if clarification is needed.
Roger
--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
Roger.Bivand using nhh.no
More information about the R-help
mailing list