How to write sf object as shapefile to ESRI file geodatabase with st_write?
Asked Answered
E

1

19

How do I write an sf object as a shapefile to a file geodatabase using st_write?

I don't quite understand the 'dsn', 'layer', and 'driver' arguments of st_write in relation to file geodatabases.

For example, I've tried both of these and no luck

st_write(sf.object, dsn = "filepath/FileGeoDatabase.gbd",layer="name of output layer", driver="OpenFileGDB")

st_write(sf.object, dsn = "filepath/FileGeoDatabase.gbd",layer="name of output layer", driver="ESRI Shapefile")
Embry answered 31/7, 2018 at 21:17 Comment(0)
P
21

A couple things here: first, you can't write a shapefile to an ESRI geodatabase as only feature classes and feature datasets can be stored in there. Second, you can't write to geodatabases via sf; you can only read them.

You have a couple of options. You can save your data as a shapefile (or any other spatial data format) outside of the geodatabase with sf:

library(sf)

## it will guess the driver automatically based on the .shp extension
st_write(sf.object, "data/my_shapefile.shp")

Or, if you absolutely need to write in a geodatabase, you can use the arcgisbinding library, but note you will need to be using a machine with an active ArcGIS license. Hence, this is a no-go on GNU/Linux and Mac.

I can't verify that this works since I am on GNU/Linux, but it should be something along these lines:

library(arcgisbinding)

arc.write("data.gdb/fc", sf.object)

Details on the R-ArcGIS Bridge (and the arcgisbinding package) can be found here.

Putscher answered 4/11, 2019 at 7:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.