Book Image

Geospatial Development By Example with Python

By : Pablo Carreira
5 (1)
Book Image

Geospatial Development By Example with Python

5 (1)
By: Pablo Carreira

Overview of this book

From Python programming good practices to the advanced use of analysis packages, this book teaches you how to write applications that will perform complex geoprocessing tasks that can be replicated and reused. Much more than simple scripts, you will write functions to import data, create Python classes that represent your features, and learn how to combine and filter them. With pluggable mechanisms, you will learn how to visualize data and the results of analysis in beautiful maps that can be batch-generated and embedded into documents or web pages. Finally, you will learn how to consume and process an enormous amount of data very efficiently by using advanced tools and modern computers’ parallel processing capabilities.
Table of Contents (17 chapters)
Geospatial Development By Example with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Styling maps


Now that we have a function to generate the map and an easy way to preview them, we will experiment with the style options:

  1. First, lets produce a bigger map so we can better see the changes. Edit the if __name__ == '__main__': block at the end of the map_functions.py file, changing the size argument of the create_map function call:

    if __name__ == '__main__':
        map_image = '../output/world3.png'
        create_map('../../data/world_borders_simple.shp',
                   'map_style.xml',map_image, size=(1024, 500))
        display_map(map_image)

Map style

The map is the canvas for the drawing; it is possible to change the background color or the background image, the coordinate reference system, and a few other options.

Let's try changing the background:

  1. In the file map_style.xml edit the map tag to change the background color. You can use a hexadecimal value, a color name, or an RGB combination. Try this as an example:

    <Map background-color="#f8be78">
  2. Run the code and see the changes.

  3. Now...