Skip to content
Prev 8332 / 29559 Next

Elevation histogram for each region

Cl?lia,

The optimal solution would depend a bit on your data. If the regions
are not too large, you could loop over the zones

library(raster)
lst = list()
for (i in 1:nzones) {
  p <- rasterToPoints(r, fun=function(x){x==i})
  lst[[i]] = histogram(p[,3])
}

If you also have the zones as polygons you could alternatively look
over the polygons and use  polygonValues in stead of rasterToPoints

Another, more elaborate, option could be to, in your loop, reclassify
the regions raster (1 / 0 ), multiply that with the elevation data;
trim the output raster, make a histogram (set maxpixels to
ncell(raster)) (this may take a long time to finish)

You could also first aggregate the rasters; unless you care much about
the extreme values.

Hope this helps,
Robert


On Wed, May 26, 2010 at 2:08 AM, Cl?lia Bilodeau
<clelia.bilodeau at gmail.com> wrote: