Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Book Image

ArcPy and ArcGIS: Geospatial Analysis with Python

Overview of this book

Table of Contents (19 chapters)
ArcPy and ArcGIS – Geospatial Analysis with Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

ArcGIS, the GIS software from industry leader ESRI, allows for the analysis and presentation of geospatial data.

The integration of Python into ArcGIS has made the ArcPy module an important tool for GIS students and professionals. The ArcPy module provides a powerful way to improve productivity when performing geospatial analysis. From basic Python scripting through advanced ArcPy methods and properties, ArcPy and other Python modules will improve the speed and repeatability of any GIS work flow.

This book will guide you from basic Python scripting to advanced scripting tools. It focuses on geospatial analysis scripting and touches on automating cartographic output. By the end of this book, you will be able to create reusable modules, add repeatable analyses as script tools in ArcToolbox, and export maps automatically. By reducing the time-consuming nature of GIS from days to hours, one GIS professional can become as powerful as a whole team.

What this book covers

Chapter 1, Introduction to Python for ArcGIS, offers a quick introduction to the basics of Python, including other uses for the programming language. It covers Python data types and important modules used throughout the book.

Chapter 2, Configuring the Python Environment, is an introduction to how Python works: its folder structure, executables, and modules. It also explains importing modules into scripts, the built-in modules, and covers Integrated Development Environments (IDEs), which are powerful programming aids.

Chapter 3, Creating the First Python Script, demonstrates how to use ArcGIS ModelBuilder to model the first analysis and then export it as a Python script. String manipulations and how to use file paths in Python are also introduced.

Chapter 4, Complex ArcPy Scripts and Generalizing Functions, examines how to perform analyses and produce outputs that are not possible using ModelBuilder. By using functions, or reusable code blocks, repeating code is avoided.

Chapter 5, ArcPy Cursors – Search, Insert, and Update, covers ArcPy data access cursors and how they are used to search, update, or insert records in feature classes and tables. It explains the quirks of iterating using cursors, and how to only select or update the records of interest.

Chapter 6, Working with ArcPy Geometry Objects, explores ArcPy Geometry objects and how they are combined with cursors to perform spatial analysis. It demonstrates how to buffer, clip, reproject, and more using the data cursors and the Arcpy geometry types without using ArcToolbox.

Chapter 7, Creating a Script Tool, explains how to make scripts into tools that appear in ArcToolbox and are dynamic in nature. It explains how the tools and scripts communicate and how to set up the ArcTool dialog to correctly pass parameters to the script.

Chapter 8, Introduction to ArcPy.Mapping, explores the powerful Arcpy.Mapping module and how to fix broken layer links, turn layers on and off, and dynamically adjust titles and text. It shows how to create dynamic map output based on a geospatial analysis.

Chapter 9, More ArcPy.Mapping Techniques, introduces Layer objects, and their methods and properties. It demonstrates how to control map scales and extents for data frames, and covers automated map export.

Chapter 10, Advanced Geometry Object Methods, expands on the ArcPy Geometry object methods and properties. It also explains how to create a module to save code for reuse in subsequent scripts, and demonstrates how to create Excel spreadsheets containing results from a geospatial analysis.

Chapter 11, Network Analyst and Spatial Analyst with ArcPy, introduces the basics of using ArcPy for advanced geospatial analysis using the ArcGIS for Desktop Network Analyst and Spatial Analyst Extensions.

Chapter 12, The End of the Beginning, covers other important topics that need to be understood to have a full grasp of ArcPy. These topics include the Environment Settings, XY values and Z and M resolutions, Spatial Reference Systems (Projections), the Describe functions, and more.

What you need for this book

You will need the proprietary or free version of ArcGIS 10.1/10.2/10.3. To support your environment, you will need 2GB RAM, 32-bit or 64 bit machine hardware configuration, and Windows 7/8. Python 2.7 is required to do the programming and is installed along with ArcGIS.

Who this book is for

This book is intended for GIS students and professionals who need an understanding of how to use ArcPy to reduce repetitive tasks and perform analysis faster. It is also a valuable book for Python programmers who would like to understand how to automate geospatial analysis using the industry standard ArcGIS software and its ArcPy module.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The two data pieces, the BusStopID and the averatePop variable are then added to a list."

A block of code is set as follows:

with arcpy.da.SearchCursor(Intersect71Census, ["STOPID","POP10"]) as cursor:
    for row in cursor:
        busStopID = row[0]
        pop10 = row[1]
        if busStopID not in dataDictionary.keys():
            dataDictionary[busStopID] = [pop10]
        else:
            dataDictionary[busStopID].append(pop10)

Any command-line input or output is written as follows:

>>> aString = "This is a string"
>>> bString = " and this is another string"
>>> aString + bString 

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Select it by clicking on it, and then clicking on the Edit button."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/8662OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.