I'm trying to white a Python plugin in QGIS (2.2) to get, for each pixel of a raster image, its X Y coordinates, as well as, its RGB (3 bands) values.
At first I opened the raster file using: rlayer = QgsRasterLayer(rfileName, rbaseName)
Now I don't know how to get, for example, for pixel (1,1) its coordinates (X,Y) and its RGB color values.
Anybody could help me?
I know that I'll need to implement a DO WHILE, but I don't know the commands to extract this information of each pixel.
Thanks in advance,
Mateus
Best Answer
As a geologist, I make geological cross section using the elevations values from a DEM and the colors from a geological map, look at the pure Python solution with osgeo.gdal in Python Script for getting elevation difference between two points
But now, since PyQGIS 2.x, it is easier with PyQGIS and the
QgsRaster.IdentifyFormatValue
functionexample with a DEM (one band):
example with a classic raster (three bands -> R,G,B values):
The result is a dictionary (key= band number) and you can create a simple function that returns the values:
I presented a complete solution with PyQGIS in French PyQGIS (QGIS 2): geological cross-sections (colorization of a topographic profile build from a DEM with the colors of a raster and placement of the intersection points of the geological layers boundaries )