Skip to main content
2 of 2
deleted 22 characters in body
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

You can open the raster image as a GDALDataset :
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );

Then get the raster band containing the color codes with :
GDALRasterBand *poBand;
poBand = poDataset->GetRasterBand( i );
where "i" represents the raster band id.

Then iterate over the raster band pixels and read each pixel color code value to count the number of pixels for a selected color code.
Knowing the area represented by a single pixel you should be able to calculate the area for all the pixels representing the selected color code.

To read values from a raster band you should use :
CPLErr GDALRasterBand::RasterIO ( GDALRWFlag eRWFlag,
int nXOff,
int nYOff,
int nXSize,
int nYSize,
void * pData,
int nBufXSize,
int nBufYSize,
GDALDataType eBufType,
int nPixelSpace,
int nLineSpace
)

For a full documentation about the GDAL LIBRARY : http://gdal.org/index.html
GDAL class list : http://gdal.org/annotated.html
Get some help with the GDAL API : http://gdal.org/gdal_tutorial.html

QgisTn
  • 378
  • 1
  • 2
  • 12