Skip to main content

2022 | Buch

A Geographer's Guide to Computing Fundamentals

Python in ArcGIS Pro

insite
SUCHEN

Über dieses Buch

This upper-undergraduate textbook teaches students programming in GIS using a mix of computer science theory and hands-on activities, with the aim of empowering students to understand fundamentals and apply their knowledge beyond the specific examples in the book. Each of the book’s twenty-one chapters integrates instructional material with exercises in ArcGIS Pro. In doing so, this book combines the strengths of workbooks and theoretical textbooks to provide a holistic and comprehensive text. Each chapter concludes with an unguided task that ensures students have learned the broader principles explained therein. In addition to its unique format, the book covers oft-neglected topics such as debugging, creating a program from scratch, and managing metadata.

Section I starts with the principles of scripting and programming with Python. Section II introduces the ArcPy module and elements specific to ArcGIS Pro. This section focuses on data structures, and how they are used and implemented within Python. Section III uses the topic of algorithms to guide the student through creating tools to add functionality to ArcGIS Pro. The last section, Section IV, builds upon section III to guide the student to developing and sharing projects and Python packages to include external open-source code and share the Python code as an open-source package.

This text will prepare students for a long-term ability to do GIS programming, whether in industry or academic research. This comes from the author’s observations of students who have learned GIS programming in one platform, such as VBA in ArcMap, struggle to apply that knowledge to a new platform, such as Python in ArcGIS Pro, because the content was presented too closely with a specific platform. The integration of exercises with conceptual content, along with the choice of chapter content, serves this goal of preparing students for working in a dynamic, rapidly changing technology field.

Inhaltsverzeichnis

Frontmatter

Part I

Frontmatter
1. Introduction to Scripting and Programming
Abstract
This chapter introduces the reader to scripting and programming, how these two are related, and why they are useful within ArcGIS Pro. There are a couple reasons users might want to write their own scripts or programs. First, they might want to automate a series of steps in a single workflow, so that it becomes easier to carry out the process represented in that workflow. Second, they may want to introduce new tools and new functionality to ArcGIS Pro. This chapter also introduces the reader to the general principles of programming, in which the programmer has to translate what they want into an algorithm for the computer. The algorithm is a series of detailed steps, or instructions, that tell the computer what to do. The chapter finishes with an example of creating an outline to carry out that process of creating an algorithm.
Jamison Conley
2. Basics of Programming: Variables, Operators, and Statements
Abstract
This chapter begins the introduction to programming itself by way of the specifics of Python. While the first chapter introduced the concepts of an algorithm and using an outline, this is the first of three chapters that takes these ideas and brings them into the Python programming language. This chapter introduces the concepts of variables, operators, and statements, and uses the analogy of writing in a foreign language to help the reader understand these concepts. Variables are like the nouns in a language, operators are analogous to verbs, and statements are simple sentences. This chapter also introduces the reader to the concepts of parsing, which is how the computer reads a program, and debugging, which is how to fix problems within the code.
Jamison Conley
3. Basics of Programming: Control Structures
Abstract
This chapter extends the previous chapter to move from simple statements to more complex statements, specifically conditional statements, also known as if/then/else statements, and loop statements, which in Python can take two forms: for loops and while loops. It also extends the ideas of parsing to understanding how the computer reads instructions that extend beyond a single line of code.
Jamison Conley
4. Basics of Programming: Functions and Objects
Abstract
This chapter completes the introduction to Python programming by extending the writing metaphor to paragraphs, which are akin to functions. It also introduces the ideas of input parameters and output values, as these are critical to understanding how functions work. This chapter also introduces the concepts of objects in programming, which are a more complex type of variable, thereby allowing more complex programs. Parsing an entire function is presented, which introduces the idea of a parsing stack, as the computer keeps track of how and where it is moving from one line of code to another within a single script.
Jamison Conley
5. Reading a Python Script
Abstract
This chapter introduces readers to a skill that is frequently useful in applied scripting or programming situations, but not always covered: how to read Python code that is found from another source. It starts by introducing the reader to IDLE instead of the ArcGIS Pro Python Window. IDLE is a development environment that is provided with ArcGIS Pro, and can provide additional capabilities beyond those inside ArcGIS Pro itself. One of these is the ability to step through a script line by line to better investigate what the values of variables are, so that someone can determine whether the code does what they want to accomplish. It also shows how to read documentation to help decipher unfamiliar commands. Lastly, the reader is introduced to the idea of comments within the code, which are regular notes that help translate back and forth between what the programmer wants to do and the computer code itself.
Jamison Conley
6. Debugging
Abstract
This chapter introduces different types of errors: syntax errors, runtime errors, and logical errors. It then shows some common debugging strategies which can be used in the Python Window, such as adding print statements to investigate the values of variables. It also shows how the debugger works in IDLE, which complements the ideas from the previous chapter and can be useful for more complex scripts. In both cases, how to read and interpret error messages is covered, as well as the idea that the error message appears when the computer discovered there’s an error, rather than where the error occurred. Lastly, much of what the reader/student is expected to accomplish is through the unguided work section of the chapter, in which they must use the strategies presented in this chapter to determine what the errors in a provided script are.
Jamison Conley

