R-ArcGIS:无法执行与数据框的 dplyr 连接?

R-ArcGIS: Impossible to perform dplyr join with data frame?

我刚刚开始使用 R-ArcGIS 桥接程序包 arcgisbinding,当我尝试将特征 class 数据与 [=12] 连接时,我 运行 遇到了问题=] 包。这是一个示例,我试图将两个 shapefile 中的臭氧柱放入单个数据框中,然后作为 shapefile 导出回来。

library(dplyr)
library(arcgisbinding)
arc.check_product()

fc <- arc.open(system.file("extdata", "ca_ozone_pts.shp",
                       package="arcgisbinding"))
d <- arc.select(fc, fields=c('FID', 'ozone'))
p<-arc.select(fc,fields=c('FID', 'ozone'))
p$ozone<-p$ozone*2
p<-left_join(p,d,by="FID")
arc.write(tempfile("ca_new", fileext=".shp"), p)
# original dataframe has shape attributes
str(d)
# new dataframe does not
str(p)

来自arcgisbinding包,上面的pd是具有形状属性的数据框对象。问题是,一旦我使用 left_join,我就会丢失连接数据框中的空间属性数据。有解决办法吗?

显然这是一个已知问题 (see GitHub here)。

使用 spdplyr 包的解决方法来自 ESRI GeoNet (link to thread) 上的 Shaun Wallbridge。基本上,将 arc.data 数据框转换为 sp 对象,执行分析,然后导出为特征 class 或 shapefile。

library(spdplyr)
library(arcgisbinding)
arc.check_product()

fc <- arc.open(system.file("extdata", "ca_ozone_pts.shp", package="arcgisbinding"))
d <- arc.select(fc,fields=c('FID', 'ozone'))
d.sp <- arc.data2sp(d)

p <-arc.select(fc,fields=c('FID', 'ozone'))
p.sp <- arc.data2sp(p)
p.sp$ozone <- p$ozone*2

joined <- left_join(p.sp, d.sp, by="FID", copy=TRUE)
joined.df <- arc.sp2data(joined)

arc.write(tempfile("ca_ozone_pts_joined", fileext=".shp"), joined.df)