2

I'm trying to get the area of a raster (without NULL cells) using gdalinfo, I read the gdal documentation but found no parameter that would give me the area; I can calculate it from the histogram obtained, by subtracting the values in the first histogram bin (which where the NULL in this case) from the width*height values (size) and multiplying by the resolution, but hist function takes some time and maybe NULL cell will have another value in other raster files. This is the function.

gdalinfo -json -hist raster.tif | jq ((.size[0]*.size[1]-.bands[0].histogram.buckets[0])*.geoTransform[1]*.geoTransform[1])/10000'

2

It don't think you'll get this out of gdalinfo, although it would be possible if you included null cells in your calculation.

Instead, I would reclassify all non-null cells to have a value of 1, and all null cells to have a value of 0, then do a sum across the entire raster, and then multiply that value by the area of one pixel.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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