[Gdal-dev] Problems reading grass raster color entry
Frank Warmerdam
warmerdam at pobox.com
Wed Jan 7 11:09:48 EST 2004
Tim Sutton wrote:
> Hi
> >
> I am having problems reading a grass raster layer using gdal. The same routine
> I am having problems with (see snippet below) works fine on a geotiff image.
> I have tested the same file with gdalinfo and it seems to read the palette
> fine. Can anyone see an obvious reason why my code is not working?
>
> Many thanks
>
> Tim
>
>
>
> QString colorInterp =
> GDALGetColorInterpretationName(gdalBand->GetColorInterpretation());
> //std::cout << "Colour Interpretation for this band is : " << colorInterp
> << std::endl;
> if ( colorInterp == "Palette")
> {
> // print each point in scandata using color looked up in color table
> GDALColorTable *colorTable = gdalBand->GetColorTable();
> QImage myQImage=QImage(myLayerXDimInt,myLayerYDimInt,32);
> myQImage.setAlphaBuffer(true);
> for (int y = 0; y < myLayerYDimInt; y++)
> {
> for (int x =0; x < myLayerXDimInt; x++)
> {
> const GDALColorEntry *colorEntry = GDALGetColorEntry(colorTable,
> scandata[y*myLayerXDimInt + x]);
> //dont draw this point if it is no data !
> if (myNoDataDouble != scandata[y*myLayerXDimInt + x])
> {
> int myRedValueInt=0; //color 1 int
> int myGreenValueInt=0; //color 2 int
> int myBlueValueInt=0; //color 3 int
> //check for alternate color mappings
> if (redBandNameQString=="Red") myRedValueInt=colorEntry->c1;
>
> Last line fails on this : myRedValueInt=colorEntry->c1;
Tim,
I gather you are getting a crash with colorEntry being NULL? There is
no guarantee to be a color entry for every pixel value in a raster.
You need to check if GDALGetColorEntry() returns NULL.
However, I don't see any particular reason your approach shouldn't work
if all the required palette entries are available.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | Geospatial Programmer for Rent
More information about the Gdal-dev
mailing list