Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

readOGR .gdb with multiple Feature Datasets in R

Tags:

r

gis

gdal

rgdal

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
      ...
like image 907
habd Avatar asked Jun 15 '15 17:06

habd


1 Answers

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

like image 92
Mike T Avatar answered Sep 20 '22 12:09

Mike T