Part II

Frontmatter
7. Introduction to ArcPy
Abstract
As the start of Section II, this chapter transitions the reader from basic Python to the specifics of ArcPy within ArcGIS Pro. It does so through introducing the structure of the documentation provided for ArcPy, and examining commonly used classes and functions to highlight elements of that documentation as well as introduce those classes and functions. Lastly, it explains how to use the documentation to run an ArcGIS Pro tool within the ArcGIS Pro Python Window.
Jamison Conley
8. Basics of Accessing Data in ArcGIS
Abstract
Much of what we do with ArcPy scripts works with data in ArcGIS Pro, so this chapter moves from the introduction into how data is set up and accessed. As a first step with the use of data in ArcPy, it examines a function for describing data, called the Describe function, which allows the user to identify what type of data it is. In addition to the data-focused elements, the chapter introduces the idea of inheritance of properties for classes and subclasses, through the ways that data classes in ArcPy inherit properties and functions from generic superclasses, such as how all properties of vector data are inherited by shapefiles and by vector geodatabase classes, as both are subclasses of vectors. Lastly, the chapter explains how to run ArcPy code within IDLE instead of the ArcGIS Pro Python Window.
Jamison Conley
9. Rasters
Abstract
This chapter is the first one to look at specific data types, presenting the simpler one first: raster data. Four common tasks with raster data are presented: calculating a slope, reclassifying data, calculating an aspect, and carrying out map algebra.
Jamison Conley
10. Tables and Cursors
Abstract
This is the first of two chapters focusing on vector data, and it looks at how attribute data is accessed and manipulated. This is through cursors, which are objects that permit the script to loop through the rows of the attribute table, as well as use an SQL query to subset the rows in the table. The three types of cursors are presented: search cursors, update cursors, and insert cursors. More advanced uses of cursors are also presented, such as looping through two tables to calculate new attributes instead of joining the tables, and using dictionaries to manage the data in ArcPy.
Jamison Conley
11. Vectors and Geometries
Abstract
The second chapter on vector data looks at how to access and use the geometry information of vector data. This continues the use of cursors, as they are the means of accessing the shape information. The chapter also describes geometry functions for both one geometry, such as creating a buffer, and two geometries, such as finding the intersection of two polygons. Lastly, the chapter describes how to create a geometry.
Jamison Conley
12. Mapping—Symbologies
Abstract
This is the first of two chapters on creating maps within ArcPy. It looks at how the symbology of the map is accessed and changed within ArcPy. The first basic approach is adding a layer to the map, followed up with how the properties of a layer, such as whether it is visible, are edited. Then the symbology of the data within the layer, such as the class breaks for a choropleth map, is changed.
Jamison Conley
13. Mapping: Layouts
Abstract
The second of the mapping chapters focuses on the aspects of the layout, instead of the layers themselves. The concept of the map frame is introduced as the container on the page that holds the map figure. Then other elements of the map, such as the scale bar, text for the title and credits, and legends, are all introduced and edited within the map.
Jamison Conley

