I have a a big feature class in geodatabase (~1.3 million rows and 234 columns; you could download it using this link) in ArcGIS 10.4.1.
I want to import the feature class from the geodatabase to R and plot specific variables (using ggplot2).
I tried importing it into R, using the answer of this question, as below
require(rgdal)
# The input file geodatabase
fgdb = "C:/Question_Online/union_question.gdb"
# List all feature classes in a file geodatabase
subset(ogrDrivers(), grepl("GDB", name))
fc_list = ogrListLayers(fgdb)
print(fc_list)
# Read the feature class
fc = readOGR(dsn=fgdb,layer="union_thirdtrial")
However, it took more than an hour, so I had to close RStudio to terminate the process.
Can anyone point out what I am missing for a better (faster) way to import this feature class to R?
1 Answer 1
You can use st_read
from the sf package. It reads the GeoDatabase as a SimpleFeatures object, which you can convert to SpatialPolygonsDataFrame using the as()
method. One caveat: the conversion does not allow for a Z-dimension, so you have to drop it.
I read your union_question.gdb
in ~ 15 minutes with st_read()
. The conversion to SPDF took 11 minutes.
library(sf)
library(sp)
x <- st_read(dsn="union_question.gdb")
y <- st_drop_zm(x)
z <- as(y, "Spatial")
-
Thanks for your time and help. I got this error after running
z <- as(y, "Spatial")
Error: cannot allocate vector of size 14 Kb. I will appreciate any help how to fix it.shiny– shiny2017年01月11日 22:42:53 +00:00Commented Jan 11, 2017 at 22:42 -
That sounds like a memory issue. Either you need more physical RAM, or you can try to increase R's memory by observing the output of
memory.limit()
, and then increasing it withmemory.limit(size = x)
.eivindhammers– eivindhammers2017年01月11日 23:19:40 +00:00Commented Jan 11, 2017 at 23:19 -
Thanks for your help. I'm using Windows 7 64-bit and my PC has 16 GB RAM. I checked
memory.limit() [1] 16264
I think this means it is 16264 Mb which is higher than the actual memory of my PC. I think this means I don't need to increase it. Any feedback will be appreciated.shiny– shiny2017年01月12日 00:56:46 +00:00Commented Jan 12, 2017 at 0:56 -
1Then unfortunately I'm not sure what the problem is. Consider saving a copy of the GDB containing only the fields you need to plot in R.eivindhammers– eivindhammers2017年01月16日 16:10:55 +00:00Commented Jan 16, 2017 at 16:10
-
1I have 8 GB memory, so that's not your problem. I'm not sure how to help you further. I would suggest figuring out how to make a copy of your GDB with only necessary fields, but it's hard to provide help for that (at least without further information).eivindhammers– eivindhammers2017年01月16日 22:00:42 +00:00Commented Jan 16, 2017 at 22:00
Explore related questions
See similar questions with these tags.