8

I have a sfc-object consisting of just points. Unfortunately, when I read in the shapefile, it created points of type XYZ. Now I removed some points and can't figure out how to export the remaining points as shapefile. I get the error:

GDAL Error 6: Geometry type of `3D Point' not supported in shapefiles

As I don't really need the third dimension So I thought I'd just remove it. But I don't know how. This is how the sfc-object looks like at the moment.

First 5 geometries:
POINT Z (397864 6302484 0)
POINT Z (386440.2 6299046 0)
POINT Z (390490.3 6296620 0)
POINT Z (391614.7 6293960 0)
POINT Z (377803.1 6276244 0)

1 Answer 1

11

Using the data from ?st_zm, here's a thing with Z and M coordinates:

> a
Simple feature collection with 2 features and 1 field
geometry type:  LINESTRING
dimension:      **XYZM**
bbox:           xmin: 1 ymin: 3 xmax: 8 ymax: 16
epsg (SRID):    NA
proj4string:    NA
  a                           geom
1 1 LINESTRING ZM (1 9 17 25, 2...
2 2 LINESTRING ZM (1 3 5 7, 2 4...

feed it into st_zm and bye bye Z and M:

> st_zm(a)
Simple feature collection with 2 features and 1 field
geometry type:  LINESTRING
dimension:      **XY**
bbox:           xmin: 1 ymin: 3 xmax: 8 ymax: 16
epsg (SRID):    NA
proj4string:    NA
  a                           geom
1 1 LINESTRING (1 9, 2 10, 3 11...
2 2          LINESTRING (1 3, 2 4)
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.