2

I am using the following instructions to read a TIGER/Line gdb into R.

The first commands work correctly and print out the feature classes:

fgdb <- "ACS_2014_5YR_BG_48_TEXAS.gdb"

subset(ogrDrivers(), grepl("GDB", name))
fc_list = ogrListLayers(fgdb)
print(fc_list)

 [1] "ACS_2014_5YR_BG_48_TEXAS"            "BG_METADATA_2014"                   
 [3] "X00_COUNTS"                          "X01_AGE_AND_SEX"                    
 [5] "X02_RACE"                            "X03_HISPANIC_OR_LATINO_ORIGIN"      
 [7] "X07_MIGRATION"                       "X08_COMMUTING"                      
 [9] "X09_CHILDREN_HOUSEHOLD_RELATIONSHIP" "X11_HOUSEHOLD_FAMILY_SUBFAMILIES"   
[11] "X12_MARITAL_STATUS_AND_HISTORY"      "X14_SCHOOL_ENROLLMENT"              
[13] "X15_EDUCATIONAL_ATTAINMENT"          "X16_LANGUAGE_SPOKEN_AT_HOME"        
[15] "X17_POVERTY"                         "X19_INCOME"                         
[17] "X20_EARNINGS"                        "X21_VETERAN_STATUS"                 
[19] "X22_FOOD_STAMPS"                     "X23_EMPLOYMENT_STATUS"              
[21] "X24_INDUSTRY_OCCUPATION"             "X25_HOUSING_CHARACTERISTICS"        
[23] "X27_HEALTH_INSURANCE"                "X99_IMPUTATION"                     
attr(,"driver")
[1] "OpenFileGDB"
attr(,"nlayers")
[1] 24

However, when I try to import specific feature classes, the following error occurs:

> X01 = readOGR(dsn=fgdb,layer="X01_AGE_AND_SEX")
Error in readOGR(dsn = fgdb, layer = "X01_AGE_AND_SEX") : 
  no features found
In addition: Warning message:
In ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  :
  ogrInfo: all features NULL

These feature classes do not contain geometry data, which may be why there are no features found.

Is there workaround to read non-geometry feature classes into R from a gdb file ? The only solution I've found so far is to use GDAL command line tools to export the feature class to csv which would then be read into R, but I would like to cut out this middle step.

ogr2ogr -f CSV output.csv ACS_2014_5YR_BG_48_TEXAS.gdb X01_AGE_AND_SEX
  • I've just explored readOGR and we can do this at the R level by hacking out the bits that error and simply using the bits that reads the data frame. It's way overdue that someone finally did this. (It's not possible to do it in sf without recompiling). Feel free to get in touch. – mdsumner Feb 8 '17 at 6:26
  • Try this. gist.github.com/mdsumner/1112c8d89d99d1c13d0989320b612620 Let me know if you need help. Thanks for the trigger. – mdsumner Feb 8 '17 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.