Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

esri

sf

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")
like image 213
rhaefer Avatar asked Jul 31 '18 21:07

rhaefer


1 Answers

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.

like image 70
haff Avatar answered Oct 24 '22 14:10

haff