Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Programming ArcGIS 10.1 with Python Cookbook

You're reading from   Programming ArcGIS 10.1 with Python Cookbook This book provides the recipes you need to use Python with AcrGIS for more effective geoprocessing. Shortcuts, scripts, tools, and customizations put you in the driving seat and can dramatically speed up your workflow.

Arrow left icon
Product type Paperback
Published in Feb 2013
Publisher Packt
ISBN-13 9781849694445
Length 304 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Eric Pimpler Eric Pimpler
Author Profile Icon Eric Pimpler
Eric Pimpler
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

Programming ArcGIS 10.1 with Python Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Fundamentals of the Python Language for ArcGIS 2. Writing Basic Geoprocessing Scripts with ArcPy FREE CHAPTER 3. Managing Map Documents and Layers 4. Finding and Fixing Broken Data Links 5. Automating Map Production and Printing 6. Executing Geoprocessing Tools from Scripts 7. Creating Custom Geoprocessing Tools 8. Querying and Selecting Data 9. Using the ArcPy Data Access Module to Select, Insert, and Update Geographic Data and Tables 10. Listing and Describing GIS Data 11. Customizing the ArcGIS Interface with Add-Ins 12. Error Handling and Troubleshooting Automating Python Scripts Five Things Every GIS Programmer Should Know How to Do with Python Index

Scheduling batch files to run at prescribed times


Once created, your batch files can then be scheduled to run at prescribed times using the Windows Scheduler.

Getting ready

Many geoprocessing scripts are time-intensive and best run after hours when they can take full advantage of system resources and free up your time to concentrate on other tasks. In this recipe, you will learn how to use the Windows Scheduler to schedule the execution of your batch files.

How to do it...

Follow these steps to schedule a batch file with the Windows Scheduler:

  1. Open the Windows Scheduler by going to Start | Programs | Accessories | System Tools | Control Panel | Administrative Tools. Select Task Scheduler. The scheduler should appear, as shown in the following screenshot:

  2. Select the Action menu item and then Create Basic Task to display the Create Basic Task Wizard dialog box, as shown in the next screenshot.

  3. Give your task a name. In this case, we will call it List Fields from a Feature Class. Click on Next:

  4. Select a trigger for when the task should be executed. This can, and often will be, a time-based trigger, but there can also be other types of triggers such as a user login or computer start. In this case, let's just select Daily. Click on Next:

  5. Select a start date/time as well as a recurrence interval. In the following screenshot, I have selected the date as 12/3/2012, with time as 1:00:00 AM, and a recurrence interval of 1 day. So, every day at 1:00 AM, this task will be executed. Click on Next:

  6. Select Start a program as the action:

  7. Browse to your script and add the parameters. Click on Next:

  8. Click on Finish to add a task to the scheduler:

  9. The tasks should now be displayed in the list of active tasks:

How it works...

The Windows Task Scheduler keeps track of all the active tasks and handles the execution of these tasks when the prescribed trigger is fired. In this recipe, we have scheduled our task to execute each day at 1:00 AM. At that time, the batch file we created will be triggered and the arguments we specified when creating the task will be passed into the script. Using the scheduler to automatically execute geoprocessing tasks after hours without the need for GIS staff to interact with the scripts gives you more flexibility and increases your efficiency. You might also want to consider logging the errors in your Python scripts to a log file, for more information about specific problems.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image