Programming ArcGIS 10.1 with Python Cookbook

Book description

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.

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

In Detail

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

  1. Programming ArcGIS 10.1 with Python Cookbook
    1. Table of Contents
    2. Programming ArcGIS 10.1 with Python Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Fundamentals of the Python Language for ArcGIS
      1. Using IDLE for Python script development
        1. The Python shell window
        2. The Python script window
        3. Editing existing Python scripts
        4. Executing scripts from IDLE
      2. Python language fundamentals
        1. Commenting code
        2. Importing modules
        3. Variables
        4. Built-in datatypes
          1. Strings
            1. String manipulation
          2. Numbers
          3. Lists
          4. Tuples
          5. Dictionaries
        5. Classes and objects
        6. Statements
          1. Decision support statements
          2. Looping statements
          3. Try statements
          4. with statements
        7. File I/O
      3. Summary
    9. 2. Writing Basic Geoprocessing Scripts with ArcPy
      1. Introduction
      2. Using the ArcGIS Python window
        1. Getting ready
        2. How to do it…
      3. Accessing ArcPy with Python
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Executing tools from a script
        1. How to do it…
        2. How it works…
        3. There's more…
      5. Using ArcGIS Desktop help
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Using variables to store data
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Accessing ArcPy modules with Python
        1. Getting ready
        2. How to do it…
        3. How it works…
    10. 3. Managing Map Documents and Layers
      1. Introduction
      2. Referencing the current map document
        1. Getting ready
        2. How to do it…
        3. How it works
      3. Referencing map documents on a disk
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Accessing a data frame
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Getting a list of layers in a map document
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Restricting the list of layers
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Changing the map extent
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Getting a list of tables
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Adding layers to a map document
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      10. Inserting layers into a map document
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      11. Updating layer symbology
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      12. Updating layer properties
        1. Getting ready
        2. How to do it…
    11. 4. Finding and Fixing Broken Data Links
      1. Introduction
      2. Finding broken data sources in your map document and layer files
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Fixing broken data sources with MapDocument.findAndReplaceWorkspacePaths()
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Fixing broken data sources with MapDocument.replaceWorkspaces()
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Fixing individual Layer and Table objects with replaceDataSource()
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Finding all broken data sources in all map documents in a folder
        1. Getting ready
        2. How to do it...
        3. How it works...
    12. 5. Automating Map Production and Printing
      1. Introduction
      2. Creating a list of layout elements
        1. Getting ready...
        2. How to do it…
        3. How it works…
      3. Assigning a unique name to layout elements
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Restricting the layout elements returned by ListLayoutElements()
        1. Getting ready
        2. How to do it…
        3. How it works...
      5. Updating layout element properties
        1. Getting ready
        2. How to do it…
        3. How it works...
      6. Getting a list of available printers
        1. Getting ready
        2. How to do it…
        3. How it works...
      7. Printing maps with PrintMap()
        1. Getting ready
        2. How to do it…
        3. How it works...
      8. Exporting a map to a PDF file
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Exporting a map to an image file
        1. Getting ready
        2. How to do it…
        3. How it works…
      10. Creating a map book with PDFDocumentCreate() and PDFDocumentOpen()
        1. Getting ready
        2. How to do it…
        3. How it works...
        4. There's more…
    13. 6. Executing Geoprocessing Tools from Scripts
      1. Introduction
      2. Finding geoprocessing tools
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Retrieving a toolbox alias
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Executing geoprocessing tools from a script
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      5. Using the output of a tool as an input to another tool
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Setting environment variables and examining tool messages
        1. Getting ready
        2. How to do it…
        3. How it works…
    14. 7. Creating Custom Geoprocessing Tools
      1. Introduction
      2. Creating a custom geoprocessing tool
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
    15. 8. Querying and Selecting Data
      1. Introduction
      2. Constructing proper attribute query syntax
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating feature layers and table views
        1. Getting ready
        2. How to do it…
        3. How it works...
        4. There's more...
      4. Selecting features and rows with the Select Layer by Attribute tool
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Selecting features with the Select by Location tool
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Combining a spatial and attribute query with the Select by Location tool
        1. Getting ready
        2. How to do it...
        3. How it works...
    16. 9. Using the ArcPy Data Access Module to Select, Insert, and Update Geographic Data and Tables
      1. Introduction
      2. Retrieving features from a feature class with a SearchCursor
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Filtering records with a where clause
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Improving cursor performance with geometry tokens
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Inserting rows with InsertCursor
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Updating rows with an UpdateCursor
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Deleting rows with an UpdateCursor
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Inserting and updating rows inside an edit session
        1. Getting ready
        2. How to do it…
        3. How it works…
      9. Reading geometry from a feature class
        1. Getting ready
        2. How to do it…
        3. How it works…
    17. 10. Listing and Describing GIS Data
      1. Introduction
      2. Getting a list of feature classes in a workspace
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      3. Restricting the list of feature classes returned with a wildcard
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Restricting the list of feature classes returned with a feature type.
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      5. Getting a list of fields in a feature class or table
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Using the Describe() function to return descriptive information about a feature class
        1. Getting ready
        2. How to do it…
        3. How it works…
      7. Using the Describe() function to return descriptive information about an image
        1. Getting ready
        2. How to do it…
        3. How it works…
      8. Returning workspace information with the Describe() function
        1. Getting ready
        2. How to do it…
        3. How it works…
    18. 11. Customizing the ArcGIS Interface with Add-Ins
      1. Introduction
      2. Downloading and installing the Python Add-In wizard
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Creating a button add-in
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Installing and testing an add-in
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Creating a tool add-in
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more…
    19. 12. Error Handling and Troubleshooting
      1. Introduction
      2. Exploring the default Python error message
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Adding Python exception handling structures (try/except/finally)
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      4. Retrieving tool messages with GetMessages()
        1. Getting ready
        2. How to do it…
        3. How it works…
      5. Filtering tool messages by severity level
        1. Getting ready
        2. How to do it…
        3. How it works…
      6. Testing for and responding to specific error messages
        1. Getting ready…
        2. How to do it…
        3. How it works…
      7. Returning individual messages with GetMessage()
        1. Getting ready
        2. How to do it...
        3. How it works...
    20. A. Automating Python Scripts
      1. Introduction
      2. Running Python scripts from the command line
        1. Getting ready
        2. How to do it…
        3. How it works…
      3. Using sys.argv[ ] to capture command-line input
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Adding Python scripts to batch files
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      5. Scheduling batch files to run at prescribed times
        1. Getting ready
        2. How to do it...
        3. How it works...
    21. B. Five Things Every GIS Programmer Should Know How to Do with Python
      1. Introduction
      2. Reading data from a delimited text file
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more...
      3. Sending e-mails
        1. Getting ready
        2. How to do it…
        3. How it works…
      4. Retrieving files from an FTP server
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      5. Creating ZIP files
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
      6. Reading XML files
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
    22. Index

Product information

  • Title: Programming ArcGIS 10.1 with Python Cookbook
  • Author(s): Eric Pimpler
  • Release date: February 2013
  • Publisher(s): Packt Publishing
  • ISBN: 9781849694445