首页 > 解决方案 > 如何使用 st_write 将 sf 对象作为 shapefile 写入 ESRI 文件地理数据库?

问题描述

如何使用 st_write 将 sf 对象作为 shapefile 写入文件地理数据库?

我不太了解与文件地理数据库相关的 st_write 的“dsn”、“layer”和“driver”参数。

例如,我已经尝试了这两种方法并且没有运气

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")

标签: resrisf

解决方案


这里有几件事:首先,您不能将 shapefile 写入 ESRI 地理数据库,因为其中只能存储要素类和要素数据集。其次,您不能通过sf;写入地理数据库。你只能阅读它们。

你有几个选择。您可以使用以下命令将数据保存为地理数据库之外的 shapefile(或任何其他空间数据格式)sf

library(sf)

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

或者,如果您绝对需要写入地理数据库,您可以使用该arcgisbinding库,但请注意您需要使用具有有效 ArcGIS 许可的计算机。因此,这在 GNU/Linux 和 Mac 上是不行的。

因为我在 GNU/Linux 上,所以我无法验证这是否有效,但它应该是这样的:

library(arcgisbinding)

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

arcgisbinding可以在此处找到有关 R-ArcGIS Bridge(和包)的详细信息。


推荐阅读