将带有 postgres 几何列的 CSV 导入为 SF

Import CSV with postgres geometry column as SF

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

”警告信息: "no simple feature geometries present: returning a data.frame or tbl_df""

我用过:

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

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

如有任何帮助,我们将不胜感激!

感谢 r-sig-geo 列表服务,我找到了答案

#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