Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (13 Ratings)
Paperback Feb 2013 304 pages 1st Edition
eBook
€19.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
€18.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2 (13 Ratings)
Paperback Feb 2013 304 pages 1st Edition
eBook
€19.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€19.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849694445
Vendor :
ESRI
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Feb 22, 2013
Length: 304 pages
Edition : 1st
Language : English
ISBN-13 : 9781849694445
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
Learning Geospatial Analysis with Python
€41.99
Python Geospatial Development - Second Edition
€41.99
Programming ArcGIS 10.1 with Python Cookbook
€37.99
Total 121.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.