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
Why Automate processes?
•Not only to do work so I don’t have to•But mainly to Free me up to do more work
Why do more work?
•Because work leads to Taking Over the world!
Automaton Strategies
•Walk through Process•Test•Be prepared•Task Scheduler and BAT Files•Maintenance•Excel Sheet To Maintain Schedule•Code Examples
Automaton Strategies:Walk through process
Automaton Strategies:Walk through process
Automaton Strategies:Walk through process
Automaton Strategies:Test
Automaton Strategies:Test
Automaton Strategies:Test Again
Automaton Strategies:Task Scheduler and BAT Files
Automaton Strategies:Task Scheduler and BAT Files•Bat Files
▫Just Text Files saved with a bat extension▫Written using DOS Commands ▫Syntax
Automaton Strategies:Task Scheduler and BAT Files
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
Excel Sheet to Maintain Schedule
Code Examples
Code Examples:Layer Update Automation
Code Examples:Feature Update Email Notification
Code Examples:Automation of Tax Map Updates
Code Examples:Cache Error Detection
Python Tips and Tricks
•Section your code•Comment Comment Comment•Use Print Command•Error Block•Email Notification•Create Logs•Time•Use Resources
Python Tips and Tricks:Section your code
•Description•Import Section
•Variables•Processes•Output•Error Reporting
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)
Python Tips and Tricks: Comment Comment Comment
Python Tips and Tricks: Use the print Command
Python Tips and Tricks: Error blocks
Python Tips and Tricks: Email Notification
Python Tips and Tricks: Create logs
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 + "' )"
Python Tips and Tricks: Use Resources•Python Window in ArcGIS desktop•ArcGIS Resources Python Section•Geoprocessing Tool References•GitHub•Friends•Python Documentation Site
Questions?
•Joe Guzi• [email protected]•330-451-7188