0

I want to open a GDB (A directory that ends with ".gdb") in R. I am assuming that some sublayers or the whole GDB is compressed, though I do not know how to confirm this. I have tried st_read() of the sf Package, but some layers are read without any features, and I get an error message:

> st_layers("C:/path/to/name.gdb")
Driver: OpenFileGDB 
Available layers:
                     layer_name                 geometry_type features fields              crs_name
1                           WSG                 Multi Polygon        0      0 ETRS89 / UTM zone 32N
2                          HQSG                 Multi Polygon        0      0 ETRS89 / UTM zone 32N
3            Boden_natur_kultur                 Multi Polygon     2220     16 ETRS89 / UTM zone 32N
4                            BR                 Multi Polygon      212     19 ETRS89 / UTM zone 32N
5                           WEA                         Point      881     17 ETRS89 / UTM zone 32N
6               Fliessgewaesser 3D Measured Multi Line String   236407     18 ETRS89 / UTM zone 32N
7                Standgewaesser     3D Measured Multi Polygon    15905     17 ETRS89 / UTM zone 32N
8        Grundwasserflurabstand                 Multi Polygon    26604     15 ETRS89 / UTM zone 32N
9                    Georisiken                 Multi Polygon      241     14 ETRS89 / UTM zone 32N
10          nat_Waldentwicklung     3D Measured Multi Polygon     7996     18 ETRS89 / UTM zone 32N
11           Kulturlandschaften                 Multi Polygon       78     17 ETRS89 / UTM zone 32N
12 Boden_grundwasserbeeinflusst                 Multi Polygon    31522     17 ETRS89 / UTM zone 32N
13  Boden_stauwasserbeeinflusst                 Multi Polygon    13837     17 ETRS89 / UTM zone 32N
14                 Biogasanlage                         Point      150     16 ETRS89 / UTM zone 32N

> read_sf("C:/path/to/name.gdb",
+         "WSG")
Simple feature collection with 0 features and 0 fields
Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
Projected CRS: ETRS89 / UTM zone 32N
# A tibble: 0 × 1
# ℹ 1 variable: SHAPE <GEOMETRY [m]>
Warnmeldung:
In CPL_read_ogr(dsn, layer, query, as.character(options), quiet,  :
  GDAL Error 1: Error occurred in ../../../../gdal-3.8.4/ogr/ogrsf_frmts/openfilegdb/filegdbtable.cpp at line 1007

I managed to convert the GDB into a GeoPackage using the following ogr command line command in the OSGeoW Shell:

ogr2ogr  -f GPKG "C:/path/to/file/name_of_file.gpkg" "C:/path/to/file/name_of_file.gdb" --config OGR_SKIP OpenFileGDB

The resulting GeoPackage has a Layer WSG with the correct number of features.

Without the last argument --config OGR_SKIP OpenFileGDB it produces the empty layers again. I am assuming it forces the use of the ESRI Driver that I received by installing QGIS via the OSGeo4W installer.

Nonetheless, is there an option to read in such GDBs into R without the use of ogr2ogr or other outside R tools? A solution where I call this from within R would be much appreciated, too.

4
  • Have you tried using the options argument in read_sf() to pass --config OGR_SKIP OpenFileGDB to GDAL? Commented Jun 12, 2024 at 15:59
  • terra::vect, proxy = TRUE, with sql dialect will work. If you point to your data, we can consider better. Commented Jun 12, 2024 at 16:04
  • @Coy, i will look into that, but st_drivers shows me that only the OpenFileGDB Driver ist present, not the FileGDB one. Also, including the options gives me a warning 1: In CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : GDAL Message 6: open option '--config OGR_SKIP OpenFileGDB' is not formatted with the key=value format. To Chris Sadly, i cant publish the data and do not know how subdivide the dataset, so the error persist Commented Jun 13, 2024 at 7:11
  • Neither of the hinted solutions works. Commented Jun 27, 2024 at 12:02

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.