[gdal-dev] Sum pixel values in selected area of an image
Even Rouault
even.rouault at spatialys.com
Thu Oct 2 08:00:46 PDT 2014
Le jeudi 02 octobre 2014 09:02:00, Lukasz Tracewski a écrit :
> Hi,
> I only recently started my adventure with GDAL and GIS in general, so
> please accept my apologies for perhaps maybe the most accurate formulation
> of the problem. I also did my best to find the answer already on this
> mailing list and outside, but to no avail - again possibly due to lack of
> experience. Last year Hansen et al. prepared a detailed map, 30 meters
> resolution, of forest cover for the whole planet. The data is publicly
> accessible, both for online viewing and download. Both can be found here:
> http://earthenginepartners.appspot.com/science-2013-global-forest The
> forest cover images are GeoTIFF and have pixel values in range [0, 100]
> that describes percentage of forest cover. I have some georeferenced
> images that essentially are composed of ones and zeros, e.g.:0 1 1 0 00 1
> 1 1 00 1 0 0 0... Those images are in 1000 meters scale and can spawn over
> whole continents. My aim is to calculate forest cover for them: wherever
> the value is "1", this pixel should be added to the forest cover. Say the
> Hansen image looks like this:10 20 30 40 5010 80 80 0 00 0 0 0 0... Then
> rows and column of this images should be multiplied by respective rows and
> columns of my own image, producing: 0 * 10 + 20 * 1 + 30 * 1 + 40 * 0 + 50
> * 0 + 10 * 0 + 80 * 1 + ... = 210 Mind that scale of both images is
> different, so the example above is actually not accurate. The real
> calculations should average pixel values, then sum them and then convert
> to area. Can anyone point me where to start? Maybe you know of any
> examples that could give me a hint?
Lukasz,
There are likely many ways of doing that. Here's a potential workflow
1) With gdalwarp -r averge -ts you could make sure both raster have same
dimensions
2) Use gdal_calc.py to do the multiplication pixel by pixel.
3) Use gdalinfo -stats to compute statistics on the raster generated by 2).
Multiply the MEAN value by the raster width and raster height, and that will
give you the sum.
Even
>
> Thanks,Lucas
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list