Python & GIS - Section Overview

ENV 859 - Geospatial Data Analytics   |   Fall 2024   |   Instructor: John Fay  

Introduction

With the fundamentals of coding in Python starting to settle in, we now return to geospatial analysis. This effort begins with a look at how we can extend Python with Python packages - modules developed by others that bring new functionality to our coding environment. Among those packages is ArcPy, written by the folks at ESRI to give us pretty much the entire functionality of ArcGIS Pro from Python. We spend a bit of time learning what we can do with the ArcPy package and how it’s done. And in doing so, we learn quite a bit about how Python is extended using packages - and the limitless possibilities this opens us up to.

Demo: Hurricane Mapper – In Python: HurricaneMapperPY.zip

Resource: https://www.esri.com/en-us/arcgis/products/arcgis-python-libraries/libraries/arcpy


Section organization & learning outcomes

Section Learning Objectives
Python environments &
extending Python
♦ Explain what Python modules & packages are and how they are used
♦ Contrast built-in vs 3rd party modules & packages
♦ Describe: “Anaconda”, “Miniconda”, and “Enthought” distributions…
Conda & Coding Environments ♦ Explain what a Python environment is and why they are needed
  -Create new/cloned Conda environments using Conda
  -Set a particular Conda environment to be the default environment
♦ Locate and install packages into a Conda environment
   -Finding packages and package documentation via package repositories
   -Add packages to a Conda environment via conda and via pip
Import packages and package components into a Python script
Prepping a GIS Coding Project Preparing your machine
  -Installing ArcGIS Pro
  -Cloning the ArcGISPro-py3 Conda environment
  -Installing necessary packages into your environment
Preparing your workspace
  -Creating folders
  -Setting your scripts folder as a Git repository
Thinking about your analysis
  -Looking for patterns in your data
  -Generating pseudocode
  -Expanding your coding toolkit…
Geospatial Analysis with ArcPy ♦ Understand the structure of the ArcPy package and its sub-modules
  -Describe what ArcPy functions and classes are and how they are used
  -Explain how extensions are enabled and licenses are set within coding environments
Create and run Jupyter notebooks from within ArcGIS Pro and ArcGIS online
♦ Access and describe spatial datasets from the coding environment
   -Learn techniques to use relative paths vs. absolute paths
♦ Run any geoprocessing tool from a coding environment
♦ Get and set ArcGIS geoprocessing environment variable values
♦ Iterate through features/records using cursors
♦ Access and manipulate geometric objects stored in feature classes
♦ Execute raster commands within a coding environment
Plan, write, debug, and share Python-based geoprocessing tools
Writing a GIS Coding Script Create an empty feature class
  -Setting its spatial reference using the spatial reference class
♦ Adding attributes to our feature class
Debugging errors
  - Syntax errors
  - Coding errors
  - Logic errors
♦ Creating geometric objects (points, lines, polygons
♦ Creating geometric features (geometries + spatial reference + attributes)
Adding geometric features to a feature class with cursors
Iterating through several text files
♦ Creating script based tools in ArcGIS Pro