1 / 17

Presenter: Phil Baranyai Crawford County GIS Manager

Automating workflows with the sweet arcpy module and python - or - How I learned to love python in GIS. Presenter: Phil Baranyai Crawford County GIS Manager. What to do? With the jobs/requests piling up, and the team of staff members consisting of just myself. I had to AUTOMATE!.

abelk
Download Presentation

Presenter: Phil Baranyai Crawford County GIS Manager

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Automating workflows with the sweet arcpy module and python- or -How I learned to love python in GIS Presenter: Phil Baranyai Crawford County GIS Manager

  2. What to do? With the jobs/requests piling up, and the team of staff members consisting of just myself. I had to AUTOMATE! Help wanted! Too many duties for 1 person @ 40/hr week. Connected services require maintenance windows and/or after hours updates. No money for additional staff.

  3. What is ArcPy? ArcPy is module (add-on) to python, it gives python access to all of the ArcGIS geoprocessing tools. What is python? Simply put, python is a basic programming language. Python is heavily used in the background processing of ArcGIS already. Python is a decision engine that uses tools to manipulate data.

  4. Model builder is great for learning automation, however it does have limitations. Can’t manipulate maps (mass changes across MXD) It can iterate loops, however python is more efficient (faster) Updates (data source changes) are harder in model builder Can’t automate model builder (without converting it to/using python) Doesn’t have as many tools available as native python, just works with ArcGIS tools Python is too hard, model builder is easier!

  5. Beginning python? You can start in model builder! Model builder is what is considered a GUI (graphical user interface), it’s got shapes and colors to visualize the workflow. Python is a programing language so it’s more “lines of code” However, when you export it from model builder, you’ll be able to see things you recognize (tools, variables, etc.)

  6. Once you start writing code, it’s common to “borrow” code from one script to another.  Logging (optional)  Modules  Variables (optional) Python begins with simple structure Open up a notepad (.txt), add these sections save as to file.py (now you have the beginning of a python script)

  7. Decide what your script will do! Any repetitive tasks are ideal to automate. First run the tool in ArcCatalog, the open the results window, and copy the tool results to a python snippet. This will carry any input/output/variables that you used to run the tool in ArcCatalog.

  8. Paste the python snippet into your script, adjust with variables to clean up the script (and make adjustments easier in the future) Using Try/Except blocks allows for handling of exceptions (flow control). It’s a simple logic that allows the program to react based off how the try portion ran. In this example, if this step fails, it will simply write an error out about the failure and then stop the program (as to not hold resources) Other examples could be: if this failed, attempt another tool, or if this works, then run another tool (doesn’t always have to be failures)

  9. In python, cursors don’t blink, but they do speed things up for iteration! If you need to sort through your data and update/insert/delete rows or simply search and report on certain data. Cursors are your answer! They quickly read the rows of your data based on logic you provide to do the work you need!

  10. ESRI’s web help has syntax and code samples for every tool in the ArcToolbox. GeoNet is another big help, odds are, someone else has tried what you’re looking to do (or a variation).

  11. Harness the power of native python! When your python skills start to improve, you can make other tweaks, such as tapping into python (without ArcPy). This is an example of finish work after a tool has run.

  12. Run your scripts on a scheduled task Once you’ve created python scripts, they don’t just run themselves. A simple batch file allows you to stack scripts to run in sequence. Convenient: batch log is a collection of individual logs all in one location.

  13. Run your scripts on a scheduled task Schedule the task in Windows task scheduler. Pick a convenient date, time, frequency. Add your batch file (or python script) to the task Breathe a sigh of relief as your tools are now working automatically.

  14. Do you even automate, bro? Weekly maintenance ETL (workspace – internal – web – open data) Parcel creation Creation from features Update from CAMA software Locator rebuilder Rebuild Republish (overwrite existing) SDE maintenance Versioned editing Compress Rebuild/Analyze Public Safety data conversion for CAD (Computer Aided Dispatch) Data loaded to remote (regional) CAD server Custom reports (to excel) from Survey 123 results Custom report (to excel) for Assessment (vendor couldn’t provide) Tax Claim data creation/updates

  15. Weekly maintenance data loaders (workspace – internal – web – open data) Avg task time (25-30 mins – automated // 2 hrs manual) Weekly Parcel creation Avg task time (2.5 hrs – automated // 6 hr manual) Weekly Locator rebuilder Avg task time (1 hr – automated // 3 hrs manual) Weekly SDE maintenance Avg task time (1.5 hrs – automated // 4.5 hr manual) Fortnightly Public Safety data conversion for CAD (Computer Aided Dispatch) Avg task time (6 mins – automated // 45 mins manual) Seems like a lot of work – is it worth it? Consider the amount of time saved per task, multiplied by the frequency of runs in a year.

  16. Python software – makes it easier! There is some software out there that will help you code, it can show you syntax errors, test code blocks for you, and generally help step you through the basics. First is ArcGIS, they have a python window, and when you install ArcGIS desktop software, you automatically get a copy of python and IDLE. IDLE will check for syntax errors and color code to help walk you along. Another free software is PyScripter, much like IDLE it can check for syntax errors and color code, but it also will help you by proposing complete syntax (closing quotes, brackets, etc.) Notepad ++ is similar to IDLE’s features Spyder also is like PyScripter offering assistance in coding and library references from the software There are many out there, just search for free python code editors or free python IDEs on the internet.

  17. Any questions? Presenter: Phil Baranyai Crawford County GIS Manager

More Related