New Year, New Skills, More Python!

When it comes to Python, there are a multitude of ways that you can use it to make your workflows more efficient. From customizing models to automating processing to ArcGIS Notebooks; you can do it all with Python!

Still finding your bearings with Python? Not quite ready to tackle use cases? Check out our article on learning Python, Scripting With Snakes: A Beginner’s Guide to Python, before continuing on!

Customizing Models

Have workflows that you are constantly repeating or are time intensive? ModelBuilder is your place to start and creating custom tools is a great place to start with Python.

  • Start by choosing a workflow that doesn’t require user input each time and build out the model for it.
  • Once you have it built out, run it as a whole and as parts to verify that you are getting the expected outcome at each step.  This will allow you to better troubleshoot later in your script if things fail.
A model creating a TIN, converting to a raster, and further analysis.
  • Now is the time to export the model to Python, here is the documentation for ArcGIS Pro and ArcMap.
  • Take some time and explore what the script looks like, walk yourself through it step by step to understand how things are put together. You can compare it back to your model to understand the progression of things.
Python snippet for creating a TIN with specific parameters.
  • Now is the time to start customizing! Add in print statements after each task to verify that each part is complete or add in statements to write to a log file. This will allow you to better trouble shoot if something fails in the process.

Automating the Process

Now that you’ve got your workflow into a model and back out to a Python script, try scheduling it! Using Windows Task Scheduler you can set your scripts to run after hours, on the weekend, or over your lunch break. This is a great option for daily, weekly, or monthly tasks; saving you time to work on other tasks that can;t run themselves.

The following steps correspond to the images in the above gallery. Together they will walk you through setting up a scheduled task for your python script.

  1. Create Task, here is where you choose the user to run the task (by default, the user setting up the task).
    • If running the task outside of office hours, choose ‘run whether user is logged on or not’.
    • Then set the ‘configure for’ section to choose the version of windows you are running on.
  2. Trigger, choose when you want the task to run and how often you want it to run.
  3. New Action, here is where you will fill in the path for the Python application and your script.
  4. New Action, now you are all set to hit the ‘ok’ button and let it run at the scheduled time.
    • You may be prompted to put in your password if you chose to run the task after hours and the setting to ‘run whether user is logged on or not’.

Want a more in-depth walk through of the process? Esri has a great walk through on the process on scheduling a model or script!

Resources

When learning Python there are many paths you can take on the road to becoming a Python master. There is no wrong way to learn Python if you start with the basics and move at your own pace. 

What are you using Python for? Reach out to us on Twitter and let us know!

Looking to learn something else? Check out these articles!

Solution Engineer

Michelle is a passionate and self-starting GIS professional looking to change the world with mapping. She works with our Enterprise team, supporting the daily operations of our GEOPowered Cloud.