I am trying to read a table directly from an ESRI file geodatabase into R. An example data file can be downloaded here. The database contains a point feature class (Zone9_2014_01_Broadcast) and two linked tables (Zone9_2014_01_Vessel and Zone9_2014_01_Voyage). You can read the shapefile in R using readOGR
from the rgeos
package:
library(rgeos)
library(downloader)
download("https://coast.noaa.gov/htdata/CMSP/AISDataHandler/2014/01/Zone9_2014_01.zip", dest="Zone9_2014_01.zip", mode="wb")
unzip("Zone9_2014_01.zip", exdir = ".")
# Not Run (loads large point file)
# broadcast <- readOGR(dsn = "Zone9_2014_01.gdb", layer = "Zone9_2014_01_Broadcast")
The two linked tables also show when you use ogrListLayers
or ogrInfo
. However, ogrInfo
gives a warning:
Warning message: In ogrInfo("Zone9_2014_01.gdb", layer = "Zone9_2014_01_Vessel") : ogrInfo: all features NULL
And if you try to use readOGR
on the tables you get an error:
vessel <- readOGR(dsn = "Zone9_2014_01.gdb", layer = "Zone9_2014_01_Vessel")
Error in readOGR(dsn = "Zone9_2014_01.gdb", layer = "Zone9_2014_01_Vessel") : no features found In addition: Warning message: In ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : ogrInfo: all features NULL
Thus, it appears that only geographical features can be read by readOGR. Is there any way to import the tables directly into R or is the only solution to first export them from ArcGIS as *.dbf (or *.txt) files as in this answer?
As an addition, if anyone can provide calls from R to a python script that automates the export of *csv (preferrably) or *.dbf files, that would be an acceptable work-around. The solution just needs to be scalable and automated.
Answer
I'm a little bit late to the party, but this can now be read by sf
, with
vessel <- sf::st_read(dsn = "Zone9_2014_01.gdb", layer = "Zone9_2014_01_Vessel")
It returns a warning (no feature geometries present) but also a data.frame with the table. See the thread that started here: https://stat.ethz.ch/pipermail/r-sig-geo/2018-February/026344.html
No comments:
Post a Comment