How the map is colorized is only a matter of defining the limits and colors in the style. So, if we want to translate statistical information into colors, we just need to associate the values that we want with a sequence of colors.
First, let's try it with the quartiles:
Since everything is prepared in our class, we just need to change the code in the
if __name__ == '__main__':
block:if __name__ == '__main__': dem = RasterData('output/dem.tif') shaded = RasterData('output/shaded.png') limits = [dem.stats['Q1'], dem.stats['Q3'], dem.stats['Maximum']] colors = ["#fc8d59", "#ffffbf", "#91cf60"] dem.colorize(limits, colors).write_image('output/stats.png') dem.alpha_blend(shaded).write_image('output/shaded_stats.png')
The following image illustrates the colored output for the analyzed parameters:
For this image you can start the lead-in this way: