How do I calculate area of several vegetation types in a raster (.img file type) image. They are color coded. Am using QGIS (1.8.0) and ERDAS 9.2.
you can check out Qgis Sextante Toolbox in plugins repository. it has lots of geoprocessing alagorithm in it.
SEXTANTE is a spatial data analysis library and a powerful geoprocessing framework.The main aim of SEXTANTE is to provide a platform for the easy implementation, deployment and usage of rich geoprocessing functionality. It currently contains more than three hundred algorithms for both raster and vector data processing, as well as tabular data analysis tools.
and there is a good answer for classified vectorizing here from @nhopton. follow his direction to achieve what you want.
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; where "i" represents the raster band id.
poBand = poDataset->GetRasterBand( i );
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,
void * pData,
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
You can do this task with Erdas itself.
Convert the color coded image to vector by using raster to vector option under vector utilities tool. Convert the resulted Arcinfo vector file to shapefile using Import/Export option.
Open the vector file in QGIS. You can see the vector polygons corresponding to the vegetation class are coded as 1, 2, 3 in grid code field of attribute table. Calculate the area by using field calculator.