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

Filtering by multiple attributes


The next step is to search the geocaching points by their attributes. For example, we may want to filter the points by the author of the geocache, by the level of difficulty to find the geocache, and so on.

We will borrow the techniques used in the methods that allowed us to get a GeoObject by its name property and the method that filtered by a polygon. The difference here is that we must allow the attribute that we want to filter by to be passed as a parameter, and we want to have the capability to combine multiple fields.

  1. Let's start adding a simple filter method in the BaseGeoCollection class:

    #...
        def filter(self, attribute, value):
            """Filters the collection by an attribute.
    
            :param attribute: The name of the attribute to filter by.
            :param value: The filtering value.
            """
            result = []
            for item in self.data:
                if item.get_attribute(attribute) == value:
                    result.append(item)
           ...