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

Setting your current location


So far, the application can open a file. The next step is to define your location so that we can find the closest geocache. To do this, we will change the GeocachingApp class so that it can keep track of the current location through a property. We will also create methods to change the location (similar to the geometries), transform its coordinates, and prepare it for processing.

Here are the steps that need to be performed:

  1. Edit the GeocachingApp class init method using the following code:

    #..
        def __init__(self, data_file=None, my_location=None):
            """Application class.
    
            :param data_file: An OGR compatible file
             with geocaching points.
            """
            self._datasource = None
            self._transformed_geoms = None
            self._my_location = None
            self.distances = None
    
            if data_file:
                self.open_file(data_file)
    
            if my_location:
                self.my_location = my_location
  2. Now, add these two methods to...