[Qgis-developer] error for QGIS tutorials in python - adding
rasters to canvas
volkan kepoglu
vkepoglu at gmail.com
Fri Jan 25 03:02:32 EST 2008
As I am new baby, I may be sauciness or wise guy or inexperience, but or I
am. I also do not know whether these adjectives are appropriate for me.
:-) But I wondered to ask... just commenting...
Backward compatibility is cared, isn't? I mean there is obvious reason to
add setColorShadingAlgorithm and setContrastEnhancementAlgorithm in 0.9.2.
Isn't it possible to keep setColorRampingType and setColorScalingAlgorithm
also in 0.9.2? They exist in 0.9.1 that is released. Version 0.9.1 and
0.9.2is so close.
I know the reason is that "Tradeoff between backward compatibility and
architectural quality." howver, the change of code is so fast. Is it normal
case for Linux? Or is QGIS fast growing and developing environment? Thanks
for your efforts.
With my best regard,
Volkan Kepoglu
On 1/24/08, Peter Ersts <ersts at amnh.org> wrote:
>
> Martin,
>
> QgsRasterLayer::setDrawingStyle() [Same in 0.9.1]
> QgsRasterLayer->setColorShadingAlgorithm() [was setColorRampingType in
> 0.91]
> QgsRasterLayer->setContrastEnhancementAlgorithm() [was
> setColorScalingAlgorithm in 0.9.1]
> ***Each of these sets a corresponding get method. And these are the only
> three things that must be understood to draw a raster layer
>
> in 0.9.2, the abstracted draw process per pixel is:
> For gray scale or RGB images
> Read data from band -> Check NoDataValue -> Get transparency level ->
> Stretch -> Invert (if necessary) -> Display
> For paletted, pseudo color, for custom color maps
> Read data from band -> Check NoDataValue -> Get transparency level ->
> Shade(color) -> Invert (if necessary) -> Display
>
> There are now a couple of new classes:
> QgsContrastEnhancement - This class is responsible for implementing the
> contrast enhancement. QgsRasterLayer calls
> QgsContrastEnhancement::stretch(pixel value) and is returned a stretched
> value(int). The actual stretching is done by what ever the current
> QgsContrastEnhancementFunction [virtual base class] does. This is a per
> pixel operation at the moment, because it is close to a direct port of
> what was previously being done in the draw loop in QgsRasterLayer. For 8
> and 16 bit data a lookup table is generated to speed things up, 32-bit
> data are computed each call to stretch().
>
> QgsRasterShader - Is similar in idea to QgsContrastEnhancement, but no
> lookup table at the moment. QgsRasterShader::generateShadedValue(pixel
> value, &returnRed, &returnGreen, &returnBlue) computes a RGB value for
> the provided pixel value. The actual computation is done by a
> QgsRasterShaderFunction[virtual base class].
>
> Programatically, you could create your own shader or contrast
> enhancement function by inheriting the base QgsRasterShaderFunction or
> QgsConstrastEnhancementFunction then calling,
> QgsRasterLayer::setContrastEnhancementFunction(new
> MyContrastEnhancementFunction())
> QgsRasterLater::setSetRasterShaderFunction(new MyRasterShaderFunction())
>
> Hope that helps a little....
>
> -pete
>
> Martin Dobias wrote:
> > Hi Tim,
> >
> > thanks for the snippet. I've updated the examples accordingly, I've
> > also kept the older version for those interested.
> > http://blog.qgis.org/?q=node/59
> >
> > Beware - you need most recent SVN trunk since it now contains fixes to
> > bindings which got broken by the recent merges.
> >
> > Is there any source of information how does the raster
> > rendering/handling work now? I was unable to find anything and some of
> > the terms are quite new to me...
> >
> > Bye
> > Martin
> >
> > 2008/1/24 Tim Sutton <tim at linfiniti.com>:
> >
> >> Hi
> >>
> >> Yes the raster API is changed. I dont know the python stuff so well
> >> but in the case of C++ you would do something like this:
> >>
> >>
> 117 mpRasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
> >>
> 118 mpRasterLayer->setColorShadingAlgorithm(QgsRasterLayer::PSEUDO_COLOR);
> >> 119 mpRasterLayer->setContrastEnhancementAlgorithm(
> >> 120 QgsContrastEnhancement::STRETCH_TO_MINMAX, false);
> >>
> >> You will need to translate that to python api but it should be quite
> >> similar. Take a look at
> >>
> http://svn.qgis.org/trac/browser/trunk/qgis/src/core/raster/qgsrasterlayer.h
> >> for the different drawing styles and shading algorithms you can use.
> >>
> >> Regards
> >>
> >> Tim
> >>
> >> 2008/1/23, Martin Dobias <wonder.sk at gmail.com>:
> >>
> >>
> >>> 2008/1/23 volkan kepoglu <vkepoglu at gmail.com>:
> >>>
> >>>> downloaded QGIS tutorials in python, changed qgis_prefix and runned
> >>>> 2_basic_main_window and 3_basic_labelling successfully,
> >>>> but 4_adding_rasters_to_canvas gives the following error;
> >>>>
> >>>> vkepoglu at vkepoglu:~/qgis/tutorials/4_adding_rasters_to_canvas$ python
> >>>> mainwindow.py
> >>>> Traceback (most recent call last):
> >>>> File " mainwindow.py", line 76, in addLayer
> >>>> layer.setColorRampingType(QgsRasterLayer.BLUE_GREEN_RED)
> >>>> AttributeError: setColorRampingType
> >>>>
> >>> Ah, that will be caused by the recent refactoring of the raster
> classes.
> >>> Peter / Tim - can you suggest how to change the code to make it
> working again?
> >>>
> >>>
> >>>> how can ı fix?
> >>>> or the most important than to fix this,
> >>>> how can ı learn to qgis bindings to python.
> >>>>
> >>>> where should ı look for reference of python bindings
> >>>>
> >>>> http://wiki.qgis.org/qgiswiki/PythonBindings, is there any other
> references?
> >>>>
> >>> Today I've updated PythonBindings wiki page with some resources
> >>> (listed in top part in Using PyQGIS section). Basically it's good to
> >>> look at QGIS C++ API reference, QGIS blog, tutorials ported to Python
> >>> and QGIS plugins that have been done already. (all links listed there)
> >>>
> >>> Martin
> >>> _______________________________________________
> >>> Qgis-developer mailing list
> >>> Qgis-developer at lists.qgis.org
> >>> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
> >>>
> >>>
> >> --
> >> Tim Sutton
> >> QGIS Project Steering Committee Member - Release Manager
> >> Visit http://qgis.org for a great open source GIS
> >> openModeller Desktop Developer
> >> Visit http://openModeller.sf.net for a great open source ecological
> >> niche modelling tool
> >> Home Page: http://tim.linfiniti.com
> >> Skype: timlinux
> >> Irc: timlinux on #qgis at freenode.net
> >>
> >>
> > _______________________________________________
> > Qgis-developer mailing list
> > Qgis-developer at lists.qgis.org
> > http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
> >
> >
>
>
> --
> ====================================
> Peter J. Ersts, Project Specialist
> American Museum of Natural History
> Center for Biodiversity and Conservation
> Central Park West at 79th Street
> New York, New York 10024
> Tel: Home Office (518)-632-4745 or NYC Office (212)-496-3488
> Web: http://biodiversityinformatics.amnh.org
> Web: http://cbc.amnh.org
>
> Quantum GIS Raster Development Team. Visit http://www.qgis.org
> to learn more about QGIS, a free and open source desktop GIS
>
> Open Source,
> ...evolving through community cooperation to change the world bit by bit
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20080125/32500a02/attachment.html
More information about the Qgis-developer
mailing list