[R-sig-Geo] Elevation histogram for each region

Clélia Bilodeau clelia.bilodeau at gmail.com
Fri May 28 15:59:03 CEST 2010


Thank you for your help.
I'm still working on it.
I think the use of polygonValues is a good idea, but the script:

library(raster)
lst = list()
for (i in 1:nzones) {
p <- polygonValues(pol,r, fun=function(x){x==i})
lst[[i]] = histogram(p[,3])
}
doesn't work yet.
Do I have to define a function to use in "fun=function(x)(x==1)"?

Thank you.
C.


2010/5/26 Robert J. Hijmans <r.hijmans at gmail.com>:
> 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:
>> Dear list,
>>
>> I have two rasters, one is a Digital Elevation Model, and the other is
>> a region file.
>> I am looking for a method that allows me to plot the elevation
>> histogram or density for each region.
>>
>> My first try was to do this with a function and to use "Zonal" from
>> the "raster" package, but I have a very large file, so I have this
>> error:
>> "RasterLayers are too large. You can use fun='sum', 'mean', 'min', or
>> 'max', but not a function"
>>
>> Is there another way to do this?
>>
>> Thank you.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list