[Qgis-developer] How to color a raster with a color table with values From - To?

Tim Sutton lists at linfiniti.com
Wed Aug 15 09:30:19 PDT 2012


Hi

On Mon, Aug 13, 2012 at 1:36 PM, SupportLists <supportlists at qlands.com> wrote:
> I tried that but QgsSingleBandPseudoColorRenderer is a class that does not
> seem to exists in 1.8.0
>

1.8 example is here:

https://github.com/qgis/Quantum-GIS/blob/release-1_8/tests/src/core/testqgsrasterlayer.cpp#L129

Regards

Tim

> Carlos.
>
>
> On 08/14/2012 12:25 AM, Etienne Tourigny wrote:
>>
>> Hi
>>
>> sorry if I have misled you, the code I was quoting is in 1.9 (dev
>> version). Have a look at the code in 1.9, it should probably work with
>> 1.8 but might require some changes.
>>
>>
>> https://github.com/qgis/Quantum-GIS/blob/master/tests/src/core/testqgsrasterlayer.cpp
>>
>> //items to imitate old pseudo color renderer
>>    QList<QgsColorRampShader::ColorRampItem> colorRampItems;
>>    QgsColorRampShader::ColorRampItem firstItem;
>>    firstItem.value = 0.0;
>>    firstItem.color = QColor( "#0000ff" );
>>    colorRampItems.append( firstItem );
>> [...]
>>    colorRampShader->setColorRampItemList( colorRampItems );
>>
>>
>> Etienne
>>
>> On Mon, Aug 13, 2012 at 8:12 AM, SupportLists <supportlists at qlands.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> I am using 1.8.0 but tests/src/core/testqgsrasterlayer.cpp is defined as:
>>>
>>> void TestQgsRasterLayer::pseudoColor()
>>> {
>>>    mpRasterLayer->setDrawingStyle( QgsRasterLayer::SingleBandPseudoColor
>>> );
>>>    mpRasterLayer->setColorShadingAlgorithm(
>>> QgsRasterLayer::PseudoColorShader
>>> );
>>>    mpRasterLayer->setContrastEnhancementAlgorithm(
>>>      QgsContrastEnhancement::StretchToMinimumMaximum, false );
>>>    mpRasterLayer->setMinimumValue( mpRasterLayer->grayBandName(), 0.0,
>>> false
>>> );
>>>    mpRasterLayer->setMaximumValue( mpRasterLayer->grayBandName(), 10.0 );
>>>    mpMapRenderer->setExtent( mpRasterLayer->extent() );
>>>    QVERIFY( render( "raster_pseudo" ) );
>>> }
>>>
>>> I cannot locate the code using ColorRampItem.
>>>
>>> Many thanks,
>>> Carlos.
>>>
>>>
>>> On 08/08/2012 08:07 PM, Etienne Tourigny wrote:
>>>>
>>>> Hi,
>>>>
>>>> which version of the api are you using? If you are using the
>>>> development version (1.9), there is support for more flexible color
>>>> ramps with rasters, using QgsVectorColorRampV2. Beware, however, that
>>>> the api is going to suffer some changes in the near future. There are
>>>> various recent threads on this subject in this mailing list.
>>>>
>>>> Another option (and the only available if using 1.8) is to follow the
>>>> approach used in the rasterlayer test in
>>>> tests/src/core/testqgsrasterlayer.cpp .
>>>> TestQgsRasterLayer::pseudoColor() uses a ColorRampItem vector and
>>>> calls colorRampShader->setColorRampItemList(items)
>>>>
>>>> Etienne
>>>>
>>>> On Wed, Aug 8, 2012 at 3:42 AM, SupportLists <supportlists at qlands.com>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am using QGIS API to develop a custom application. Currently I'm
>>>>> using
>>>>> QgsRasterLayer::PalettedColor + QgsRasterLayer::ColorRampShader  +
>>>>> QgsColorRampShader::ColorRampItem to render a raster using a specific
>>>>> color
>>>>> map.
>>>>>
>>>>> Now, I need to render the raster with a colormap using value From - To
>>>>> however, ColorRampItem struct only accepts one value. Is there another
>>>>> way
>>>>> around? Or, its it possible to create user defined DrawingStyles and
>>>>> ColorShadingAlgorithms? If so how?
>>>>>
>>>>> Any help is very much appreciated.
>>>>>
>>>>> Regards,
>>>>> Carlos.
>>>>> _______________________________________________
>>>>> Qgis-developer mailing list
>>>>> Qgis-developer at lists.osgeo.org
>>>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>>
>>>
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer



-- 
Tim Sutton - QGIS Project Steering Committee Member (Release  Manager)
==============================================
Please do not email me off-list with technical
support questions. Using the lists will gain
more exposure for your issues and the knowledge
surrounding your issue will be shared with all.

Visit http://linfiniti.com to find out about:
 * QGIS programming and support services
 * Mapserver and PostGIS based hosting plans
 * FOSS Consulting Services
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
==============================================


More information about the Qgis-developer mailing list