[Qgis-developer] Raster histogram in Python plugin

Benoit de Cabissole benoit at exigesa.com
Sun Oct 17 13:15:59 EDT 2010


 Hi Tim,

Many thanks for your reply.

I see that the API doc classifies HistogramVector as a QVector but I
cannot find any reference of QVector in the Qt doc (there are QVector2D,
QVector3D and QVector4D). Could it be the problem?

What I'm trying to do is to improve the speed of my plugin '1-band
raster colour table' that allows to create colour table from a colour
palette and a colouring method. As I'm doing it in Python, the
computation of the stats and histogram takes for ever on large rasters.
I was hoping to piggyback on the stats and histo function built in QGIS
(they themselves are (very) slow on large rasters).

I agree that this work should be patched to the current code, but I'm
not able to program in C++/C...
So once the python plugin works as expected, it would be a good idea to
hand it over to a C++ guru for patching!

Cheers,
Benoit


On 17/10/2010 19:00, Tim Sutton wrote:
> Hi
>
> I see that member is commented out in the sip file for rasterbandstats:
>
> python/core/qgsrasterbandstats.sip
>
>  40     //HistogramVector * histogramVector;
>
> If I uncomment it I get a compile time error:
>
> sip: QgsRasterBandStats::histogramVector has an unsupported type -
> provide %GetCode and %SetCode
> make[2]: *** [python/analysis/sipanalysispart0.cpp] Error 1
> make[1]: *** [python/CMakeFiles/python_module_qgis_analysis.dir/all] Error 2
>
> So I guess the sip bindings need some tweaking to make it work.
>
> As an aside, if you are planning any tweaks improvements to the raster
> historgram, it would be great to do it as a patch to existing
> properties dialog rather than as a separate plugin. I found out how to
> enable zoom (but I wont do it in time for 1.6 release) on the charts.
> I also plan to add to the chart the user configured min/max entries
> per band, and maybe later a way to interactively set them on the
> chart.
>
> Regards
>
> Tim
>
> On Sun, Oct 17, 2010 at 4:09 PM, Benoit de Cabissole <benoit at exigesa.com> wrote:
>>  Hi all,
>>
>> Is it possible to access the histogramVector attribute from the
>> QgsRasterBandStats Class in Python code from a plugin?
>>
>> When the following code is run it issues the error:
>> AttributeError: 'QgsRasterBandStats' object has no attribute
>> 'histogramVector'
>>
>> self.theLayer.populateHistogram(1,grd.S.nClass)
>> myStats = self.theLayer.bandStatistics(1)
>> grd.S.Histo[0, 0] = myStats.histogramVector[0].y()
>>
>> where 'self.theLayer' is a one band raster image and 'grd.S.nClass' = 40001
>>
>> Python version: 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32
>> bit (Intel)]
>> QGIS version: 1.6.0-Trunk Trunk, 14378
>> >From OSGeo4W on WinXP.
>>
>> Cheers,
>> Benoit
>>
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>
>


More information about the Qgis-developer mailing list