我正在尝试使用rgdal :: readOGR读取.gdb文件。几天前,我终于通过删除路径末尾的“ /”和文件名末尾的.gdb使其工作了。然后,of!今天我的代码行不通。据我所知,什么都没有改变!
代码失败后,我尝试更新所有内容,因此我现在正在运行:Mac OS10.14.4,RStudio v1.2.1335,R v3.6.0和rgdal v1.4-3。我检查过rgdal是否具有OpenFileGDB驱动程序。我也尝试过将.gdb扩展名添加到文件名中,并更改.lyr文件名以匹配该.gdb文件名,但是没有任何效果。
这是我正在使用的代码...
gdb <- path.expand("Data/GIS/CA_LandUse2014/ds2677")
luca <- readOGR(gdb, "ds2677")
这是错误消息:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
Cannot open data source
这些是ds2677文件夹中的文件:
> list.files(path.expand("Data/GIS/CA_LandUse2014/ds2677"))
[1] "ds2677_LandUse2014.lyr" "ds2677.gdb"
这些是ds2677.gdb中的文件。
> list.files(path.expand("Data/GIS/CA_LandUse2014/ds2677/ds2677.gdb"))
[1] "a00000001.freelist" "a00000001.gdbindexes"
[3] "a00000001.gdbtable" "a00000001.gdbtablx"
[5] "a00000001.TablesByName.atx" "a00000002.gdbtable"
[7] "a00000002.gdbtablx" "a00000003.gdbindexes"
[9] "a00000003.gdbtable" "a00000003.gdbtablx"
[11] "a00000004.CatItemsByPhysicalName.atx" "a00000004.CatItemsByType.atx"
[13] "a00000004.FDO_UUID.atx" "a00000004.freelist"
[15] "a00000004.gdbindexes" "a00000004.gdbtable"
[17] "a00000004.gdbtablx" "a00000004.spx"
[19] "a00000005.CatItemTypesByName.atx" "a00000005.CatItemTypesByParentTypeID.atx"
[21] "a00000005.CatItemTypesByUUID.atx" "a00000005.gdbindexes"
[23] "a00000005.gdbtable" "a00000005.gdbtablx"
[25] "a00000006.CatRelsByDestinationID.atx" "a00000006.CatRelsByOriginID.atx"
[27] "a00000006.CatRelsByType.atx" "a00000006.FDO_UUID.atx"
[29] "a00000006.freelist" "a00000006.gdbindexes"
[31] "a00000006.gdbtable" "a00000006.gdbtablx"
[33] "a00000007.CatRelTypesByBackwardLabel.atx" "a00000007.CatRelTypesByDestItemTypeID.atx"
[35] "a00000007.CatRelTypesByForwardLabel.atx" "a00000007.CatRelTypesByName.atx"
[37] "a00000007.CatRelTypesByOriginItemTypeID.atx" "a00000007.CatRelTypesByUUID.atx"
[39] "a00000007.gdbindexes" "a00000007.gdbtable"
[41] "a00000007.gdbtablx" "a0000000a.FDO_GlobalID.atx"
[43] "a0000000a.gdbindexes" "a0000000a.gdbtable"
[45] "a0000000a.gdbtablx" "a0000000a.spx"
[47] "gdb" "timestamps"
请帮助!
答案 0 :(得分:0)
我没有使用过rgdal,但是用于与空间数据进行交互的另一个强大的替代方法是sf包。要从地理数据库加载,您可以使用st_read(dsn,layer)例如
library(sf)
luca <- st_read("data/mygeodatabase.gdb", layer = "layername")
答案 1 :(得分:0)
ogrListLayers(src)
告诉您什么?我认为src
应该是到达ds2677.gdb
并包括RI_geodatabase_wetlands.gdb
的路径。
这是对我有用的-a0000001.etc
是其中所有> ogrListLayers("/data/gdb/RI_geodatabase_wetlands.gdb")
[1] "Rhode_Island" "RI_Wetlands"
[3] "RI_Wetlands_Project_Metadata" "RI_Wetlands_Historic_Map_Info"
attr(,"driver")
[1] "OpenFileGDB"
attr(,"nlayers")
[1] 4
文件的文件夹:
> RI = readOGR("/data/gdb/RI_geodatabase_wetlands.gdb","Rhode_Island")
OGR data source with driver: OpenFileGDB
Source: "/data/gdb/RI_geodatabase_wetlands.gdb", layer: "Rhode_Island"
with 1 features
It has 5 fields
现在我有了可以一次读取一层的层名称:
gdb <- path.expand("Data/GIS/CA_LandUse2014/ds2677")
luca <- readOGR(gdb, "ds2677")
看看您在这里尝试过什么:
gdb <- path.expand("Data/GIS/CA_LandUse2014/ds2677/ds2677.gdb")
ogrListLayers(gdb)
我怀疑您应该这样做:
luca <- readOGR(gdb, "some_layer_name")
然后选择所需的图层名称并执行操作:
[{"picture": "XXX", "image_hash": null, "name": "test", "video": null, "link": "http://www.google.com", "table_id": 356}, ..]
答案 2 :(得分:0)
这是我在没有ARC-GIS许可证的Windows 10上使用rgdal 1.4-4驱动程序在R 3.60中进行此操作的方法。请注意,我最终会将* .gdbtable文件转换为shp文件,以便在Google Earth Pro上使用。 gdbtable文件中只有一个没有“空几何”或我不感兴趣的字段。因此编号文件对我而言并不有趣。但是ogrInfo证明“ a0000000b.gdbtable”很有趣。警告:我只是发布我如何破解此内容。很多时候,我发现R特有的GIS代码足以使我不必费心去理解库的功能。我只是使它工作得足够好,可以给我导入ESRI shp文件。
dir(pattern="*gdbtable")
[1] "a00000001.gdbtable" "a00000002.gdbtable" "a00000003.gdbtable" "a00000004.gdbtable" "a00000005.gdbtable" "a00000006.gdbtable" "a00000007.gdbtable" "a0000000b.gdbtable"
library(data.table)
library(rgdal) #rgdal_1.4-4
sessionInfo()
nrow(ogrDrivers())
as.data.table(ogrDrivers())[grepl("ESRI",long_name),]
cat('
name long_name write copy isVector
1: ESRI Shapefile ESRI Shapefile TRUE FALSE TRUE
2: OpenFileGDB ESRI FileGDB FALSE FALSE TRUE
')
setwd("C:/Users/username/Downloads/EAP_ENV_AmbientStations/EAP_ENV_AmbientStations.gdb")
ogrInfo("a0000000b.gdbtable")
cat('
Source: "C:\Users\username\Downloads\EAP_ENV_AmbientStations\EAP_ENV_AmbientStations.gdb\a0000000b.gdbtable", layer: "EAP_ENV_AmbientStations"
Driver: OpenFileGDB; number of rows: 557
Feature type: wkbPoint with 2 dimensions
Extent: (623276.8 93472.33) - (2533932 1367270)
CRS: +proj=lcc +lat_1=47.33333333333334 +lat_2=45.83333333333334 +lat_0=45.33333333333334 +lon_0=-120.5 +x_0=500000.0001016001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs
Number of fields: 22
name type length typeName
1 STATION 4 6 String
2 STANAME 4 35 String
3 WBID 4 10 String
... ')
a0000000b <- readOGR("a0000000b.gdbtable")
writeOGR(a0000000b,dsn="EAP_ENV_AmbientStations.gdb",layer="EAP_ENV_AmbientStations_b",driver="ESRI Shapefile")
as.data.table(data.frame(a0000000b))[,names(.SD)]
[1] "STATION" "STANAME" "WBID" "DECOREGN" "ECORGN" "WATERSHED" "GLACIAL" "SPECIALCRI" "CORE" "STRUCT" "SURROUND" "LOCATIONTY" "ELEV" "RMI" "LAT_DD" "LONG_DD" "TRS" "QUAD" "COUNTY"
[20] "CONGDIST" "LEGDIST" "CLASS" "coords.x1" "coords.x2" "optional"
bubble(a0000000b['LAT_DD'], col=rgb(0.5,0.5,1,0.5))