【问题标题】:Import CSV with postgres geometry column as SF将带有 postgres 几何列的 CSV 导入为 SF
【发布时间】:2019-10-15 15:25:06
【问题描述】:

我有一个带有 postgis 几何列的 csv 文件。我想将 csv 导入 R 并将文件导出到 postgres 数据库。我正在尝试将几何列设置为正确的 postgis 几何数据类型。但是,我不断收到此警告消息:

“警告信息: "不存在简单的特征几何:返回一个 data.frame 或 tbl_df""

我用过:

file <- st_read("name.csv", stringsAsFactors=F, geometry_column=geom) and

file <- fread("name.csv", headers=True)
file <- st_as_sf(file)

任何帮助将不胜感激!

【问题讨论】:

  • 为什么不使用 COPY 或 \copy 将其直接加载到 PostgreSQL?如果通过 R 传递它会导致问题,那么....不要。
  • 在将表加载到数据库之前,我正在 R 中进行其他一些编辑。

标签: r postgresql csv postgis sf


【解决方案1】:

感谢 r-sig-geo listserv,我找到了答案

#1. convert the geometry strings to sf spatial objects:
newGeom = st_as_sfc(structure(as.character(file$geom), class = "WKB"),EWKB=TRUE)

#2. create a new spatial data frame with the new spatial objects as geometry
sdf = st_set_geometry(file, newGeom)

#3. (optional) drop the character format column
sdf$geom=NULL

【讨论】:

  • 哦,是的,那是我的回答!您可能会考虑将来在gis.stackexchange.com,空间和 GIS 问题的网站上提问。
  • 会的!谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 2012-06-21
  • 1970-01-01
  • 1970-01-01
  • 2020-02-17
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 2021-10-02
相关资源
最近更新 更多