I would like to know how to calculate area of raster image based on cell? based on night light data I classified the image and i need to know the area of that particular classified area
Asked
Active
Viewed 4,338 times
3 Answers
2
Your raster dataset has a resolution in ground units, meaning the width and height of each of your cells: if your raster has 100m resolution, each one of your cells is 100m x 100m
That means 1 cell is 10,000 square metres
If you extract your target cells (night light data) and count the number of cells x the resolution of a single cell you will get the area.
DPSSpatial_BoycottingGISSE
- 18,790
- 4
- 66
- 110
2
Here is a short Python code using GDAL to calculate area. Save it to a file e.g. raster_area.py. Replace 'your_raster' and 'your_value' with your data.
from osgeo import gdal
# open dtm image
data = gdal.Open("your_raster", gdal.GA_ReadOnly)
# get pixel area from georeference of raster
geotr = data.GetGeoTransform()
pixel_area = abs(geotr[1] * geotr[5])
# get the only band, I supposed you have one band
band = data.GetRasterBand(1)
area = 0.0 # variable for area sum
for y in range(band.YSize):
scanline = band.ReadRaster(0, y, band.XSize, 1, band.XSize,
1, band.DataType)
values = struct.unpack(fmt, scanline)
area += sum([value for value in values if value = your_value])
print area
Zoltan
- 7,325
- 17
- 27
-1
It is merely cells * (xres * yres).
or in your case
Cells with desired value * (xres * yres)
If you do not know- just GIS
- 7,416
- 28
- 71