Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Programming ArcGIS 10.1 with Python Cookbook
  • Table Of Contents Toc
Programming ArcGIS 10.1 with Python Cookbook

Programming ArcGIS 10.1 with Python Cookbook

By : Donald Eric Pimpler, Eric Pimpler
4.2 (13)
close
close
Programming ArcGIS 10.1 with Python Cookbook

Programming ArcGIS 10.1 with Python Cookbook

4.2 (13)
By: Donald Eric Pimpler, Eric Pimpler

Overview of this book

ArcGIS is an industry standard geographic information system from ESRI.This book will show you how to use the Python programming language to create geoprocessing scripts, tools, and shortcuts for the ArcGIS Desktop environment.This book will make you a more effective and efficient GIS professional by showing you how to use the Python programming language with ArcGIS Desktop to automate geoprocessing tasks, manage map documents and layers, find and fix broken data links, edit data in feature classes and tables, and much more."Programming ArcGIS 10.1 with Python Cookbook" starts by covering fundamental Python programming concepts in an ArcGIS Desktop context. Using a how-to instruction style you'll then learn how to use Python to automate common important ArcGIS geoprocessing tasks.In this book you will also cover specific ArcGIS scripting topics which will help save you time and effort when working with ArcGIS. Topics include managing map document files, automating map production and printing, finding and fixing broken data sources, creating custom geoprocessing tools, and working with feature classes and tables, among others.In "Python ArcGIS 10.1 Programming Cookbook" you'll learn how to write geoprocessing scripts using a pragmatic approach designed around an approach of accomplishing specific tasks in a Cookbook style format.
Table of Contents (21 chapters)
close
close
Programming ArcGIS 10.1 with Python Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
3
Index

Running Python scripts from the command line


Up to this point in the book, all your Python scripts have been run as either script tools in ArcGIS or from a Python development environment. The Windows command prompt provides yet another way of executing your Python scripts. The command prompt is used primarily to execute scripts that will be run as a part of a batch file and/or as scheduled tasks.

Getting ready

There are a couple of advantages to running Python geoprocessing scripts from the command prompt. These scripts can be scheduled to batch process your data during off hours for more efficient processing, and they are easier to debug due to the built-in Python error handling and debugging capabilities.

In this recipe, you will learn how to use the Windows command prompt to execute a Python script. You will need administrative rights to complete this recipe, so you may need to contact your information technology support group to make this change.

How to do it…

Follow these steps to learn how to run a script from the Windows command prompt:

  1. In Windows, go to Start | All Programs | Accessories | Command Prompt to display a window similar to the following screenshot:

    The window will display the current directory. Your directory will differ to some degree. Let's change to the directory for this appendix.

  2. Type cd c:\ArcpyBook\Appendix1.

  3. Type dir to see a listing of the files and sub-directories. You should see only a single Python file called ListFields.py:

  4. You will want to make sure that the Python interpreter can be run from anywhere in your directory structure. Go to Start | All Programs | Accessories | System Tools | Control Panel.

  5. Click on System and Security.

  6. Click on System.

  7. Click on Advanced system settings.

  8. In the System Properties dialog box, select the Advanced tab and then the Environment Variables button as shown in the following screenshot:

  9. Find the Path system variable seen in the screenshot below and click on Edit.

  10. Examine the entire text string for the directory c:\Python27\ArcGIS10.1. If the text string isn't found, add it to the end. Make sure that you add a semi-colon before adding the path. Now, when you type python in the command prompt, it will look through each of the directories in the Path system variable, checking for an executable called python.exe.

  11. Click on OK to dismiss the Edit System Variable dialog box.

  12. Click on OK to dismiss the Environment Variables dialog box.

  13. Click on OK to dismiss the System Properties dialog box.

  14. Return to the command prompt.

  15. Type python ListFields.py. This will run the ListFields.py script. After a brief delay, you should see the following output:

How it works…

The ListFields.py script provided for you in this recipe is a simple script that lists the attribute fields for the Burglaries_2009.shp file. The workspace and shapefile name are hardcoded in the script. Typing python followed by the name of the script, which is ListFields.py in this case, triggered the execution of a script using the Python interpreter. As I mentioned, the workspace and shapefile name were hardcoded in this script. In the next recipe, you will learn how to pass in arguments to the script, so that you can remove the hardcoding and make your script more flexible.

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Programming ArcGIS 10.1 with Python Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon