如何使用R从ESRI文件地理数据库(.gdb)读取表 [英] How to read a table from an ESRI file geodatabase (.gdb) using R
问题描述
我正在尝试使用R从没有几何的ESRI地理数据库(.gdb)读取表.readOGR抛出错误,因为未定义几何,这是有道理的:
I am trying to read a table from an ESRI geodatabase (.gdb) that has no geometry using R. readOGR is throwing an error because there is no geometry defined, which kind of make sense:
# Load module to get readOGR
require('rgdal');
# Load module to get read.dbf
require('foreign');
收取不可或缺的包裹:外国
Le chargement a nécessité le package : foreign
# goto the directory with the GDB files
fgdb <- "c:/Mrnmicro/VulnerabilitePeuplements/gdb/Produits_IEQM_04151.gdb"
# List all feature classes in a file geodatabase
subset(ogrDrivers(), grepl("GDB", name))
name long_name write copy isVector
34 OpenFileGDB ESRI FileGDB FALSE FALSE TRUE
ogrListLayers(fgdb)
[1] "ESSENCE_MAJ" "ETAGE_MAJ" "Perimetre" "PEE_MAJ" "META_MAJ"
attr(,"driver")
[1] "OpenFileGDB"
attr(,"nlayers")
[1] 5
# Read the feature class
fc = readOGR(dsn=fgdb,layer="ESSENCE_MAJ",dropNULLGeometries=FALSE)
Error in readOGR(dsn = fgdb, layer = "ESSENCE_MAJ", dropNULLGeometries = FALSE) :
no features found
In addition: Warning message:
In ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
ogrInfo: all features NULL
----------
与PEE_MAJ之类的另一层(即shapefile)相同的代码起作用.
The same code with another layer (that is a shapefile) like PEE_MAJ works.
fc = readOGR(dsn=fgdb,layer="PEE_MAJ",dropNULLGeometries=FALSE)
OGR data source with driver: OpenFileGDB
Source: "c:/Mrnmicro/VulnerabilitePeuplements/gdb/Produits_IEQM_04151.gdb", layer: "PEE_MAJ"
with 135202 features
It has 31 fields
您能帮我阅读ESSENCE_MAJ表中包含的功能吗?
Could you please help me to read features contained in the ESSENCE_MAJ table ?
推荐答案
我遇到了同样的问题.我当前的解决方案是直接从R调用OGR库,并将表的内容转储到我在R中读回的csv中:
I had the same problem. My current solution is to directly call the OGR library from R and dump the content of the table into a csv that I read back in R:
system("ogr2ogr -f CSV ESSENCE_MAJ.csv Produits_IEQM_04151.gdb ESSENCE_MAJ")
有关更多信息,请参见此处.它是在UNIX机器上,对于在Windows上调用ogr2ogr的确切命令还不太确定.希望对您有帮助!
See here for more info. It was on a unix machine, not quite sure about the exact command to call ogr2ogr on Windows. Hope it helps!
这篇关于如何使用R从ESRI文件地理数据库(.gdb)读取表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!