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
Programming ArcGIS 10.1 with Python Cookbook
Programming ArcGIS 10.1 with Python Cookbook

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
Profile Icon Donald Eric Pimpler Profile Icon Eric Pimpler
Arrow right icon
€8.99 €28.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (13 Ratings)
eBook Feb 2013 304 pages 1st Edition
eBook
€8.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Donald Eric Pimpler Profile Icon Eric Pimpler
Arrow right icon
€8.99 €28.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (13 Ratings)
eBook Feb 2013 304 pages 1st Edition
eBook
€8.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Programming ArcGIS 10.1 with Python Cookbook

Chapter 2. Writing Basic Geoprocessing Scripts with ArcPy

In this chapter, we will cover the following recipes:

  • Using the ArcGIS Python window

  • Accessing ArcPy with Python

  • Executing tools from a script

  • Using ArcGIS Desktop help

  • Using variables to store data

  • Accessing ArcPy modules with Python

Introduction


Geoprocessing tasks tend to be time consuming and repetitive, and often need to be run on a periodic basis. Frequently, many data layers and functions are involved. The ArcPy Python site package for ArcGIS provides a set of tools and execution environments that can be used to transform your data into meaningful results. Using scripts you can automate your geoprocessing tasks and schedule them to run when it is most convenient for your organization.

ArcGIS provides a geoprocessing framework for the purpose of automating your repetitive GIS tasks through a set of tools and execution environments for these tools. All tools operate on an input dataset, which you supply and transform in some way (depending upon the nature of the tool used) to produce a new output dataset. This new output dataset can then, if necessary, be used as the input dataset to additional geoprocessing tools in a larger workflow for your tasks. There are many tools provided by the ArcGIS geoprocessing framework...

Using the ArcGIS Python window


In this recipe, you'll learn how to use the ArcGIS Python window. In Chapter 1, Fundamentals of the Python Language for ArcGIS, you learned how to use the IDLE development environment for Python, so this chapter will give you an alternative for writing your geoprocessing scripts. Either development environment can be used but it is common for people to start writing scripts with the ArcGIS Desktop Python window and then move on to IDLE when scripts become more complex. I should also mention that there are many other development environments that you may want to consider, including PythonWin, Wingware, Komodo, and others. The development environment you choose is really a matter of preference.

Getting ready

The new Python window is an embedded, interactive Python window in ArcGIS Desktop 10, that is ideal for testing small blocks of code, learning Python basics, building quick and easy workflows, and executing geoprocessing tools. However, as your scripts become...

Accessing ArcPy with Python


Before you can take advantage of all the geoprocessing functionality provided by ArcPy, you must first import the package into your script. This will always be the first line of code in every geoprocessing script that you write.

Getting ready

ArcPy is a Python site package that is part of the ArcGIS 10 release, and fully encompasses the functionality provided with the arcgis scripting module at ArcGIS 9.2, which further enhances its capabilities. With ArcPy you have access to the geoprocessing tools, extensions, functions, and classes for working with ESRI GIS data. ArcPy provides code-completion and integrated documentation for the modules, classes, and functions. ArcPy can also be integrated with other Python modules to widen the scope of its capabilities. All ArcGIS geoprocessing scripts that you write with Python must first provide a reference to ArcPy.

How to do it…

Follow these steps to import the arcpy site package into the ArcGIS Python window:

  1. Open the c...

Executing tools from a script


As an ArcGIS user, you have almost certainly used the many available tools in ArcToolbox to accomplish your geoprocessing tasks. Some examples include Clip, Buffer, Feature Class to Feature Class, Add Field, and many more. Your scripts can execute any of the tools found in ArcToolbox. Remember that the tools available to you as a programmer are dependent upon the license level of ArcGIS Destkop that you are using. These tasks can be automated through the creation of a Python script that executes these tools programmatically.

How to do it…

  1. Follow these steps to learn how to execute a geoprocessing tool from your script. Open c:\ArcpyBook\Ch2\TravisCounty.mxd with ArcMap.

  2. Open the Python window.

  3. Import the arcpy package:

    import arcpy
  4. Set the workspace. We haven't discussed the env class yet. Environment settings for ArcGIS are exposed as properties of this env class, which is a part of arcpy. One of the properties of the env class is workspace, which defines the current...

Using ArcGIS Desktop help


The ArcGIS Desktop help system is an excellent resource for obtaining information about any available tool. Each tool is described in detail on a unique page. The help system is available through ArcGIS Desktop or online.

