I'm taking an R class and I have an assignment that I'm trying to figure out. Instructor wants us to save all layers in a gdb file as sf objects. He told us that we should use loops.
I'm able to import the gdb file using
scd <- st_read(dsn='/path/to.gdb')
And I'm also able to list layers using
scdl <- st_layers(dsn='/path/to.gdb')
Update:
st_read(dsn = '/path/to.gdb', layer=i)
feat <- st_read(code here)
}
i
this is what I have done so far which loops over the layernames. but when I try to assign them to objects using feat <- st_read(code here)
line, it breaks my loop.
"Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : Expecting a single value: [extent=5]. In addition: Warning message: In if (nchar(dsn) < 1) { : the condition has length > 1 and only the first element will be used"
for
function or any of theapply
family of functions? – Spacedman Sep 17 '20 at 5:46scd <- st_read(dsn='/path/to.gdb')
scdl <- st_layers(dsn='/path/to.gdb')
for(i in scd) {
st_as_sf(scd)
save(scd, file="layer")
st_write(i)
``` scdl gives me the names of every layer. but I need to save those layers as separate files which, I couldn't figure out. I assumed looping over scdl would work but it doesn't work. – puredata Sep 17 '20 at 6:08