【问题标题】:Extract band values to points from mosaic (ArcGIS) in R从R中的马赛克(ArcGIS)中提取波段值到点
【发布时间】:2020-10-25 04:51:24
【问题描述】:

我在 ArcGIS 中对卫星图像进行分类。我想部分评估我在 R 中的结果,例如通过交叉验证。 我想用马赛克(6 个波段的栅格)将波段值提取到点,但从我的栅格中它只能从 1 个波段获取值。如何从每个波段获取值?

下面是我使用的代码:

df <- mosaic %>% 
extract(y = points) %>%  
as.data.frame %>% 
mutate(id_cls = points@data$id_cls) %>% 
left_join(y = unique(poly@data), by = c("id_cls" = "id")) %>% 
mutate(id_cls = NULL) 

我想接收带有选定点所有波段值的 data.frame。

【问题讨论】:

    标签: r classification raster arcgis cross-validation


    【解决方案1】:

    这是一个最小的、独立的、可重现的示例,对 ?extract 进行了少量修改

    r <- raster(ncol=36, nrow=18, vals=1:(18*36))
    s <- stack(r,r,r)  # similar to your mosaic 
    # from what I see you are using polygons to extract?
    cds1 <- rbind(c(-180,-20), c(-160,5), c(-60, 0), c(-160,-60), c(-180,-20))
    cds2 <- rbind(c(80,0), c(100,60), c(120,0), c(120,-55), c(80,0))
    polys <- spPolygons(cds1, cds2)
    
    v <- extract(r, polys)
    str(v)
    #List of 2
    # $ : num [1:38] 326 327 328 329 330 331 332 333 334 335 ...
    # $ : num [1:23] 173 208 209 244 245 280 281 282 315 316 ...
    

    【讨论】:

      猜你喜欢
      • 2021-01-09
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      • 2012-08-28
      相关资源
      最近更新 更多