iza44
iza44

Reputation: 1

Extract band values to points from mosaic (ArcGIS) in R

I am classifying satellite images in ArcGIS. I would like to partially evaluate my results in R, e.g. through Crossvalidation. I want with mosaic (raster with 6 bands) extract band values to points but from my raster it only gets values from 1 band. How to get values from each bands?

Below is the code I used:

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) 

I would like to receive data.frame with the values of all bands at selected points.

Upvotes: 0

Views: 108

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47481

Here is a minimal, self-contained, reproducible example, with a minor modification from ?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 ...

Upvotes: 0

Related Questions