Graphics Reference
In-Depth Information
block = provider.block(1, raster_extent, raster_width,
raster_height)
if block.isValid():
for x in range(raster_width):
for y in range(raster_height):
elevation = block.value(x, y)
if elevation != no_data_value:
try:
histogram[elevation] += 1
except KeyError:
histogram[elevation] = 1
for height in sorted(histogram.keys()):
print height, histogram[height]
Note that we've added a no data value check to the code. Raster data often includes pixels
that have no value associated with them. In the case of a DEM, elevation data is only
provided for areas of land; pixels over the sea have no elevation, and we have to exclude
them, or our histogram will be inaccurate.
Search WWH ::




Custom Search