Python in ArcGIS Pro


Clinton Dow

Introduction

Today’s Presentation

Overview of ArcGIS Pro

  • Why Switch to Pro?
  • Automating ArcGIS Pro
  • Using and creating Packages

Product Engineer - Geoprocessing at Esri California (1 year 8 months)


  • Python

  • ArcPy
  • Conda Integration

  • C#/WPF

  • Python Backstage
  • Charts and Graphs

  • Presentations

  • Dev Summit
  • User Conference
  • PyCon
  • GeoPython
  • AnacondaCon

GIS Developer at Matrix Solutions in Calgary (2 years)

  • Civil Engineering/Environmental Consultant Firm
  • Created several dozen custom Geoprocessing tools in Python
  • Customized ArcGIS with Python and C#/WPF

Computer Nerd (30 years)

  • Open Source Development Experience
  • Community Moderation
  • Grown up with the internet and programming

Why ArcGIS Pro?

Modern View for ArcGIS:

  • Nearly all active development and new features
  • .Net 4.5 concurrency model
  • Integrated 2D and 3D views
  • Modern Python Experience
  • Supports environments and packages via Conda

ArcGIS Pro

Python Features in ArcGIS Pro UI

Python Window

Quick means of interacting with ArcGIS Pro using Python

  • Good way to practice and test concepts
  • View help documentation for ArcPy functions
  • Import and Export Python Scripts

Interactive Selections

  • Operate on data selected on Map
  • Automatically show result in Map

TBX Toolboxes

The original ArcGIS toolbox.

  • Created via the ArcGIS GUI
  • Tool Validation not set in Python script
  • Set via ‘Properties’ menu of tool in ArcGIS

Python Toolboxes

ArcGIS toolboxes revisited in Python

  • All steps defined in a .pyt file
  • Ease of testing & debugging
  • Validation defined within script
  • Works with Python IDEs
  • Define .pyt as a Python file type in settings
    • Syntax Highlighting
    • Autocomplete

Model Builder

Model Builder

Allows for visual creation of Geoprocessing tools

  • Consume custom geoprocessing tools
  • Ensure you are setting an output!
  • Export to Python code
  • A good way to introduce scripting concepts

Python Packages in ArcGIS Pro

Significant effort has been made at Esri to integrate Python package management and virtual environment support into the ArcGIS Pro experience.

  • Shipped with default virtual environment
  • In-app user interface
  • Packaging effort for Esri Python code

Conda in ArcGIS Pro

Python Packages and Environments

Package Management on Windows

Using pip, wheels, virtualenvs

  • Packaged with distributions of Python
  • Package devs: On OSX and Linux, ‘easy’ to get the deps! Use a system package manager (e.g. apt, brew, yum)
  • Included Compiler (e.g. clang, gcc).

Virtual Environments

What are Virtual Environments

  • Self-contained instances of Python
  • Seperate from main Python installation
  • Can contain a unique set of packages
  • Useful when working on multiple projects at one time
  • Can be shared between team members

What about Windows?

Windows lacks broadly used package management

  • Only developers have a C compiler on their machine (Typically Visual Studio)
  • Difficult problems for many organizations to reliably solve
  • “Works on my machine but not yours” problem.
  • Supporting users takes up valuable dev time
  • No guarantee that customers will be supported

Enter Conda

Why Conda?

Scientific Python community identified that there was a gap not being addressed by the core Python infrastructure, limiting their ability to get packages into the hands of users

Industry standard built by people who care about this space — Continuum Analytics

Handles dependencies for many languages (C, C++, R and of course Python)

Built for Python first, but it really solves a much broader infrastructural issue.

Coming Soon

Support for custom channels

  • Public Channels
  • Anaconda.org
  • Private Channels
  • Control package distribution, licensing etc.


Package Creation via UI

  • Currently only available in cmd line
  • Share packages with colleagues and customers


Additional Support on Server

  • Conda packages and environments fully supported on Enterprise
  • ArcGIS Python API Notebooks served on Enterprise

Using Packages to our Advantage

Open Source Ecosystem

The Python Ecosystem includes thousands of open-source packages. Saves development time and money.

Esri is using several packages in ArcGIS

  • NumPy
  • SciPy
  • matplotlib
  • Pandas (coming soon)

Open Source Ecosystem

Automate or Extend your ArcGIS capabilities

Easily package and share your work

Setting up a Development Environment

What can we install? Not just scientific packages.

  • Documentation
  • Datasets
  • GUI toolkits (PyQt, TKinter)
  • Database Drivers (psycopg2)
  • C++ Libraries (Boost)
  • IDEs

Setting up a Production Environment

Proven environments that will ‘Just work’

  • Solves ‘works on my machine’ problem
  • Metapackages
    • Packages which only have requirements
  • Environment.yaml
    • More complex requirements.txt

Packaging Tools the Right Way

Creating a Package

Using setuptools and distutils to create a Python Package.

  • setuptools
  • setup
  • pkg_resources
  • distutils
  • Legacy, use setuptools if possible

Deploying a Package

On a network

  • Point at a network location containing a package

Via a http server

  • All advantages of any http service
  • Authentication
  • Metrics
  • Availability

Anaconda.org

Deploying a Tool as a Service

Tools and data sets can be uploaded to ArcGIS Enterprise or ArcGIS Online as services.

  • Custom GP Tools
  • Datasets
  • Results

Consuming services via the ArcGIS Python API

The ArcGIS Python API is a cross-platform solution which allows for users to view, administer and interact with services on ArcGIS Enterprise or ArcGIS Online.

Thank you!! Questions/Comments?? cdow@esri.com