【问题标题】:R-ArcGIS: Impossible to perform dplyr join with data frame?R-ArcGIS:无法使用数据框执行 dplyr 连接?
【发布时间】:2023-04-03 16:06:01
【问题描述】:

我刚刚开始使用 R-ArcGIS bridge 包arcgisbinding,当我尝试将要素类数据与dplyr 包连接时遇到了问题。这是一个示例,我试图将两个 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,我就会丢失连接数据框中的空间属性数据。有没有办法解决这个问题?

【问题讨论】:

    标签: r dplyr arcgis


    【解决方案1】:

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

    使用spdplyr 包的解决方法来自 ESRI GeoNet (link to thread) 上的 Shaun Wallbridge。基本上,将 arc.data 数据框转换为 sp 对象,执行分析,然后导出为要素类或 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多