automating processes with arcpy to do work so i don’t have to joe guzi gis systems analyst stark...

33
Automating Processes with ArcPy Automating Processes with ArcPy to do work so I don’t have to to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September 21 - 23, 2015 | Hyatt Regency Columbus| Columbus, Ohio

Upload: jacob-boyd

Post on 03-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automating Processes with ArcPy Automating Processes with ArcPy to do work so I don’t have toto do work so I don’t have to

Joe Guzi

GIS Systems Analyst

Stark County GIS Department

2015 Ohio GIS ConferenceSeptember 21 - 23, 2015 | Hyatt Regency Columbus| Columbus, Ohio

Page 2: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Why Automate processes?

•Not only to do work so I don’t have to•But mainly to Free me up to do more work

Page 3: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Why do more work?

•Because work leads to Taking Over the world!

Page 4: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September
Page 5: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies

•Walk through Process•Test•Be prepared•Task Scheduler and BAT Files•Maintenance•Excel Sheet To Maintain Schedule•Code Examples

Page 6: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Walk through process

Page 7: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Walk through process

Page 8: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Walk through process

Page 9: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Test

Page 10: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Test

Page 11: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Test Again

Page 12: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Task Scheduler and BAT Files

Page 13: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Task Scheduler and BAT Files•Bat Files

▫Just Text Files saved with a bat extension▫Written using DOS Commands ▫Syntax

Page 14: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Task Scheduler and BAT Files

Page 15: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Automaton Strategies:Task Scheduler and BAT Files•Task Scheduler Parameters:

▫Trigger – Declare when the task will run and how frequently

▫Actions – Declare what the Task will do▫Conditions – Declare computer setting for

power or idle▫Settings – Determine how the task can be

treated Allow the task to run on demand Stop the task if it takes forever

Page 16: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Excel Sheet to Maintain Schedule

Page 17: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Code Examples

Page 18: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Code Examples:Layer Update Automation

Page 19: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Code Examples:Feature Update Email Notification

Page 20: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Code Examples:Automation of Tax Map Updates

Page 21: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Code Examples:Cache Error Detection

Page 22: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks

•Section your code•Comment Comment Comment•Use Print Command•Error Block•Email Notification•Create Logs•Time•Use Resources

Page 23: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks:Section your code

•Description•Import Section

•Variables•Processes•Output•Error Reporting

Page 24: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September
Page 25: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Comment Comment Comment• Comment everything• If you change your code

comment the change• You never know when you

will have to come back to your code and commenting will be the best way to remember why you did something

• Also commenting is good back up in case something happened to the author (God forbid)

Page 26: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Comment Comment Comment

Page 27: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Use the print Command

Page 28: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Error blocks

Page 29: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Email Notification

Page 30: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Create logs

Page 31: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Time• Time Libraries:

▫ Time▫ Datetime

• Time.gmtime• datetime.datetime.utcnow

()• datetime.timedelta(minute

s = 15)• str(DayAgo)[0:19]• "( LAST_EDITED_DATE

>= '" + DayAgoFormat + "' )"

Page 32: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Python Tips and Tricks: Use Resources•Python Window in ArcGIS desktop•ArcGIS Resources Python Section•Geoprocessing Tool References•GitHub•Friends•Python Documentation Site

Page 33: Automating Processes with ArcPy to do work so I don’t have to Joe Guzi GIS Systems Analyst Stark County GIS Department 2015 Ohio GIS Conference September

Questions?

•Joe Guzi• [email protected]•330-451-7188