Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Geospatial Development By Example with Python
  • Table Of Contents Toc
  • Feedback & Rating feedback
Geospatial Development By Example with Python

Geospatial Development By Example with Python

By : Pablo Carreira
5 (4)
close
close
Geospatial Development By Example with Python

Geospatial Development By Example with Python

5 (4)
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 (12 chapters)
close
close
11
Index

Creating utility functions to generate maps

Now we will create the first function that will compose our application.

  1. Still in the mapnik_experiments folder, create a new file: map_functions.py.
  2. Insert the code as follows into that file:
    # coding=utf-8
    
    import mapnik
    
    
    def create_map(style_file, output_image, size=(800, 600)):
        """Creates a map from a XML file and writes it to an image.
    
        :param style_file: Mapnik XML file.
        :param output_image: Name of the output image file.
        :param size: Size of the map in pixels.
        """
        map = mapnik.Map(*size)
        mapnik.load_map(map, style_file)
        map.zoom_all()
        mapnik.render_to_file(map, output_image)
    
    
    if __name__ == '__main__':
        create_map('map_style.xml', '../output/world3.png',
                   size=(400, 400))

What we did here is pack the map generation code into a function that we can reuse in the future. It takes two required arguments: the XML style file and the...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete