O'Reilly logo

Geospatial Development By Example with Python by Pablo Carreira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Showing statistics with colors

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:

  1. 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')

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required