Python for ArcGIS Pro

Book description

Extend your ArcGIS expertise by unlocking the world of Python programming. A fully hands-on guide that takes you through exercise after exercise using real data and real problems. NOTE: This book is compatible with ArcGIS Pro 2.9.

Key Features

  • Learn the core components of the two Python modules for ArcGIS: ArcPy and ArcGIS API for Python
  • Use ArcPy, pandas, NumPy, and ArcGIS in ArcGIS Pro Notebooks to manage and analyze geospatial data at scale
  • Integrate with ArcGIS Online using Python to publish and manage data

Book Description

Integrating Python into your day-to-day ArcGIS work is highly recommended when dealing with large amounts of geospatial data. Python for ArcGIS Pro aims to help you get your work done faster, with greater repeatability and higher confidence in your results.

Starting from programming basics and building in complexity, two experienced ArcGIS professionals-turned-Python programmers teach you how to incorporate scripting at each step: automating the production of maps for print, managing data between ArcGIS Pro and ArcGIS Online, creating custom script tools for sharing, and then running data analysis and visualization on top of the ArcGIS geospatial library, all using Python.

You’ll use ArcGIS Pro Notebooks to explore and analyze geospatial data, and write data engineering scripts to manage ongoing data processing and data transfers. This exercise-based book also includes three rich real-world case studies, giving you an opportunity to apply and extend the concepts you studied earlier.

Irrespective of your expertise level with Esri software or the Python language, you’ll benefit from this book’s hands-on approach, which takes you through the major uses of Python for ArcGIS Pro to boost your ArcGIS productivity.

What you will learn

  • Automate map production to make and edit maps at scale, cutting down on repetitive tasks
  • Publish map layer data to ArcGIS Online
  • Automate data updates using the ArcPy Data Access module and cursors
  • Turn your scripts into script tools for ArcGIS Pro
  • Learn how to manage data on ArcGIS Online
  • Query, edit, and append to feature layers and create symbology with renderers and colorizers
  • Apply pandas and NumPy to raster and vector analysis
  • Learn new tricks to manage data for entire cities or large companies

Who this book is for

