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

Creating color classified images


If we want to display image information on a map, we must prepare a visual output of what we got. A common and efficient form of visual representation is to separate values into classes and give each class a different color. In our case, we can split the data into altitude classes. NumPy makes it easy for us. Let's write a method that can be called in the pipeline to get started:

  1. Add a new method to the RasterData class:

    #...
        def colorize(self, style):
            """Produces an BGR image based on a style containing
             limits and colors.
    
            :param style: A list of limits and colors.
            """
            shape = self.data.shape
            limits = []
            colors = []
            # Separate the limits and colors.
            for item in style:
                limits.append(item[0])
                colors.append(self._convert_color(item[1]))
            colors = np.array(colors)
            # Put each color in its limits.
            flat_array = self.data.flatten()
            di_array...