Getting ready

In addition to containing basic descriptive information about each tool, the help system also includes information of interest to Python programmers, including syntax and code examples that provide detailed information about how the tool can be used in your scripts. In this recipe, you will learn how to access the ArcGIS Desktop help system to obtain syntax information and code examples.

How to do it...

Follow these steps to learn how to use the ArcGIS Desktop help system to access syntax information about a tool as well as a code example showing how the tool is used in a script.

  1. If necessary, open ArcMap and select Help | ArcGIS Desktop Help from the main menu.

  2. Select the Contents tab.

  3. Select Geoprocessing | Tool reference. The tools are...

Using variables to store data


In Chapter 1, Fundamentals of the Python Language for ArcGIS, we covered the topic of variables, so you should have a basic understanding of these structures. Variables are given a name and assigned a data value in your scripts. These named variables occupy space in your computer's memory and the data contained within these structures can change while a script is running. After the script has finished the memory space occupied by these variables is then released and can be used for other operations.

Getting ready

When writing geoprocessing scripts with Python there will be many times when you will need to create variables to hold data of one type or another. This data can then be used in your script as input parameters for tools and functions, as intermediate data for internal processing, to hold paths to datasets, and for other reasons. In addition, many of the ArcPy functions and tools also return data that can be stored in a variable for further use in your...

Accessing ArcPy modules with Python


Up to this point, we have covered some basic concepts related to ArcPy. In addition to the basic ArcPy site package, there are a number of modules that you can use to access specific functionality. These modules must be specifically imported into your scripts before you can use the functionality provided. In this recipe, you will learn how to import these modules.

Getting ready

In addition to providing access to tools, functions, and classes, ArcPy also provides several modules. Modules are purpose-specific Python libraries containing functions and classes. The modules include a Mapping module (arcpy.mapping), a Data Access module (arcpy.da), a Spatial Analyst module (arcpy.sa), a Geostatistical module (arcpy.ga), a Network Analyst module (arcpy.na), and a Time module (arcpy.time). To use the functions and classes included with each of these modules you must specifically import their associated libraries.

How to do it…

Follow these steps to learn how...

Left arrow icon Right arrow icon

Key benefits

  • Learn how to create geoprocessing scripts with ArcPy
  • Customize and modify ArcGIS with Python
  • Create time-saving tools and scripts for ArcGIS

Description

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.

Who is this book for?

"Programming ArcGIS 10.1 with Python Cookbook" is written for GIS professionals who wish to revolutionize their ArcGIS workflow with Python. Basic Python or programming knowledge is essential(?).

What you will learn

  • Fundamental Python programming skills
  • Update layer properties and symbology
  • Automate map production, printing, and the creation of PDF map books
  • Find and fix broken data links in your map document files
  • Create custom geoprocessing tools that can be shared with others
  • Schedule your geoprocessing scripts to run after hours
  • Create new feature classes or tables and add records, as well as edit feature classes and tables
  • Customize the ArcGIS Desktop interface with Python add-ons

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 22, 2013
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781849694452
Vendor :
ESRI
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 22, 2013
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781849694452
Vendor :
ESRI
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 121.97
Programming ArcGIS 10.1 with Python Cookbook
€37.99
Python Geospatial Development - Second Edition
€41.99
Learning Geospatial Analysis with Python
€41.99
Total 121.97 Stars icon
Banner background image

Table of Contents

12 Chapters
Fundamentals of the Python Language for ArcGIS Chevron down icon Chevron up icon
Writing Basic Geoprocessing Scripts with ArcPy Chevron down icon Chevron up icon
Managing Map Documents and Layers Chevron down icon Chevron up icon
Finding and Fixing Broken Data Links Chevron down icon Chevron up icon
Automating Map Production and Printing Chevron down icon Chevron up icon
Executing Geoprocessing Tools from Scripts Chevron down icon Chevron up icon
Creating Custom Geoprocessing Tools Chevron down icon Chevron up icon
Querying and Selecting Data Chevron down icon Chevron up icon
Using the ArcPy Data Access Module to Select, Insert, and Update Geographic Data and Tables Chevron down icon Chevron up icon
Listing and Describing GIS Data Chevron down icon Chevron up icon
Customizing the ArcGIS Interface with Add-Ins Chevron down icon Chevron up icon
Error Handling and Troubleshooting Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(13 Ratings)
5 star 61.5%
4 star 23.1%
3 star 0%
2 star 7.7%
1 star 7.7%
Filter icon Filter
Top Reviews

