ArcPy and ArcGIS – Geospatial Analysis with Python Use the ArcPy module to automate the analysis and mapping of geospatial data in ArcGIS Silas Toms BIRMINGHAM - MUMBAI ArcPy and ArcGIS – Geospatial Analysis with Python 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: February 2015 Production reference: 1210215 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-78398-866-2 www.packtpub.com [ FM-2 ] Credits Author Copy Editors Silas Toms Aarti Saldanha Adithi Shetty Reviewers Alessio Di Lorenzo Project Coordinator Dara O'Beirne Milton Dsouza Mark Pazolli Marjorie Roswell Proofreaders Simran Bhogal Joanna McMahon Commissioning Editor Ashwin Nair Bernadette Watkins Acquisition Editor Indexer Harsha Bharwani Priya Sane Content Development Editor Production Coordinator Akashdeep Kundu Alwin Roy Technical Editor Cover Work Deepti Tuscano Alwin Roy [ FM-3 ] About the Author Silas Toms is a geospatial programmer and analyst with a love of geography, history, food, and sports. He resides in the San Francisco Bay Area and can't decide which side of the Bay is more beautiful. He received a bachelor's degree in Geography from Humboldt State University and is currently pursuing a master's degree in GIS at San Francisco State University. With a background in GIS analysis for city governments and environmental consulting, Silas loves the combination of GIS and Python for analysis automation and data manipulation. Working for Arini Geographics, Silas is helping governments understand how GIS can organize and simplify the management of infrastructure and the environment. This dual role as a programmer and analyst allows him to use Python and GIS to quickly produce geospatial data and tools. Combined with web mapping, these tools are transforming how governments work to serve the public. He also teaches workshops on ArcPy and web mapping at the City College of San Francisco, while hoping to one day finish his master's thesis. Silas has worked as a reviewer on the book Python Geospatial Analysis, Packt Publishing and is working on the book Python Geospatial Development, Packt Publishing to be published in 2015. I would like to thank my girlfriend, Christine, for her encouragement and patience. I would like to thank my boss, Gabriel Paun, for his inspiration and for pushing me to become a true GIS professional. I would like to thank the faculty at HSU and SFSU for their help along the way, and I would like to thank my family for their belief in me and for never asking me if I was going to become a teacher with my geography degree (even though I have and I love it!). [ FM-4 ] About the Reviewers Alessio Di Lorenzo is a marine biologist and has an MSc in Geographical Information Systems (GIS) and Remote Sensing. Since 2006, he has been dealing with the analysis and development of GIS applications dedicated to the study and spread of environmental and epidemiological data. He is experienced in the use of the main proprietary and open source GIS software and programming languages. Dara O'Beirne is a certified GIS Professional (GISP) with over eight years of GIS and Python experience. Dara earned both his Bachelors and Masters of Arts degrees in geography from San Francisco State University. Dara is currently a GIS Analyst working at Arini Geographics in Santa Clara, CA. Before joining Arini Geographics, Dara was a GIS Analyst and technical lead at Towill Inc., a GIS and Land Surveying company in Northern California. At Towill, Dara played a central role in developing and implementing procedures related to the collection and analysis of LiDAR data for environmental and engineering applications. Prior to Towill, Dara gained his professional GIS experience working for the Golden Gate National Recreation Area managed by the National Park Service, one of the largest urban park systems in the world, which includes National treasures, such as Alcatraz, Muir Woods, and the Marin Headlands. His Master's Thesis examined the errors associated with measuring tree heights in an urban environment with both traditional field methods and airborne LiDAR data. I would like to thank my wife, Kate, and daughter, Anya O'Beirne, for their patience and assistance during the review of this book. [ FM-5 ] Marjorie Roswell is a web developer and map maker from Baltimore, MD. She purchased her first GIS in 1991, and built an application to assist citizen callers to the Baltimore Office of Recycling. Recent projects include interactive maps of legislative scores, political endorsements, committees, election data, and advocacy interests. Her site http://committeemaps.org/ details Congressional committee membership, while the site http://farmbillprimer.org/ is devoted to mapping and charting federal food and farm policy. Marjorie is the author of Drupal 5 Views Recipes, Packt Publishing. She was the technical reviewer of jQuery UI 1.10, The User Interface Library for jQuery, Packt Publishing. Mark Pazolli is an engineer and data scientist who uses ArcGIS and Python to help his employers decipher the mountains of data they keep on the assets of the Western Australian electrical network. He has qualifications in Electrical Engineering, Computer Science, and Applied Mathematics. He appreciates excellent design and enjoys building interesting things. [ 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 1 Chapter 1: Introduction to Python for ArcGIS 7 Overview of Python 7 Python as a programming language 8 Interpreted language 8 Standard (built-in) library 9 The glue language 9 Wrapper modules 9 The basics of Python 10 Import statements 11 Variables 12 For loops 13 If/Elif/Else statements 14 While statements 14 Comments 15 Data types 15 Strings 16 Integers 16 Floats 17 Lists 17 Tuples 18 Dictionaries 18 Iterable data types 19 Other important concepts 20 Indentation 20 Functions 21 Keywords 21 Namespaces 21 Zero-based indexing 22
Description: