[Qgis-developer] get mean of pixel values within defined area around current mouse position

Fred Lehodey lehodey at gmail.com
Tue Jul 2 10:05:10 PDT 2013


Hi,

Not sure it's the best way but I did something similar with these
workarounds:

A - with gdal:
1 - the user click and you get your buffer. (already done)
2 - use gdalwarp with "-cutline" and "*-*crop_to_cutline" options to
extract a new raster. (python subprocess)
3 - read the created raster in a numpy array to do all the statistics you
need.

B - with matplotlib:
1 - with the buffer: create an array of the vertices
2 - read the raster into another numpy array
3 - use the "points_inside_poly" function of "matplotlib" lib to create a
numpy mask.

Not tried but postgis raster should do the job.

Hth,
Fred


On Tue, Jul 2, 2013 at 1:12 PM, Otto Dassau <dassau at gbd-consult.de> wrote:

> Hi,
>
> for a qgis 1.8 plugin I would like to query the mean of pixel values of a
> raster layer within a defined buffer for the current mouse position (not
> for
> an existing point layer).
>
> For the buffer it works:
>
> ...
> feat.geometry().asPoint()
> (3.5176e+06,5.4062e+06)
> buff_geom = feat.geometry().buffer(1000, 5)
> buff_geom.asPolygon() [[(3.5186e+06,5.4062e+06), (3.51855e+06,5.4059e+06),
> (3.51841e+06,5.40562e+06), (3.51819e+06,5.4054e+06),
> (3.51791e+06,5.40525e+06), (3.5176e+06,5.4052e+06),
> (3.51729e+06,5.40525e+06), (3.51701e+06,5.4054e+06),...]]
>
> but now I try to find a solution to query the raster pixels within the
> buffer zone and calculate the mean, but I don't know how and if this is
> possible in QGIS 1.8 at all. I found QgsZonalStatistics, but that doesn't
> work for my task.
>
> Does anybody have a solution for this or a better idea, how to solve this?
>
> Thanks
>
> Otto
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20130702/2a3d0e68/attachment.html>


More information about the Qgis-developer mailing list