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

Memory and images


First, we will check how opening images affects random access memory (RAM) usage. In our first example, we will try to open band 8 of the Landsat data using the same technique as before:

  1. Prepare the working environment for Chapter 9 by making a copy of the Chapter8 folder in your geopy project. Name the copied folder as Chapter9.

  2. In Chapter9 folder, open the experiments folder and delete all the files inside it.

  3. In the experiments folder, create a new Python file and name it images.py. Open it for editing.

  4. Now type the following code in this file:

    # coding=utf-8
    
    import cv2 as cv
    
    def open_image(img_path):
        image = cv.imread(img_path)
        print(type(image))
        raw_input("Press any key.")
    
    
    if __name__ == '__main__':
        image_path = "../../data/landsat/LC80140282015270LGN00_B8.TIF"
        open_image(image_path)
  5. Run the code. Press Alt + Shift + F10 and select the images on the list.

  6. Depending on your computer's memory and the OpenCV version, you may succeed. Otherwise, you will...