Filter reviews by




Doina Brownell Oct 04, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very good book for Python programmers, with a lot of "cookbook" recipes to use. This book corroborated with the ArcGIS Resource Center online helped me relearn and create a script for automating a county parcel layer. Good job, Eric!
Amazon Verified review Amazon
Nicholas Trichel Mar 18, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Pros: Excellent BookCons: Had to convert MXD's to 10.0 compatible version because they are meant for 10.1. Other than that. No concerns!
Amazon Verified review Amazon
Vedette Bianciotti Mar 30, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I brought a copy of this book for a friend of mine who is studying GIS and in particular ArcGIS and so far they have absolutely loved it!They have decent understanding of ArcGIS and python but they are no master and wanted help combining the two things together. Not being an expert in the two subjects myself I thought that this book might hit the spot (being practical!).So far it has totally lived up to its promise of being practical.The chapters are thus:PrefaceChapter 1: Fundamentals of the Python Language for ArcGISChapter 2: Writing Basic Geoprocessing Scripts with ArcPyChapter 3: Managing Map Documents and LayersChapter 4: Finding and Fixing Broken Data LinksChapter 5: Automating Map Production and PrintingChapter 6: Executing Geoprocessing Tools from ScriptsChapter 7: Creating Custom Geoprocessing ToolsChapter 8: Querying and Selecting DataChapter 9: Using the ArcPy Data Access Module to Select, Insert, and Update Geographic Data and TablesChapter 10: Listing and Describing GIS DataChapter 11: Customizing the ArcGIS Interface with Add-InsChapter 12: Error Handling and TroubleshootingAppendix A: Automating Python ScriptsAppendix B: Five Things Every GIS Programmer Should Know How to Do with PythonAccording to my friend this book covers all of the basics of day-to-day ArcGIS processes so is perfect if you want to speed up things that take hours previously and automate simple but annoying tasks like creating maps and general geoprocessing tasks.This book isn't a "Mastering" book but like every cookbook it is practical and will get you improving real-world issues in no time. My friend absolutely loves it as a reference guide to getting things done and I don't think you can ask much more than that.
Amazon Verified review Amazon
Susan Nash Apr 10, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I agree that the "cookbook" part of the title is a bit of a misnomer. However, it does include very helpful scripts which take advantage of ArcGIS 10 features.What I find most useful is the fact that the organization of the book takes a building block approach which is helpful for someone who may need to get started, and equally so for someone who would like to simply pinpoint and extract what they want and need.Here are some of the useful features:* automated map production and printing: can automate the production of map production and printing (including exporting PDFs), which is helpful when creating a set of maps or map files.* quickly using geoprocessing tools: this is a quick way to increase functionality and power without having to do everything separately; application-level environment settings are utilized quite helpfully as well.* creating custom tools: the example shows how to filter the data for North American wildfires -- it's a useful example; I think it might be even more helpful to list some of the common sources of data and practice importing them and working with them by developing additional custom tools.* working with attribute and spatial queries: I think it would have been good to go into a bit more detail about how / why syntax decisions are made, and to discuss the logic, the flow, and the structure; after all, mind and the mental processes are where clean code begins and ends. That said, the section discusses how Python interprets the queries and how / when it matters where a string is placed. The examples are clear, but I always need lots of examples, so I would have welcomed even more examples, but that would perhaps confuse some users, so I concluded that the book hit the right balance.* for the more adventurous, the book includes how to use the add-in wizard. I have always been a bit leery of add-ins, believing (perhaps superstitiously) that they will create conflicts, and unleash a small troop of gremlins. This chapter shows how / where to place an add-in in a folder that is easily discoverable by ArcGIS Desktop. This is probably the key to having the thing work, and it solves a small mystery of why add-ins sometimes do not work.In sum, I'd like to say that I find the book to be very clear, well-organized, and helpful. It's likely to have a nice, long shelf life as well.
Amazon Verified review Amazon
John Williams Mar 13, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I thought this was a very well written introduction to the topic of programming ArcGIS with Python. As a beginner to the subject I felt that it gave me the tools that I need to start writing my own scripts to automate geoprocessing tasks in ArcGIS. The topic of cursors (Chapter 9) was particularly good for me since we have a lot of geoprocessing workflows that edit or add records to feature classes and tables.I enjoyed it very much and cannot wait to start putting these new tools to work.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.