Module 02

Essential geoprocessing and analysis

Yesterday in the Great Smokies
Webcam archive
GEO 409: Advanced GIS


  • Lab is now open after-hours.
  • Use student ID for swipe access.
  • Check first submission on Canvas for ❤️

Virtual field trip to

Natural Bridge State Resort Park


Historic images from


  • Review first lab
  • Build a Notebook that will clip any number of layers to any AOI.
  • Perform summary statistics on the clipped layers
  • Start making a base map for Kentucky (to use in module 4).

Lab review

Lab 1

  • Find points within search area.
  • Now we have a density measure.
    • 3.14 * 52 = 78.5 sq mi
    • 2 places per 10 sq mi.
  • How does this compare to other locations?
  • Trivial question because we have a script!


  • if you had a hundred locations to search and compare.
  • Wouldn't it be awesome to automate this redundant task?
  • Will discover the for loop in this lesson.

Hold up!

  • We found 15 and 16 places.
  • How do you represent a polygon as a point?

Center of polygon?

  • Irregular and multipart polygons?
  • Why not buffer the polygon?
  • Centering requires knowledge of the geometry units.

Lab 2

  • You have a geodatabase with many layers
  • that need extraction to an AOI.
  • Perform summary statistics on the layers.
  • Automate workflow in Notebook.

Go from massive amounts of data

to analysis and visualization.

Python Essentials

In-class task

  • Create a Notebook called, 'practice-02.ipynb'
  • Practice along in the following examples.


  • Block of statements that execute when called.
  • The function might accept input data as arguments.
  • The function might return data.
  • Many ArcPy functions output data to the disk.
  • 📚 ➡ 🔨 ➡ 🌟

Most important function?

  • The print() function
  • reveals the contents of variables
  • and tells you if a block of code runs.
  • Tip: whenever code is indented, print something!


  • Variables inside function
  • which allow us to pass information to the function.
  • Their sequence is critical.

Clip function

  • Perhaps most used GIS function
  • Clips spatial data to an Area of Interest (AOI)
  • Requires three parameters
  • Most everyone, initially, gets the parameter order mixed up.

Clip function

  • The spatial data is the cookie dough
  • The AOI is the cookie cutter
  • The output is the cookie

ArcGIS Pro example


  • ALWAYS read the documentation.
  • Do a web search with 'arcpy {function name}'


  • String formatting that allows concatenation of:
    • variables
    • expressions
    • and numbers.
  • Build strings from variables.


  • Sequence of values, aka items or elements
  • Also known as arrays.
    • Enclosed in square brackets [ ]
    • Elements separated by commas ,
    • Elements are ordered.
  • Common way to store data.

for loops

  • iterate over a sequence of values.
  • Use with a list
  • to access each element in the list.

In-class task

  • Create a Notebook called, 'state-base-map.ipynb'
  • Open lesson and build Notebook cells.
  • Then, refactor the code.

Summary Statistics

  • Aggregate features based on shared attributes.
  • How long is the Kentucky River?
  • How much forested land in Kentucky?
  • How much of x is in y?

Vector layers

  • Look for common attributes.
  • Combine features
  • and look at Shape_Length and Shape_Area attributes.


In-class task

  • Explore streams layer
  • both geometry and attribute table
  • and use these two functions.

Statistics on-the-fly

  • SearchCursor function
  • iterates over records in a table
  • accessing any field value.

Raster layers

  • Matrix of cell values
  • always a number.
  • Look for cell size.

Continuous raster

  • Cell number represent varying quantity.
  • Elevation, temperature, precipitation, etc.
  • Digital elevation model (DEM).

Imaging raster

  • Cell number represent reflected/emitted light.
  • Multiple bands.
  • Photography, satellite imagery, renderings, etc.
  • Shaded relief (artificial illumination).

We'll look at these in the next module

Integer raster


  • Count and value fields
  • with total count * area of cell = total area

In-class task

  • Explore NLCD layer
  • and find total area of forest.

Lab 2 Goals

  • Find percent of total and area of NLCD classes
  • in a custom area of interest.

Lab 2 Requirements

  • Check Deliverables.
  • Basic flow:
    • Set up local environment
    • Define area of interest
    • Clip
    • Summary Statistics

Let's jump in

  • Tip: work with your neighbor.
  • Code is very sharable.



  • Where's my data?
  • Functions have input AND output.


  • If you are not getting them, then you are
    • lucky
    • or not making practicing.
  • Errors are your friend.

Syntax errors

  • Typeos
  • in file path names, variables, etc.
  • Using functions properly?
  • Throws an error, look at last line.


  • If the error has a code, ERROR 000670, search it.
  • Remove layers from Contents pane.
  • Rebuild your Notebook from scratch.

Big Picture

  • Once you have a working Notebook
  • you can answer how much of x is in y (*)
  • for any area in Kentucky.


Python II


Build a function

Build a function

  • Store and reuse statements
  • def keyword defines a function
  • followed by unique name and():
  • Parameters? i.e., does the function use data?
  • Indent function body four spaces


  • Whenever you use a function
  • look up its documentation.
  • ArcGIS Pro has excellent docs 🚀


  • Functions that only work on certain types. 🔮🐉
  • String type, integer type, csv type, etc.
  • Uses dot notation, i.e., myString.upper()


String Methods

  • Perform common tasks on strings
  • Find substrings, change case, etc.
  • Most return new values, others return `True` or `False`
  • They do not change the original string.
  • Built-in methods


justWords = "If you live to be a hundred, I want to live to be a hundred minus one day so I never have to live without you."

String slice

  • Access substring using [start : end] indexes
  • Two index values separated by a colon : inside bracket [] notation
  • End index is up-to-but-not-including
  • "Let's Hike"[0:2] returns "Le"

String stride

  • Optional third number in [start:end:stride]
  • Third number returns every nth character
  • By default, 1
  • Negative numbers reverse the string

Slice a URL

A uniform resource locator is the unique address of anything on the Web.



  • Interrupts sequential execution of code
  • runs same block of code over and over
  • modifying it with each new run
  • until a desired condition is found.


  • Loop statement ends with semicolon :
  • loop block is indented four spaces
  • runs block until a condition is met.

for loop

  • Iterate over sequence
  • value by value
  • with an iterating variable
  • until all values have been accessed
  • or until a break occurs in the block.

while loop

  • Runs while statement remains true
  • or until a break occurs in the block.
  • Can run indefinite number of times.

Python lists

  • A collection of values in a sequence.
  • One of the most common data collections.
  • Values enclosed in [ ] square brackets
  • and separated by commas.