This book is ideal for anyone looking to add Python to their ArcGIS Pro workflows, even if you have no prior experience with programming. This includes ArcGIS professionals, intermediate ArcGIS Pro users, ArcGIS Pro power users, students, and people who want to move from being a GIS Technician to GIS Analyst; GIS Analyst to GIS Programmer; or GIS Developer/Programmer to a GIS Architect. Basic familiarity with geospatial/GIS syntax, ArcGIS, and data science (pandas) is helpful, though not necessary.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Part I: Introduction to Python Modules for ArcGIS Pro
  3. Introduction to Python for GIS
    1. Python: Built different
      1. Python versions
      2. ArcGIS Python versions
      3. What is Python?
        1. Where is it installed?
        2. Python interpreter
        3. What is a Python script?
        4. Executables included
        5. How to call the executable
        6. IDLE development environment
        7. Windows file path issues
        8. The operating system and Python system modules
    2. The basics of programming
      1. Variables
        1. Variable formatting rules
        2. Assigned to vs is equal to (value comparison)
      2. Data types
        1. Checking the data type
        2. Strings
        3. Integers
        4. Floating numbers
        5. Conversion between strings, integers, and floats
      3. Data structures or containers
        1. Tuples
        2. Lists
        3. Sets
        4. Dictionaries
      4. Iteration
        1. For loops
        2. While loops
        3. Counters and enumerators
      5. Conditionals
        1. If versus else
      6. Zero-based indexing
        1. Data extraction using index position
        2. Data extraction using reverse index position
      7. Functions
        1. Components of a function
        2. Namespaces
        3. Function examples
      8. Classes
    3. Installing and importing modules
      1. Using pip
      2. Installing modules that are not in PyPI
        1. The setup.py file
        2. Wheel files
      3. Installing in virtual environments
      4. Importing modules
        1. Three ways to import
        2. Importing custom code
        3. The site-packages folder
    4. Basic style tips for writing scripts
      1. Indentation
      2. Using print statements
      3. Structuring a script
    5. Summary
  4. Basics of ArcPy
    1. Checking your ArcPy install
      1. Using the correct Python IDLE Shell
      2. Using the Python IDLE Shell
      3. The Python window in ArcGIS Pro
    2. ArcPy environment settings
    3. ArcPy tools: Geoprocessing using ArcPy
    4. Built-in ArcPy functions
      1. The Describe function
      2. List functions
        1. The wildcard parameter
        2. Combining wildcard and feature type parameters
    5. Introduction to ArcPy modules
      1. Spatial Analyst module
    6. Summary
  5. ArcGIS API for Python
    1. What is the ArcGIS API for Python?
      1. ArcGIS API modules
      2. What does it do and why use it?
    2. The Python Package Manager
      1. Python environments
      2. How to create a new virtual environment
    3. ArcGIS Pro Notebooks
      1. Creating a Notebook in ArcGIS Pro
        1. Creating your first Notebook
        2. ArcGIS Notebook structure
        3. Keyboard shortcuts
      2. Connecting to ArcGIS Online or ArcGIS Enterprise
        1. Anonymous users
        2. ArcGIS Pro connection
        3. Built-in users
      3. Creating a Notebook
    4. Using the gis module to manage your GIS
      1. Searching for data, users, or groups
        1. Searching for public data as an anonymous user
        2. Searching for data when connected to your organization
        3. Managing users
    5. Summary
  6. Part II: Applying Python Modules to Common GIS Tasks
  7. The Data Access Module and Cursors
    1. Walking through a directory to find data
      1. arcpy.da.Walk
      2. arcpy.da.Walk exercise
        1. Unzipping files using os.walk
        2. Copying shapefiles to feature classes using arcpy.da.Walk
    2. Cursors
      1. Search cursor
        1. Accessing the geometry of a feature class
        2. Using a search cursor with a data dictionary as a lookup value
      2. Update cursor
      3. Insert cursor
    3. Summary
  8. Publishing to ArcGIS Online
    1. Using ContentManager for publishing and organizing data
      1. Publishing data
        1. Adding data from a CSV
        2. Adding and publishing tips
      2. Organizing data and managing groups and users
        1. Organizing data into a folder
        2. Accessing and managing groups
    2. Using the features module to work with feature layers
      1. Querying feature layers
      2. Editing features
      3. Appending features
    3. Using the mapping module to visualize your data
    4. Summary
  9. ArcToolbox Script Tools
    1. Introduction to script tools
    2. How to create a script tool
      1. Script tool General settings
      2. Script tool Parameters tab
      3. Script tool Validation
      4. Writing messages
    3. Exercise: Turning scripts into tools
      1. Exporting a Notebook to a script in ArcGIS Pro 2.8
      2. Copying and pasting cells to a script in ArcGIS Pro 2.7
      3. Modifying a script to accept user input in the script tool
      4. Creating your script tool in ArcGIS Pro
      5. Running and testing the script tool
      6. Updating the script tool to take census geography files
      7. Testing input parameters
      8. Adding custom messages
      9. Testing the finished script tool
        1. Testing SQL with Contra Costa Tract data
        2. Testing the script with California county geography
        3. Testing the script with a space in the area name
    4. Summary
  10. Automated Map Production
    1. Referencing projects and maps within projects
    2. Updating and fixing data sources
      1. Fixing broken links
    3. Working with layers
      1. Adding, moving, and removing layers
      2. Layer symbology
    4. Layouts
      1. Layers
      2. Layout elements
        1. Legend
        2. North arrow, scale bar, and text
      3. Exporting layouts
    5. Summary
  11. Part III: Geospatial Data Analysis
  12. Pandas, Data Frames, and Vector Data
    1. Introduction to Pandas
      1. Pandas DataFrames
      2. Pandas Series
      3. Spatially Enabled DataFrames
      4. Installing Pandas
      5. Getting data into (and out of) a Pandas DataFrame
        1. Reading data from a file
        2. Writing data to a file
    2. Exercise: From GeoJSON to CSV to SHP using Pandas
      1. Normalizing the nested JSON data
      2. Joining data frames
      3. Dropping columns
      4. Creating a CSV
      5. Creating a Spatially Enabled DataFrame from a DataFrame
      6. Dropping NaN values using dropna
      7. Querying the data frame
      8. Publishing the data to ArcGIS Online
      9. Converting an ArcGIS Online layer to a DataFrame
      10. Indexing and slicing DataFrame rows and columns
    3. Summary
  13. Raster Analysis with Python
    1. Raster data objects
      1. Creating a new blank raster
      2. Reading and copying raster properties
      3. Creating a raster object from an existing raster
      4. Saving a raster
      5. Accessing the raster properties
        1. Accessing raster and cell value properties
        2. Geographic properties
    2. ArcPy Raster tools
      1. The Spatial Analyst toolset and the sa module
        1. Generating a raster object
        2. Statistical raster creation tool
        3. Conditionals
        4. The Hillshade tool
        5. The Conditional tool
      2. Map Algebra
        1. Shorthand operators for Map Algebra
    3. Using arcgis.raster
      1. Working with imagery layers
        1. Plotting a histogram
      2. Working with raster layers
    4. Summary
  14. Geospatial Data Processing with NumPy
    1. Introduction to NumPy
      1. Advantages of NumPy arrays
      2. NumPy arrays versus Python lists
      3. Importing NumPy
    2. Basics of NumPy for rasters
      1. Creating an array 
      2. Reading a raster into an array
      3. Array properties
        1. Size
        2. Shape
        3. Data type
      4. Accessing specific elements
      5. Accessing a subset of the array
      6. Slicing a raster
      7. Concatenating arrays
      8. Creating a raster from a NumPy array
      9. Mathematical operations with NumPy
      10. Array queries
    3. Exercise: Statistical analysis of raster data using NumPy
      1. Creating charts from NumPy arrays using Matplotlib
    4. Summary
  15. Part IV: Case Studies
  16. Case Study: ArcGIS Online Administration and Data Management
    1. Case study: Administering your ArcGIS Online account
      1. Creating users
      2. Assigning licenses and credits
      3. Creating reports for item usage
      4. Reassigning user data
        1. Transferring data to a different user and creating a new folder
        2. Transferring data to a different user with an existing folder
    2. Case study: Downloading and renaming attachments
    3. Summary
  17. Case Study: Advanced Map Automation
    1. Case study introduction
    2. Setting up a layout for map automation
      1. Source text element
      2. Inset map frame
      3. DetailsHeader and DetailsBox text elements
      4. Legend element
      5. Legend Item elements
      6. Scale bar and north arrow elements
        1. Scale bar
        2. North arrow
      7. Title text element
        1. Map Frame element
    3. Creating and adding data to your map
    4. Working with legend and text elements in the layout
    5. Changing the map view and exporting
    6. Summary
  18. Case Study: Predicting Crop Yields
    1. Case study introduction
      1. Data and study area
      2. Data concepts
    2. Downloading datasets
      1. World countries
      2. Population
      3. Rainfall
      4. Agricultural land
      5. Crop yields
      6. Pesticide and fertilizer use
      7. Temperature change
    3. Cleaning up and combining the data
    4. Fitting a random forest model
    5. Loading the result into ArcGIS Online
    6. Generating an HTML file using ArcGIS API for JavaScript
    7. Summary
  19. Other Books You May Enjoy
  20. Index

Product information

  • Title: Python for ArcGIS Pro
  • Author(s): Silas Toms, Bill Parker
  • Release date: April 2022
  • Publisher(s): Packt Publishing
  • ISBN: 9781803241661