You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在R或sf包中读取(压缩).gdb文件?解决空层读取问题

问题:在R中读取ESRI FileGDB时部分图层为空的解决方案

问题背景与现象

尝试在R中读取目录格式的.gdb文件,怀疑部分子图层或整个GDB已被压缩,但无法确认。使用sf包的st_read()读取时,部分图层返回空要素,相关命令与报错信息如下:

> 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

已验证的外部转换方法

通过OSGeo4W Shell中的ogr2ogr命令可将GDB转换为GeoPackage,转换后WSG层包含正确数量的要素。命令如下:

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

若省略参数--config OGR_SKIP OpenFileGDB,转换后的GPKG仍会生成空层,推测该参数强制使用了通过OSGeo4W安装QGIS时获取的ESRI驱动。

需求

寻求以下两种解决方案:

  • 无需外部工具,直接在R中读取此类GDB的方法
  • 在R内部调用上述ogr2ogr命令的实现方案

内容的提问来源于stack exchange,提问作者m4D_guY

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 12:25:23