Learning Geospatial Analysis with Python Second Edition An effective guide to geographic information system and remote sensing analysis using Python 3 Joel Lawhead BIRMINGHAM - MUMBAI Learning Geospatial Analysis with Python Second Edition Copyright © 2015 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: October 2013 Second edition: December 2015 Production reference: 1211215 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78355-242-9 www.packtpub.com [ FM-2 ] Credits Author Project Coordinator Joel Lawhead Izzat Contractor Reviewers Proofreader Mark Cederholm Safis Editing Truc Viet Le John Maurer Indexer Mariammal Chettiyar Julia Wood Graphics Commissioning Editor Jason Monteiro Kartikey Pandey Production Coordinator Acquisition Editors Arvindkumar Gupta Kevin Colaco Usha Iyer Cover Work Kartikey Pandey Arvindkumar Gupta Content Development Editor Anish Sukumaran Technical Editor Manthan Raja Copy Editor Tasneem Fatehi [ FM-3 ] About the Author Joel Lawhead is a project management institute-certified Project Management Professional (PMP), certified GIS Professional (GISP), and the Chief Information Officer (CIO) of NVision Solutions Inc., an award-winning firm that specializes in geospatial technology integration and sensor engineering. Joel began using Python in 1997 and started combining it with geospatial software development in 2000. He is the author of the first edition of Learning Geospatial Analysis with Python and QGIS Python Programming Cookbook, both by Packt Publishing. His Python cookbook recipes were featured in two editions of Python Cookbook, O'Reilly Media. He is also the developer of the widely-used, open source Python Shapefile Library (PyShp). He maintains the geospatial technical blog http://geospatialpython.com/ and the Twitter feed, @SpatialPython, which discusses the use of the Python programming language in the geospatial industry. In 2011, Joel reverse-engineered and published the undocumented shapefile spatial indexing format and assisted fellow geospatial Python developer, Marc Pfister, in reversing the algorithm used, allowing developers around the world to create better-integrated and more robust geospatial applications. Joel serves as the lead architect, project manager, and co-developer for geospatial applications used by U.S. government agencies, including NASA, FEMA, NOAA, the U.S. Navy, and many other commercial and non-profit organizations. In 2002, he received the international Esri Special Achievement in GIS award for his work on the Real-Time Emergency Action Coordination Tool (REACT), for emergency management using geospatial analysis. [ FM-4 ] About the Reviewers Mark Cederholm, GISP, has over 20 years of experience in developing GIS applications using various Esri technologies, from ARC/INFO AML to ArcObjects to ArcGIS Runtime and Web SDKs. He lives in Flagstaff, Arizona. He has been a technical reviewer for the book, Developing Mobile Web ArcGIS Applications, Packt Publishing. Truc Viet Le is currently a PhD candidate in information systems at the Singapore Management University. His research interests primarily involve novel methods for the modeling and predicting of human mobility patterns and trajectories, learning smart strategies for urban transportation, and traffic flow prediction from fine-grained GPS and sensor network data. He uses R and Python every day for his work, where he finds R superb for data manipulation/visualization and Python an ideal environment for machine learning tasks. He is also interested in applying data science for the social work and international development work. When not behind the computer screen, he is an avid traveler, adventurer, and an aspiring travel writer and photographer. His work portfolio and some of his writings can be found on his personal website at http://vietletruc.com/. He spent a wonderful year at Carnegie Mellon University in Pittsburgh, Pennsylvania, while pursuing his PhD. Previously, he obtained his bachelor's and master's degrees from Nanyang Technological University in computer engineering and mathematical sciences. [ FM-5 ] John Maurer is a programmer and data manager at the Pacific Islands Ocean Observing System (PacIOOS) in Honolulu, Hawaii. He creates and configures web interfaces and data services to provide access, visualization, and mapping of oceanographic data from a variety of sources, including satellite remote sensing, forecast models, GIS layers, and in situ observations (buoys, sensors, shark tracking, and so on) throughout the insular Pacific. He obtained a graduate certificate in remote sensing as well as a master's degree in geography from the University of Colorado, Boulder, where he developed software to analyze ground-penetrating radar (GPR) for snow accumulation measurements on the Greenland ice sheet. While in Boulder, he worked with the National Snow and Ice Data Center (NSIDC) for eight years, sparking his initial interest in Earth science and all things geospatial: an unexpected but comfortable detour from his undergraduate degree in music, science, and technology at Stanford University. Julia Wood is currently a Geospatial Information Sciences (GIS) analyst who spends her professional time completing projects as a contractor in the Washington D.C. area. She graduated magna cum laude from the University of Mary Washington in Fredericksburg, Virginia, in the spring of 2014 with a bachelor's degree in both history and geography as well as a minor in GIS. Though her career is still in its early stages, Julia has aspirations to keep growing her skill set, and working on this review has certainly helped expand her professional experience; she hopes to continue learning and eventually work toward a master's degree while still working full time. In her non-work life, she enjoys reading, crafting, cooking, and exploring the big city, one local restaurant at a time. Reviewing this book for Packt Publishing was Julia's first professional reviewing experience and she hopes that she can pursue similar endeavors in the future. I'd like to thank my parents, John and Diana, for always encouraging me to do well in my educational and professional endeavors; my sister, Sarrina, and my brother, Jonathan, for offering support and advice when I needed it; and my boyfriend, Max, and my cat, Coco, for keeping me company while I conducted the reviews for this book. A thank you to Packt for letting me be a part of this experience! [ FM-6 ] www.PacktPub.com Support files, eBooks, discount offers, and more For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. TM https://www2.packtpub.com/books/subscription/packtlib Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books. Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access. [ FM-7 ] Table of Contents Preface ix Chapter 1: Learning Geospatial Analysis with Python 1 Geospatial analysis and our world 1 Beyond disasters 4 History of geospatial analysis 4 Geographic information systems 9 Remote sensing 11 Elevation data 17 Computer-aided drafting 18 Geospatial analysis and computer programming 18 Object-oriented programming for geospatial analysis 19 Importance of geospatial analysis 21 Geographic information system concepts 21 Thematic maps 22 Spatial databases 23 Spatial indexing 24 Metadata 24 Map projections 24 Rendering 26 Remote sensing concepts 27 Images as data 27 Remote sensing and color 28 Common vector GIS concepts 28 Data structures 28 Buffer 30 Dissolve 30 Generalize 31 Intersection 32 [ i ]