Search code examples
rspatialshapefiler-sf

Unable to read shapefiles with st_read() in R


I am trying to read a shapefile

library(sf)
wards <- read_sf("Shape_files/benguluru_ward_boundaries_reprojected.shp")

and I am getting this error

Error in CPL_get_z_range(obj, 3) : z error - expecting three columns;

I googled it and it seems it has to do with z-dimension but I couldn't find a solution. How to solve this? Thanks in advance.

Edit: This is what I am getting when I load the sf package

> library(sf)
Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE

you can get the files here

Edit2: I was able to solve this by running extract z values as mentioned here and there dropping it while exporting the layer. I am able to read that new layer without any issues.


Solution

  • I was able to find a workaround to this problem first by reading the layer using terra and then transforming the SpatVect to a sf object.

    libary(terra)
    library(sf)
    library(tidyverse)
        
    df <- terra::vect(path_to_shp) %>% st_as_sf()