rspatialshapefiler-sf

sf error: OGR error: cannot export to WKT


I'm having issues running sf on my computer (R version 4.3.3, linux ubuntu 22.04.4). When trying to import a shapefile using st_read(), I am faced with the following error and warning messages:

> parks <- sf::st_read("Canada/PAs/ProtectedConservedArea_2023.gdb")

Multiple layers are present in data source /run/user/1472454/gvfs/smb-share:server=files.ok.ubc.ca,share=rsmarcus/GitHub/NDVI/Canada/PAs/ProtectedConservedArea.gdb, reading layer `ProtectedConservedArea'.
Use `st_layers' to list all layer names and their type in a data source.
Set the `layer' argument in `st_read' to read a particular layer.
Reading layer `ProtectedConservedArea' from data source 
  `/Canada/PAs/ProtectedConservedArea.gdb' using driver `OpenFileGDB'

Error: OGR error: cannot export to WKT
In addition: Warning messages:
1: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  automatically selected the first layer in a data source containing more than one.
2: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Message 1: organizePolygons() received a polygon with more than 100 parts. The processing may be really slow.  You can skip the processing by setting METHOD=SKIP, or only make it analyze counter-clock wise parts by setting METHOD=ONLY_CCW if you can assume that the outline of holes is counter-clock wise defined
3: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Error 1: PROJ: proj_as_wkt: std::bad_alloc

I'm currently running sf version 1.0-16 (with GEOS 3.12.1, GDAL 3.8.4, and PROJ 9.3.1) - these errors only appeared after updating my packages a little while ago. Before updating my packages, I was able to use all sf functions without issue, including importing this exact same shapefile. I have tried updating all my packages in case this was an issue with a dependency (using the update.packages() function), but this did not fix the issue.

I have attached a line of reproducible code using the shapefile of protected areas in Canada, which can be obtained here: https://data-donnees.az.ec.gc.ca/data/species/protectrestore/canadian-protected-conserved-areas-database/Databases

library('sf')
parks <- sf::st_read("Canada/PAs/ProtectedConservedArea_2023.gdb")

I'm hoping to fix this issue without having to resort to installing an older version of the package for my code to run!


Solution

  • Ok, after many times re-installing sf, I was able to get it to work. I believe the issue was related to GDAL installation - I installed GDAL again using the steps here described, and after that I was able to succesfully load and use sf.