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

Opening the file and getting its contents


Now, we will open the downloaded file and prepare it for processing. This is something that we already did in Chapter 1, Preparing the Work Environment, so we will copy our function and improve it so that we can reuse it in this application and the ones to come. Here are the steps that we will perform:

  1. Create a new file named geo_functions.py inside the utils directory.

  2. Open the world_areas.py file from Chapter 1, Preparing the Work Environment, and copy the open_shapefile function. Then, paste it into the created file.

  3. Now, change the name of the function to open_vector_file so that it makes more sense as we will use this function to open many kinds of file. The geocaching file isn't a shapefile—it's a GPX, and to open it, we don't need to change anything. OGR will handle this for us.

  4. Now, to keep the code well documented, change the docstring to reflect the function's capabilities. Change it to something similar to "Opens a vector file compatible with...