readOGR .gdb with multiple Feature Datasets in R

2.8k views Asked by At

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
      ...
2

There are 2 answers

0
hrbrmstr On

THIS IS NOT AN ANSWER but more space is needed for clarification since the OP did not provide a reproducible example. I will delete this once the OP q is more complete.

When I run ogrinfo on NHDH_CT.gdb (one of the smaller archives) I get:

Layer name: NHDPoint
Layer name: NHDFlowline
Layer name: NHDLine
Layer name: NHDArea
Layer name: NHDWaterbody
Layer name: NHDAreaEventFC
Layer name: NHDLineEventFC
Layer name: NHDPointEventFC
Layer name: WBDLine
Layer name: NonContributingDrainageArea
Layer name: NWISBoundary
Layer name: NWISDrainageArea
Layer name: WBDHU14
Layer name: WBDHU8
Layer name: WBDHU2
Layer name: WBDHU4
Layer name: WBDHU6
Layer name: WBDHU10
Layer name: WBDHU12
Layer name: WBDHU16
Layer name: HYDRO_NET_Junctions

That matches:

> ogrListLayers("NHDH_CT.gdb")
 [1] "NHDPoint"                    "NHDFlowline"                 "NHDLine"                    
 [4] "NHDArea"                     "NHDWaterbody"                "NHDAreaEventFC"             
 [7] "NHDLineEventFC"              "NHDPointEventFC"             "WBDLine"                    
[10] "NonContributingDrainageArea" "NWISBoundary"                "NWISDrainageArea"           
[13] "WBDHU14"                     "WBDHU8"                      "WBDHU2"                     
[16] "WBDHU4"                      "WBDHU6"                      "WBDHU10"                    
[19] "WBDHU12"                     "WBDHU16"                     "HYDRO_NET_Junctions"        

What are you expecting to see? What does your ogrinfo show? (NOTE: Hawaii's gave similar output).

0
Mike T On

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:

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).