python: building geoprocessing tools · 2020-07-02 · python: building geoprocessing tools author:...

23
Kenneth Mitchell Python: Building Geoprocessing Tools

Upload: others

Post on 29-Jul-2020

17 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Kenneth Mitchell

Python:

Building Geoprocessing Tools

Page 2: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Why build geoprocessing tools

• Your work becomes part of the

geoprocessing framework

• Easy to access and run from within

ArcGIS Enterprise

• Familiar look and feel

• Make a mistake?

- Re-run from the previous result

• Run from anywhere you can run a tool

- Python, ModelBuilder, Service

• Multiple product support

Page 3: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Tool recipe

Geoprocessing tools are made from 3 primary ingredients

Python: Building Geoprocessing Tools

Parameters Validation Source code

Page 4: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Presenter(s)

From Python to

geoprocessing tool

Page 5: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• Tool parameters are initialized based on their definitions

Page 6: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• Any interaction with the tool

- updateParameters

- Internal validation

- updateMessages

‒ Have all the required parameters been supplied

‒ Are the values of the appropriate data types?

‒ Does the input or output exist?

‒ Do values match their filter?

Page 7: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• The OK or Run button is pushed

- Parameter values are sent

- .py is called

Page 8: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• Script receives argements

- GetParameterAsText or GeParameter functions used

Page 9: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• Script can communicate with the app with:

- Messages

- A progressor

• Script can also respond to a cancellation

Page 10: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• If any, but every tool should have an output

Page 11: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

How a tool works

• Outputs are added to the map

• Symbology is applied

• Result is added to the history

Page 12: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Script tools vs Python toolboxes

Build tools in two ways:

Which do I use? - “A tool is a tool”

Script tools Python toolboxes

• Source is Python

• Parameters through wizard

• Validation is Python (stored in toolbox)

• Source is Python

• Parameters are Python

• Validation is Python

Page 13: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Parameters

• How you interact with a tool

• Simple rules to guide behaviors

- Does an input exist?

- Is the input the right type?

- What are valid fields for this data?

- Is this value an expected keyword?

Page 14: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Parameters properties

Script Tool

• Data type

- Feature Layer, Raster Layer, Table View, …

- String, Boolean, Long, Float, …

• Direction

- Input, Output

• Parameter type

- Required, Optional, Derived

Data Type

Direction

Parameter type

Filter

Dependencies

Default

Environment

Symbology

Multivalue

Page 15: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Presenter(s)

Working with tool

parameters

Page 16: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Validation

• Provides more control

- Parameter interaction

- Calculate defaults

- Enable or disable parameters

• Setting parameters errors and messages

• Defining output characteristics

- Chain tools in ModelBuilder

Page 17: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Validation

• Mechanically, validation is about responding to

changes in:

- value/valueAsText:

- Does a parameter have a value?

- What is the value?

- Properties of the data (arcpy.Describe)

- Altered

- Has the parameter been altered?

- hasBeenValidated

- Has internal validation checked the parameter?

Page 18: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Validation

Model Builder

• Describe outputs for chaining in ModelBuilder

• By updating schema of outputs, subsequent tools can see pending changes prior to

execution

Page 19: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Presenter(s)

Tool validation

Page 20: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Keeping your work private

• Script tools have supported encryption for many releases

- Embed, then set a password

• Python toolboxes support encryption at 10.5, Pro 1.3

- Encrypt the toolbox in one step

- Python toolboxes are encrypted in place

Page 21: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Migration to ArcGIS Pro

• Use the Analyze Tools For Pro tool, to identify the following:

- ArcPy differences

- Python 2 to 3 compatibility issues

• For python differences

- See http://python3porting.com/strategies.html

- Useful for writing code that will work in both Python 2 and Python 3

Page 22: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Print Your Certificate of Attendance

Print Stations Located in 150 Concourse Lobby

Tuesday12:30 pm – 6:30 pm

Expo

Hall B

5:15 pm – 6:30 pm

Expo Social

Hall B

Wednesday10:45 am – 5:15 pm

Expo

Hall B

6:30 pm – 9:30 pm

Networking Reception

Smithsonian National Museum

of Natural History

Page 23: Python: Building Geoprocessing Tools · 2020-07-02 · Python: Building Geoprocessing Tools Author: Esri Subject: 2020 Federal GIS Conference Presentation Keywords: Python: Building

Download the Esri

Events app and find your event

Select the session

you attended

Scroll down to

“Survey”

Log in to access the

survey

Complete the survey

and select “Submit”

Please Share Your Feedback in the App