Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

3 Answers

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

I hope this helps!

share|improve this answer
add comment

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.

i hope it helps you...

share|improve this answer
add comment

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.

Hope this will help you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.