【问题标题】:Joining sfc objects and assigning categorical attribute using maximum overlapping area使用最大重叠区域连接 sfc 对象并分配分类属性
【发布时间】:2020-05-12 12:36:18
【问题描述】:

想象以下 sfc 对象

zone_A <- st_as_sfc(st_bbox(c(xmin = 0, ymin = 0, xmax = 2, ymax = 2)))
zone_B <- st_as_sfc(st_bbox(c(xmin = 0, ymin = 2, xmax = 2, ymax = 4)))
Zones <- st_as_sf(data.frame(class = c("A", "B"),c(zone_A, zone_B)))
st_crs(Zones) <- "WGS84"

feat_X <- st_as_sfc(st_bbox(c(xmin = 0.5, ymin = 1.25, xmax = 1.5, ymax = 3.5)))
feat_Y <- st_as_sfc(st_bbox(c(xmin = 0.1, ymin = 0.5, xmax = 0.5, ymax = 2.2)))
feat_Z <- st_as_sfc(st_bbox(c(xmin = 1.5, ymin = 2.5, xmax = 1.9, ymax = 3.5)))
feat <- st_as_sf(data.frame(name = c("X", "Y", "Z"),c(feat_X, feat_Y, feat_Z)))
st_crs(feat) <- "WGS84"

看起来像这样:

ggplot showing to superimposed layers

我的任务是将这两层连接起来,并将来自Zones 对象的分类变量class 分配给feat 对象的每个特征。如果一个要素与两个区域重叠,则重叠区域应作为分配哪个类的标准。

虽然这可以通过使用 st_join 的明确覆盖(例如 Z int 示例)轻松完成,但如果一个特征与 Zones 对象的两个特征交叉(像 X 和 Y)。在这里,我寻求一种计算交叉点面积、比较面积并将较大交叉点的class 属性分配给整个要素的解决方案。理想情况下,这应该适用于具有多个多边形(可能遍历所有不明确的多边形)的更大 sfc 对象。

这类似于st_interpolate_aw,但使用的是分类数据而不是数字数据。我不知道有什么现成的功能可以做到这一点

【问题讨论】:

    标签: join attributes sf


    【解决方案1】:

    st_join 函数具有参数largest。如果您设置largest=TRUE,它将“返回 x 的特征,这些特征增加了与 x 的每个特征有最大重叠的 y 的字段”。看这里 - https://r-spatial.github.io/sf/reference/st_join.html

    这是你需要的吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2014-07-15
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2017-08-31
      相关资源
      最近更新 更多