Geoprocessing with Python
Chris Garrard
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 761 Shelter Island, NY 11964 Email:
orders@manning.com2016 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 761Shelter Island, NY 11964 |
Development editor: Jennifer StoutTechnical development editor: Karsten StrbkCopyeditor: Katie PetitoProofreader: Katie TennantTechnical proofreader: Rizwan BilbulTypesetter: Marija TudorCover designer: Marija Tudor
ISBN: 9781617292149
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 EBM 21 20 19 18 17 16
Brief Table of Contents
Table of Contents
Preface
Although Id taken a lot of programming classes in college, I never fully appreciated programming until I had a job that involved a lot of repetitive tasks. After amusing myself by automating much of that job, I decided to return to school and study biology, which is when I took my first GIS course. I was instantly in love, and managed to convince someone to give me a biology degree for writing an extension for ArcView GIS (a precursor to ArcGIS, for you Esri fans out there). After finishing that up, I went to work for the Remote Sensing/Geographic Information Systems Laboratory at Utah State University. One of my first projects involved some web mapping, and I soon became a big fan of the open source UMN MapServer software. That was my introduction to open source geospatial software, including GDAL.
Im fairly certain that I didnt appreciate the power of the GDAL/OGR library when I first learned about it, but I came to my senses once I started using it in my C++ and C# code. In the College of Natural Resources, there werent many people around who were interested in coding, but I did get to point people to the GDAL command-line utilities on a regular basis. But then Esri introduced Python as the scripting language of choice for ArcGIS, and things started to change. I dont think I had used Python much before then, but playing with arcgisscripting (the original Esri Python module) made me realize how much I enjoyed working with Python, so naturally I had to start using GDAL with it as well.
More importantly for this book, my coworker John Lowry suggested that we team-teach a Python-for-GIS class. He taught students how to use Python with ArcGIS, and I taught them about GDAL. The class turned out to be popular, so we taught it that way for another few years until John moved away. I took over the entire class and have been teaching it in various configurations ever since. Ive never bothered to take the class material from the first two years off the web, however, which is how Manning found me. They asked if I would write a book on using GDAL with Python. Id never had the desire to write a book, so it took a bit of persuasion to convince me to do it. In the end, it was my love for teaching that won me over. Ive discovered over the years that I really enjoy teaching, mostly because I love watching students incorporate what theyre learning into the rest of their work. This is especially true of graduate students, some of whom might not have completed their research in a timely manner (or at all) if they hadnt learned how to write code. I know that these skills will continue to assist them throughout their careers, and my hope is that this book will provide the same help to you, no matter if youre a student, professional, or a hobbyist. This is fun stuff, and I hope you enjoy it as much as I do!
Acknowledgments
I knew that writing a book would be difficult, but it was even harder than I anticipated, and it ended up taking quite a bit longer than I thought it would. My coworkers, friends, and family were very supportive throughout the process, and definitely deserve my thanks. Chris McGinty and Tommy Thompson provided feedback on some of the text. My neighbors Marybeth and McKay Wilson knew I was busy and seemed to take joy in mowing my lawn or clearing snow from my driveway before I could get to it, and they also dropped treats by occasionally. My friend Gayle Edlin published her own book while I was working on this one, which proved to me that it really could be done!
My Manning editor, Jennifer Stout, was my biggest cheerleader, always encouraging me when I got bogged down. Thanks for being so patient with me!
There were many reviewers who provided invaluable feedback throughout the process: Alban Thomas, Alfredo Alessandrini, Chris Gaschler, Fredric Ragnar, Gonzalo Vazquez, Jackie Wilson, Ji Fejfar, Marcus Geselle, Nate Ron-Ferguson, Ramesha Murthy, Ryan Stelly, Scott Chausse, Shaun Langley, and Thorsten Szutzkus. Rizwan Bilbul gave the complete manuscript a technical proofread.
The book never wouldve been finished without the help of the rest of the team at Manning, including Katie Tennant, Katie Petito, Kevin Sullivan, Chuck Larson, and Marija Tudor.
And last but not least, Id like to acknowledge my students over the years, because without them this never wouldve happened. Nobody wouldve asked me to write a book if I hadnt left old class materials stranded on the web, nor would I have realized how much I enjoyed helping people learn.
About this Book
I wrote Geoprocessing for Python to help you learn the basics of working with geospatial data, mostly using GDAL/OGR. There are other options, of course, but some of them build on top of GDAL, so if you understand the material in this book, youll probably be able to pick them up without too much trouble. This is not a book on GIS or remote sensing, although some background theory will be explained. Instead, this book will teach you how to write Python code for manipulating and creating spatial data, along with some simple analyses. You can use these building blocks to implement more-complicated analyses of your own devising.
Who should read this book
This book is for anyone who wants to learn to work with geospatial data. Some basics of GIS and remote sensing are explained so that readers new to geospatial analysis will know why theyre learning certain things, but the code starts out simple enough so that people with a geospatial backgroundbut not much coding experiencewill also benefit.
How this book is organized
This book is organized into 13 chapters. It starts out with a general introduction to geospatial data and Python and then covers vector data, spatial reference systems, raster data, and visualization.