I am trying to read shapefiles contained within a geodatabase file (.gdb) into R. The .gdb contains two Feature Datasets with multiple Feature Classes within each.
The problem is only one of the two Feature Datasets is being read. Specifically, I am using the NHD dataset for all states ftp://nhdftp.usgs.gov/DataSets/Staged/States/FileGDB/HighResolution/ In each state .gdb are two feature Datasets, 'WBD' and 'Hydrography'. Only 'WBD' is being read. Using ogrListLayers only returns layers from 'WBD'. How can I specify the 'Hydrography' dataset and access the Feature Classes within it?
Any suggestions would be much appreciated. R version 3.2.0. OSX v.10.10.3
Edit 06/16/15: When I run orgListLayers, it returns:
ogrListLayers('NHDH_VI.gdb')
[1] "ExternalCrosswalk" "NHDFCode" "NHDFeatureToMetadata"
[4] "NHDFlow" "NHDFlowlineVAA" "NHDMetadata"
[7] "NHDProcessingParameters" "NHDReachCodeMaintenance" "NHDReachCrossReference"
[10] "NHDSourceCitation" "NHDStatus" "NHDVerticalRelationship"
[13] "WBDHU14" "WBDHU8" "WBDHU2"
[16] "WBDHU4" "WBDHU6" "WBDHU10"
[19] "WBDHU12" "WBDHU16" "HYDRO_NET_Junctions"
The 21 layers are different then expressed by Mike T and hrbrmstr. Specifically I am looking for: Layer name: NHDWaterbody.
When I runogrinfo -ro NHDH_VI.gdb
from terminal.
ERROR 1: Error: Failed to open Geodatabase (This release of the GeoDatabase is either invalid or out of date.)
FAILURE: Unable to open datasource `NHDH_VI.gdb' with the following drivers.
-> FileGDB
-> OpenFileGDB
...
You are probably reading the file with the ESRI File Geodatabase (OpenFileGDB) driver. OGR does not preserve or use feature datasets, so all the feature classes are mixed in the same flat namespace. Looking at (e.g.) NHDH_VI.gdb in ArcCatalog:
Then reading the same file from a command-line prompt with ogrinfo -ro NHDH_VI.gdb
INFO: Open of `NHDH_VI.gdb'
using driver `OpenFileGDB' successful.
1: NHDPoint (Point)
2: NHDFlowline (Multi Line String)
3: NHDLine (Multi Line String)
4: NHDArea (Multi Polygon)
5: NHDWaterbody (Multi Polygon)
6: NHDAreaEventFC (Multi Polygon)
7: NHDLineEventFC (Multi Line String)
8: NHDPointEventFC (Point)
9: WBDLine (Multi Line String)
10: NonContributingDrainageArea (Multi Polygon)
11: NWISBoundary (Multi Line String)
12: NWISDrainageArea (Multi Polygon)
13: WBDHU14 (Multi Polygon)
14: WBDHU8 (Multi Polygon)
15: WBDHU2 (Multi Polygon)
16: WBDHU4 (Multi Polygon)
17: WBDHU6 (Multi Polygon)
18: WBDHU10 (Multi Polygon)
19: WBDHU12 (Multi Polygon)
20: WBDHU16 (Multi Polygon)
21: HYDRO_NET_Junctions (Point)
And the same is available from in R:
> library(rgdal)
> ogrListLayers("NHDH_VI.gdb")
[1] "NHDPoint" "NHDFlowline"
[3] "NHDLine" "NHDArea"
[5] "NHDWaterbody" "NHDAreaEventFC"
[7] "NHDLineEventFC" "NHDPointEventFC"
[9] "WBDLine" "NonContributingDrainageArea"
[11] "NWISBoundary" "NWISDrainageArea"
[13] "WBDHU14" "WBDHU8"
[15] "WBDHU2" "WBDHU4"
[17] "WBDHU6" "WBDHU10"
[19] "WBDHU12" "WBDHU16"
[21] "HYDRO_NET_Junctions"
attr(,"driver")
[1] "OpenFileGDB"
attr(,"nlayers")
[1] 21
So you need to manually filter the datasets from the ArcCatalog hierarchy to what you can find from OGR. Not all classes are available to OGR (e.g. non-spatial tables, relationship classes).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With