Use Python modules such as ArcPy, ArcREST and the ArcGIS API for Python to automate the analysis and mapping of geospatial data.
About This Book
Perform GIS analysis faster by automating tasks.
Access the spatial data contained within shapefiles and geodatabases and transform between spatial reference systems.
Automate the mapping of geospatial analyses and production of map books.
Who This Book Is For
If you are a GIS student or professional who needs an understanding of how to use ArcPy to reduce repetitive tasks and perform analysis faster, this book is for you. It is also a valuable book for Python programmers who want to understand how to automate geospatial analyses and implement ArcGIS Online data management.
What You Will Learn
Understand how to integrate Python into ArcGIS and make GIS analysis faster and easier.
Create Python script using ArcGIS ModelBuilder.
Learn to use ArcGIS online feature services and the basics of the ArcGIS REST API
Understand the unique Python environment that is new with ArcGIS Pro
Learn about the new ArcGIS Python API and how to use Anaconda and Jupyter with it
Learn to control ArcGIS Enterprise using ArcPy
In Detail
ArcGIS allows for complex analyses of geographic information. The ArcPy module is used to script these ArcGIS analyses, providing a productive way to perform geo-analyses and automate map production.
The second edition of the book focuses on new Python tools, such as the ArcGIS API for Python. Using Python, this book will guide you from basic Python scripting to advanced ArcPy script tools.
This book starts off with setting up your Python environment for ArcGIS automation. Then you will learn how to output maps using ArcPy in MXD and update feature class in a geodatabase using arcpy and ArcGIS Online. Next, you will be introduced to ArcREST library followed by examples on querying, updating and manipulating ArcGIS Online feature services. Further, you will be enabling your scripts in the browser and directly interacting with ArcGIS Online using Jupyter notebook. Finally, you can learn ways to use of ArcPy to control ArcGIS Enterprise and explore topics on deployments, data quality assurances, data updates, version control, and editing safeguards.
By the end of the book, you will be equipped with the knowledge required to create automated analysis with administration reducing the time-consuming nature of GIS.
Style and approach
The book takes a pragmatic approach, showing ways to automate repetitive tasks and utilizing features of ArcPy with ArcGIS Pro and ArcGIS online.
Author(s): Silas Toms; Dara O'Beirne
Edition: 2
Publisher: Packt Publishing
Year: 2017
Chapter 1. Introduction to Python for ArcGISIn this chapter, we will discuss the development of Python as a programming language from its introduction in the late 1980s to its current state. We will discuss the creator of the language and the philosophy of design that spurred its development. We will also touch on important modules that will be used throughout the rest of the book, and especially focus on the modules built into the Python Standard Library. We will configure Python and the computer to execute Python scripts. The structure of the Python folder will be discussed, as will the location of the ArcPy module within the ArcGIS folder structure. We will also discuss Integrated Development Environments (IDEs)--programs designed to assist in code creation and code execution--comparing and contrasting existing IDEs to determine what benefits each IDE can offer when scripting Python code.This chapter will cover the following topics:Quick Overview of Python: what it is and what it do
Chapter 1. Introduction to Python for ArcGIS
Chapter 2. Creating the First Python ScriptWith the Python environment configured to fit our needs, we can now create and execute ArcPy scripts. To ease into the creation of Python scripts, this chapter will use ArcGIS ModelBuilder to model a simple analysis, and export it as a Python script. ModelBuilder is very useful for creating Python scripts. It has an operational and a visual component, and all models can be outputted as Python scripts, where they can be further customized. This chapter we will cover the following topics:Modeling a simple analysis using ModelBuilderExporting the model out to a Python scriptWindows file paths versus Pythonic file pathsString formatting methods
Chapter 2. Creating the First Python Script
Chapter 3. ArcPy Cursors - Search, Insert, and UpdateNow that you understand how to interact with ArcToolbox tools using ArcPy, you will have a basic understanding of how to improve GIS work flows using Python. In this chapter, we will cover data cursors and the data access module introduced in ArcGIS 10.1. Data cursors are used to access data records contained within data tables, using a row-by-row iterative approach. The concept was imported from relational databases, where data cursors are used to extract data from tables returned from an SQL expression. Cursors are used not only to search for data, but also to update data, or to add new data.When we discuss creating data searches using ArcPy cursors, we are not just talking about attribute information. The new data access model cursors can interact directly with the shape field, and when combined with ArcPy Geometry objects, can perform geospatial functions, and replace the need to pass data to ArcToolbox tools. Data access cursor
Chapter 3. ArcPy Cursors - Search, Insert, and Update
Chapter 4. ArcPy Geometry Objects and CursorsThe essence of geospatial analysis is using geometric shapes--points, lines, and polygons--to model the geography of real-world objects and their location-based relationships. The simple shapes and their geometric properties of location, length, and area are processed using geospatial operations to generate analysis results. It is the combination of modeled geographic data and the associated attribute information that separates geospatial information systems from all other information systems.Until ArcPy, processing feature class geometry using geospatial operations depended on the pre-built tools within ArcToolbox. ArcPy has made it possible to directly access the geometric shapes which are stored as mathematical representations in the shape field of feature classes. Once accessed, this geometric data is loaded into ArcPy geometry objects to make the data available for analysis within an ArcPy script. Because of this advance, writing script
Chapter 4. ArcPy Geometry Objects and Cursors
Chapter 5. Creating a Script ToolNow that the basics of creating and executing ArcPy scripts have been covered, we need to take the next step, and create reuseable "script tools". Creating script tools will allow for greater code reuse, and will make it easy to create custom tools for other GIS analysts and customers. With a Python script "back end", or code, and a familiar ArcGIS tool "front end" or graphical user interface (GUI), the custom script becomes a reliable tool for all users within a GIS work shop.This chapter will cover the following topics:Adding parameters to scripts to accept input, and produce output as required by the userCreating a custom tool front end and a custom toolboxSetting the parameters of the tool front end to allow it to pass arguments to the code back end
Chapter 5. Creating a Script Tool
Chapter 6. The arcpy.mapping ModuleCreating maps is an art, one that can be learned through years of dedicated study of cartography. The visual display of information is both exciting and difficult, and can be a rewarding part of the daily work flow of geospatial professionals. Once the basics have been learned and then mastered, cartographic output becomes a constant battle to produce more maps at a faster pace. ArcPy once again has a powerful solution: the arcpy.mapping module.By allowing for the automatic manipulation of all map components, including the map window, the layers, the legend, and all text elements, arcpy.mapping makes creating, modifying, and outputting multiple maps fast and simple. Map book creation, another important skill for geospatial professionals, is also made easy using the module. In this chapter, we will discuss some basic functionality available through arcpy.mapping and use it to output a map book of bus stops and their surrounding census blocks.This chapt
Chapter 6. The arcpy.mapping Module
Chapter 7. Advanced Analysis TopicsArcGIS for Desktop extensions benefit from the power of Python and ArcPy. In this chapter we'll explore two important examples of extensions, the Network Analyst and Spatial Analyst modules. Each of these modules have ArcPy wrapper tools to access ArcToolbox. They also have ArcPy access modules for improved control of available tools, methods, and properties. Using the extensions and ArcPy scripting, advanced analysis workflows such as modeling traffic or planning bus routes using a streets dataset can be automated.This chapter will cover the following topics:Creating a simple network datasetChecking out the extensionsThe ArcPy Network Analyst moduleThe ArcPy Spatial Analyst module
Chapter 7. Advanced Analysis Topics
Chapter 8. Introduction to ArcGIS OnlineIn this chapter, we will discuss the use of ArcGIS Online to create web maps and share geospatial data. ArcGIS Online, created by Esri, is built to easily integrate web mapping into any production ArcGIS environment. By adding the ability to publish data to the cloud directly from an MXD, Esri has made it easy to share analysis results with the public or with a specific group of users.This chapter will cover the following topics:The basics of ArcGIS OnlineSigning up for an ArcGIS online accountFeature services and layersPublishing data from an MXD
Chapter 8. Introduction to ArcGIS Online
Chapter 9. ArcPy and ArcGIS OnlineNow that we have reviewed the basics of ArcGIS Online, we will go through some more advanced functionalities and begin to build the foundation to interact with ArcGIS Online hosted feature services using Python. In order to program with Python and ArcGIS Online, we will need to first understand how the data is formatted and the methods used to access that data programmatically.This chapter will cover the following topics:ArcGIS Online REST servicesURL parametersUsing ArcGIS feature setsArcGIS Online tokensUpdating a feature class from an AGOL-hosted feature service
Chapter 9. ArcPy and ArcGIS Online
Chapter 10. ArcREST Python PackageAfter the introduction to the ArcGIS REST API and beginning to work with Python and ArcGIS web services, we have now built the foundation of knowledge necessary to begin working with the ArcREST Python library developed by ESRI. This module is designed for working with the ArcGIS REST API and making it easier and more efficient. If you work with ArcGIS Online, Portal for ArcGIS, or ArcGIS Server, the ArcREST Python package will make managing services and the administration of your sites much easier. As you may remember from the previous chapter, we wrote a function called return_token that was approximately 14 lines of code in order to access a token for an ArcGIS feature service. Now, using ArcREST, we will show you how to get this token with only one line of code, along with many other use cases. Although you can use ArcREST with Portal for ArcGIS and ArcGIS for Server, in this chapter, we will primarily be covering use cases for ArcGIS Online.This
Chapter 10. ArcREST Python Package
Chapter 11. ArcPy and ArcGIS ProAfter reviewing ArcPy and the ArcGIS Online infrastructure, we are shifting gears back to the latest desktop product release from ESRI, which is called ArcGIS Pro. ArcGIS Pro is the most recent release of ArcGIS desktop apps that speeds up processing and improves 3D and 2D cartographic representation. In this chapter, we will review some of the significant differences between ArcGIS Pro and ArcMap. The majority of the material covered in this chapter reviews the differences between using ArcPy in ArcGIS Pro as compared to the traditional ArcMap environment. We will discuss some of the significant architectural changes within the Python environment, as well as the use of a Python package manager called Conda.In this chapter, we will cover the following topics:Introducing ArcGIS ProArcGIS Pro configurationPython 3.5 and ArcGIS ProPython installation and configurationArcGIS Pro Python windowConda
Chapter 11. ArcPy and ArcGIS Pro
Chapter 12. ArcGIS API for PythonAfter reviewing some of the basics of Python and covering the foundational knowledge required to program with Python using ArcGIS Online and ArcGIS Enterprise, we can now move on to the newest release by ESRI, the ArcGIS API for Python. ESRI has been working on an easy and efficient solution to combine desktop scripting with online web mapping and infrastructure. The ArcGIS API for Python is ESRIâs most modern solution to scripting for web mapping with Python. In the next chapter, we will cover the basics of the ArcGIS API for Python and learn how to configure our environment to work with the API using two versions of Python.In this chapter, we will cover the following topics:Introducing the ArcGIS API for PythonInstalling Anaconda and working with JupyterIntroducing the four primary modulesProviding script examples to create a web map and interact with dataAn example of administering an ArcGIS Online account
Chapter 12. ArcGIS API for Python