Part III

Frontmatter
14. Creating Custom Tools
Abstract
This is the first chapter of the third section of the book, focused on algorithms and how they are used to extend ArcGIS Pro’s functionality. This introduces the ability to create a custom tool, including setting the parameters for it and then writing Python code for that tool. This includes how to ensure the tool accesses the correct Python file, as well as how to ensure the code is able to access the parameters provided by the user in the tool’s dialog box. Lastly, the chapter presents how to share the tool to a wider audience.
Jamison Conley
15. Error Handling
Abstract
This chapter extends the previous one, by taking the tool created in Chap. 14 and adding error handling to it, so that the program behaves better when the user has problematic inputs, such as accidentally entering values in the wrong input boxes. To accomplish this, two additional programming skills are introduced: the ability to create custom functions and the ability to use the try/except conditional statement for creating and handling custom error messages.
Jamison Conley
16. Creating Custom Classes
Abstract
This chapter continues the algorithmic enhancements from Chap. 15. To accommodate a more complex algorithm for adding new capabilities to the tool within the previous two chapters, the ability to create a custom class is introduced. This process starts with planning using Unified Markup Language (UML), flow charts, and pseudocode as strategies to help the student plan out the new class. Then the plan is converted into Python code, first through creating a template using comments within the script and then adding Python code into the template. This illustrates the principles of “divide and conquer” programming, wherein a larger task is broken down into a series of more manageable subtasks. Lastly, there is debugging that is inevitable.
Jamison Conley
17. Putting It All Together
Abstract
This chapter is different from the others, in that it does not explicitly introduce any new programming or ArcPy skills or concepts. It instead challenges students through the use of a scenario wherein they are given data and a set of tasks to complete by creating custom tools and Python programs to finish those tasks. Where the guided work would normally be, there is instead a worked example of taking a set of guidelines or specifications and turning those into a custom tool. It also illustrates the practice of testing the new tool to ensure that it meets all the desired specifications.
Jamison Conley

Part IV

Frontmatter
18. ArcPy for Web GIS Using ArcGIS Online
Abstract
This chapter will introduce concepts of Web GIS and illustrate these concepts through the use the arcpy.sharing module. The use of data portals for Web GIS is also included. Just as important as writing the code here is creating metadata and the necessary information to enable people who come across your ArcGIS Online project to use and interpret it effectively.
Jamison Conley
19. Incorporating External Packages
Abstract
This chapter will take the ideas of sharing code and use that to incorporate code that has been shared online as a package. This will be carried out using examples from statistical computing using external packages such as the NumPy package and the arcgisbinding package in R.
Jamison Conley
20. Using Multiple Python Files
Abstract
This chapter extends the algorithm chapters to move from creating custom classes in Python to creating custom packages. In doing so, the use of UML to facilitate more complex forms of software engineering is presented. It also introduces the rationale and complexity of developing a package with multiple python files. It concludes with an example creating a package.
Jamison Conley
21. Developing a Custom Python Package
Abstract
This chapter has a similar approach to Chap. 17, concluding Part III, in that it focuses on the development process rather than introducing new computational concepts or techniques. The process of developing a package to meet specified criteria is presented, along with the process of debugging it and testing it to ensure it works. Lastly, the creation of documentation to enable proper sharing and use of the package is covered.
Jamison Conley
Backmatter
Metadaten
Titel
A Geographer's Guide to Computing Fundamentals
verfasst von
Jamison Conley
Copyright-Jahr
2022
Electronic ISBN
978-3-031-08498-0
Print ISBN
978-3-031-08497-3
DOI
https://doi.org/10.1007/978-3-031-08498-0

Premium Partner