I need to get multiple histograms from a tif image. I have the following data:
A big raster tif image:
tif1 <- raster("myRaster.tif") hist(tif1, breaks= 10) # gives the entire histogram
A shapefile of a country. This shapefile contains a polygon for each administrative area:
shp_np <- readOGR("NPL_adm2.shp")
I can think of a way to get the histogram by repetitively cropping raster tif using each Polygon in shapefile one by one. But, it is not efficient.
Now, I am searching for easy way to get the histogram information for each polygon in the shapefile.