Avoiding the Snake Pit:

Python Scripting with ArcGIS Pro

Sam Giebner

  1. Python

  2. ArcGIS Pro

  3. Python 2.7 vs. 3.4

  4. Python for ArcGIS Pro

  5. Mapping Module

Python Anyone?

Python

Powerful

Easy to learn

Open-source

Cross-platform

Large user community

ArcPy

  • Esri's Python site package
  • Allows users to perform:
    • Geographic analysis
    • Data conversion
    • Data management
    • Map automation

www.codecademy.com/learn/python

ArcGIS Pro

  • Member of the ArcGIS for Desktop family
  • Provides users:
    • Project-based workflows
    • Combined 3D/2D visualization
    • Task-based work automation
    • Vector tile creation
    • 64-bit support
    • Multiple display and map layout support

What is ArcGIS Pro?

Combines the best parts of ArcMap, ArcCatalog, and ArcGlobe

Python 2.7 vs. 3.4

2.7

print "Hello Sam"

3.4

print("Hello Sam")

Print Function

2.7

3 / 2 = 1

3.4

Integer Division

3 / 2 = 1.5

Mapping Module Changes

arcpy.mapping is now arcpy.mp

  • Create a report on information contained in projects
  • Update, repair or replace layer data sources in a map
  • Find and replace a text string for all layouts in a project
  • Build PDF map books

Leverage the power of ArcObjects...

With the simplicity of Python!

Goodbye data frame...

Hello:

- Map

- MapFrame

- Camera

# Create map document object
mxd = arcpy.mapping.MapDocument("CURRENT")

# Create data frame object
df = arcpy.mappingLisDataFrames(mxd)[0]

# Create list of layers in data frame
lyr_list = arcpy.mapping.ListLayers(mxd,"",df)

# Iterate through list and print layer names
for lyr in lyr_list:
    print lyr.name

arcpy.mapping

# Create ArcGIS Project object
aprx = arcpy.mp.ArcGISProject("CURRENT")

# Create map object
m = aprx.ListMaps()[0]

# Create list of layers in map
lyr_list = m.ListLayers()

# Iterate through list and print layer names
for lyr in lyr_list:
    print(lyr.name)

arcpy.mp

Installing Python for ArcGIS Pro

Why would I install Python if it comes with ArcGIS Pro?

pro.arcgis.com/en/pro-app/arcpy/get-started/installing-python-for-arcgis-pro.htm

Download the Python setup from My Esri

www.accounts.esri.com

Managing your Pythons

py -3 python3script.py
python python2script.py

Python 2.7 

Python 3.4

Questions?

Sam Giebner

samg@northpointgis.com

218.720.67.47 ext 4

Avoiding the Snake Pit: Python Scripting with ArcGIS Pro

By North Point Geographic Solutions

Avoiding the Snake Pit: Python Scripting with ArcGIS Pro

For many years, ArcPy has been the “go-to” Python site package for geographic data analysis, data conversion, and map automation. With the release of ArcGIS Pro, users are introduced to the new Python 3.4 version of ArcPy. Like many changes to GIS software, the ArcMap to ArcGIS Pro transition is not without its growing pains. In this presentation, we will discuss the some of the common pitfalls encountered in the transition from Python 2.7 to 3.4, tips for utilizing the new ArcPy, and methods for configuring your computer to run standalone scripts for workflow automation.

  • 1,172