我正在尝试让 R 读取 gdb 文件。我做的第一件事就是找出它的层,我通过运行来完成:
ogrListLayers("my_data.gdb")
事实证明 my_data 有两个大层。我尝试打开两者,但都没有成功。这是我到目前为止所尝试过的:
1)
Wont_open <- readOGR(dsn = "D:/my_data.gdb", layer = "layer_1", dropNULLGeometries = F)
我已经尝试过使用和不使用 dropNULLGeometries 参数以及 my_data 中的两个层的上述方法。运行此程序时,出现以下错误:
Error in readOGR(dsn = "D:/my_data.gdb", :
Unsupported field type: Binary
我已经对 my_data 中的两个层尝试了上述方法。当我运行这个程序时,R 在开始该过程大约 1 小时后停止工作。
3)
read_GDB_Layer <- function(dsn, layerName, overwrite = T){
conversionDir <- tempdir()
gdalUtils:: ogr2ogr(src_datasource_name = dsn, dst_datasource_name = conversionDir, f = "ESRI Shapefile", layer + layerName, verbose = T, overwrite = overwrite)
df <- read.dbf(file.path(conversionDir, paste0(layerName, ".gdbtable")))
return(df)}
那么,
Wont_open <- read_GDB_Layer(dsn = "D:/my_data.gdb", layerName = "layer_1")
我对两个层都尝试了此操作,并更改了 .dbf 函数的 .gdbtable 参数以在两个层上运行它,但它仍然不起作用。我收到以下警告消息:
1: In gdal_setInstallation(search_path = NULL, rescan = FALSE, ignore.full_scan = TRUE, :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)
2: In gdal_setInstallation(search_path = NULL, rescan = FALSE, ignore.full_scan = TRUE, :
If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)
正如@sven-brandt 所指出的,
st_read()
功能对我有用
terra::vect()
也可用于打开.gdb中的空间特征。我不确定这个函数是否能更有效地处理大文件,但似乎值得尝试。
terra::vect()
的一个好处是您可以使用 proxy
参数将数据保存在磁盘而不是内存上。从那里你可以使用 terra::query()
函数来子集你的对象并生成一个 vect 对象。这似乎是减少对象总大小的合理方法。