[Qgis-developer] color ramp shader in python
Volkan Kepoglu
vkepoglu at gmail.com
Thu Jan 22 07:48:49 EST 2009
i do not get what you mean, but you maybe try what i am using below
python sample code in qgis 1.0 preview 2 for win.
fileInfo = QtCore.QFileInfo("c:/temp/r_b.tif")
# add a (hardcoded) layer and zoom to its extent
rstlayer = QgsRasterLayer(fileInfo.filePath(), fileInfo.completeBaseName())
if not rstlayer.isValid():
raise NoValidRaster, "raster layer is not valid."
return
rstlayer.setDrawingStyle(QgsRasterLayer.SingleBandPseudoColor)
rstlayer.setColorShadingAlgorithm(QgsRasterLayer.PseudoColorShader)
rstlayer.setContrastEnhancementAlgorithm(QgsContrastEnhancement.StretchToMinimumMaximum,
False)
# add layer to the registry
QgsMapLayerRegistry.instance().addMapLayer(rstlayer);
mapCanvas=self.iface.mapCanvas()
mapCanvas.setCurrentLayer(rstlayer)
# set extent to the extent of our layer
mapCanvas.setExtent(rstlayer.extent())
mapCanvas.zoomToSelected()
mapCanvas.refresh()
On 1/20/09, Barry Rowlingson <b.rowlingson at lancaster.ac.uk> wrote:
> Hi all,
>
> I want to setup a custom colormap shading of a raster in Python.
> Previously I did:
>
> self.setValueClassification(schemeVCL)
> self.setCustomClassificationEnabled(True)
> self.setDrawingStyle(self.SINGLE_BAND_PSEUDO_COLOR)
>
> Where schemeVCL was a list of QgsRasterLayer.ValueClassificationItem
> objects.
>
> Now it's all changed, but I can't see how to set the color map of a
> shader in Python. QgsColorRampShader doesn't seem to be wrapped, and
> there's no colorTable() method on raster layers either.
>
> The only way I can see to do it is to write a QgsRasterShader in
> python, but that would be duplicating what a QgsColorRampShader does
> anyway, and it would probably be much slower because it'll be calling
> back to python for every colour look-up.
>
> Or am I doing it wrong?
>
> Barry
> _______________________________________________
> 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