Issue to extract raster pixel values in different elevation zones

I have large daily datasets in raster format. I want to extract pixel based on values in different polygons in a single shapefile. The shapefile is basically STRM DEM 90 meter classified 24 elevation zones. These 24 elevation zones bascially representing 24 polygons in single shapefile. I want to check how many pixel occupied by each polygon. Primarily, I need to check the number of pixels based on following values (200,210,240,250) in each polygon and finally store it into csv. I already developed code: But facing issue by end. Kindly guide me. Thanks

mod = raster("MOYDGL06_Maximum_Snow_Extent_2004097.tif")
shp= readOGR("Gilgit_DEM_24.shp")
mod_ext =  extract(mod,shp,df=T,na.rm=T)
mod_mask = mask(mod,shp)
plot(r2,axes = TRUE,ext = extent(shp))
r3_200    =  rasterToPoints(mod_mask,function(x){ x ==200 },spatial = TRUE)
r3_210    =  rasterToPoints(mod_mask,function(x){ x ==210 },spatial = TRUE)
r3_240    =  rasterToPoints(mod_mask,function(x){ x ==240 },spatial = TRUE)
r3_250    =  rasterToPoints(mod_mask,function(x){ x ==250 },spatial = TRUE)
r3_200_1          =    raster::intersect(shp,r3_200)
write.csv(r3_200_1,file = 'r2_extract_gilgit.csv')

Kindly find the image and R code in below link

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.