Programming ArcGIS 10.1 with Python Cookbook


Programming ArcGIS 10.1 with Python Cookbook
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
$22.94
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
$44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • Learn how to create geoprocessing scripts with ArcPy
  • Customize and modify ArcGIS with Python
  • Create time-saving tools and scripts for ArcGIS

Book Details

Language : English
Paperback : 304 pages [ 235mm x 191mm ]
Release Date : February 2013
ISBN : 1849694443
ISBN 13 : 9781849694445
Author(s) : Eric Pimpler
Topics and Technologies : All Books, Other, Cookbooks, Python

Table of Contents

Preface
Chapter 1: Fundamentals of the Python Language for ArcGIS
Chapter 2: Writing Basic Geoprocessing Scripts with ArcPy
Chapter 3: Managing Map Documents and Layers
Chapter 4: Finding and Fixing Broken Data Links
Chapter 5: Automating Map Production and Printing
Chapter 6: Executing Geoprocessing Tools from Scripts
Chapter 7: Creating Custom Geoprocessing Tools
Chapter 8: Querying and Selecting Data
Chapter 9: Using the ArcPy Data Access Module to Select, Insert, and Update Geographic Data and Tables
Chapter 10: Listing and Describing GIS Data
Chapter 11: Customizing the ArcGIS Interface with Add-Ins
Chapter 12: Error Handling and Troubleshooting
Appendix A: Automating Python Scripts
Appendix B: Five Things Every GIS Programmer Should Know How to Do with Python
Index
      • Chapter 3: Managing Map Documents and Layers
        • Introduction
        • Referencing the current map document
        • Referencing map documents on a disk
        • Accessing a data frame
        • Getting a list of layers in a map document
        • Restricting the list of layers
        • Changing the map extent
        • Getting a list of tables
        • Adding layers to a map document
        • Inserting layers into a map document
        • Updating layer symbology
        • Updating layer properties
        • Chapter 4: Finding and Fixing Broken Data Links
          • Introduction
          • Finding broken data sources in your map document and layer files
          • Fixing broken data sources with MapDocument.findAndReplaceWorkspacePaths()
          • Fixing broken data sources with MapDocument.replaceWorkspaces()
          • Fixing individual Layer and Table objects with replaceDataSource()
          • Finding all broken data sources in all map documents in a folder
          • Chapter 5: Automating Map Production and Printing
            • Introduction
            • Creating a list of layout elements
            • Assigning a unique name to layout elements
            • Restricting the layout elements returned by ListLayoutElements()
            • Updating layout element properties
            • Getting a list of available printers
            • Printing maps with PrintMap()
            • Exporting a map to a PDF file
            • Exporting a map to an image file
            • Creating a map book with
            • Chapter 6: Executing Geoprocessing Tools from Scripts
              • Introduction
              • Finding geoprocessing tools
              • Retrieving a toolbox alias
              • Executing geoprocessing tools from a script
              • Using the output of a tool as an input to another tool
              • Setting environment variables and examining tool messages
                • Chapter 8: Querying and Selecting Data
                  • Introduction
                  • Constructing proper attribute query syntax
                  • Creating feature layers and table views
                  • Selecting features and rows with the Select Layer by Attribute tool
                  • Selecting features with the Select by Location tool
                  • Combining a spatial and attribute query with the Select by Location tool
                    • Chapter 10: Listing and Describing GIS Data
                      • Introduction
                      • Getting a list of feature classes in a workspace
                      • Restricting the list of feature classes returned with a wildcard
                      • Restricting the list of feature classes returned with a feature type
                      • Getting a list of fields in a feature class or table
                      • Using the Describe() function to return descriptive information about a feature class
                      • Using the Describe() function to return descriptive information about an image
                      • Returning workspace information with the Describe() function
                        • Chapter 12: Error Handling and Troubleshooting
                          • Introduction
                          • Exploring the default Python error message
                          • Adding Python exception handling structures (try/except/finally)
                          • Retrieving tool messages with GetMessages()
                          • Filtering tool messages by severity level
                          • Testing for and responding to specific error messages
                          • Returning individual messages with GetMessage()
                          • Appendix A: Automating Python Scripts
                            • Introduction
                            • Running Python scripts from the command line
                            • Using sys.argv[ ] to capture command-line input
                            • Adding Python scripts to batch files
                            • Scheduling batch files to run at prescribed times

                              Eric Pimpler

                              Eric Pimpler is the founder and owner of GeoSpatial Training Services (geospatialtraining.com) and has over 20 years of experience in implementing and teaching GIS solutions using Esri, Google Earth/Maps, and open source technology. Currently, he focuses on ArcGIS scripting with Python and the development of custom ArcGIS Server web and mobile applications using JavaScript. He is the author of Programming ArcGIS 10.1 with Python Cookbook. Eric has a bachelor's degree in Geography from Texas A&M University and a master's degree in Applied Geography with a concentration in GIS from Texas State University.

                              Code Downloads

                              Download the code and support files for this book.


                              Submit Errata

                              Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                              Errata

                              - 13 submitted: last submission 30 Jan 2014

                              Errata type: Others | Chapter 4 and Chapter 9 |

                               

                              1. Chapter 4: Fixing broken data sources with MapDocument.replaceWorksapces()
                                 
                                 Step 5: has an extra .mxd
                              
                              2. Chapter 9: Inserting and updating rows inside an edit session
                                 
                                 Step 5: Instead of c:\ArcpyBook\data\CityOfSanAntonio.gdb it should be 
                                 c:\ArcpyBook\data\WildfireData\WildlandFires.mdb.  
                              
                                 Also same change in Step 8 where it defines the entire script.

                               

                               

                              Errata type: Code | Location: Chapter 9 in the “Inserting Rows with InsertCursor” tutorial. | Errata date: 30-4-2013

                               

                              On lines 13 and 18 where it says –
                              
                               
                              
                              with da.InsertCursor(“FireIncidents”,(“SHAPE@XY”,”CONFIDENCEVALUE”)) as cur:
                              
                               
                              
                              This code would not run as written within Idle. The following line of code gets the script to work.
                              
                               
                              
                              with arcpy.da.InsertCursor(“FireIncidents”,(“SHAPE@XY”,”CONFIDENCEVALUE”)) as cur:
                              
                               
                              
                              

                               

                               

                              Errata type: Others | Page number: 13 | Errata date: 18 Dec 08

                               

                              Chapter 4: example "Finding all broken data sources in all map documents in a folder"
                              
                              Step 9: 
                              First error:
                              -------------------------------------------------------------------------------------
                              If a whole drive has to be searched, the path must be assigned as follows:
                              path = "C:\\"
                              
                              In the book the following expression is used:
                              Path = r"C:"
                              
                              If that statement is used, only the first subdirectory on the drive is searched 
                              
                              If another subdirectory should be searched, the path can be assigned with r
                              e.g. path = r"C:\ESRIPress"
                              ------------------------------------------------------------------------------------------
                              
                              Step 9:
                              Second error:
                              Assignment of fullPath is wrong
                              
                              fullPath = os.path.join(root,filename)
                              
                              instead of expression in book:
                              fullPath = os.path.join(path,filename)
                              
                              If subdirectories exist, to the attribute path only the head for beginning the search is assigned
                              Only the attribute root contains the whole path down to the leaf.
                              ____________________________________________________________________
                              
                              One more suggestion:
                              In the f.write-Statement also the attribute root should be written too, so that one can see immediately 
                              Where the .mxd was found, otherwise the user has to search all subdirectories again for the path of the .mxd's
                              
                              # write the path name for the .mxd, it is the path of a subtree			
                              # write the map document name
                              f.write("Path: " + root + "      MXD: " + filename + "\n")
                              
                              In Chapter 5, example
                              
                              „Restricting the layout elements returned by ListLayoutElements()
                              
                              In Step 5 the colon is missing at the end of the for-statement
                              
                              In Chap 5
                              
                              Example „Exporting a map to an image file
                              
                              Step 7
                              
                              Mapping.ExportToPDF                 is wrong there
                              
                              Should be: Mapping.ExportToJPEG

                               

                               

                              Errata type: Code| Chapter number: 4 | Errata date: 10-6-2013

                               

                              Chapter 4: Fixing broken data sources with MapDocument.replaceWorksapces()
                              
                                
                              
                                 Step 5: has an extra .mxd
                              
                              ----------------------------------------------------------------
                              
                              Besides that error the .mxd of the example is false: it should be
                              
                              “DataLinksLayer.mxd”
                              
                              Instead of
                              
                              “BrokenDataLinks.mxd”
                              
                               
                              
                              Because the .gdb-file path given in Step 8 is not the path which includes “OldData” in it and in the “BrokenDataLinks.mxd” the broken path contains “OldData” as part of the path string.

                               

                               

                              Errata type: Code| Chapter 7, 1. Example | Errata date: 18 June 2013

                               

                              In the script InsertWildFires.py
                              
                               
                              
                              The path-notations are wrong:
                              
                              arcpy.env.workspace = "C:/ArcpyBook/Ch7data/Wildfires/WildlandFires.mdb"
                              
                                  f = open("C:/ArcpyBook/Ch7data/Wildfires/NorthAmericaWildfires_2007275.txt","r")
                              
                               
                              
                              should be without “Ch7data” , stead only “data” :
                              
                               
                              
                              arcpy.env.workspace = "C:/ArcpyBook/data/Wildfires/WildlandFires.mdb"
                              
                                  f = open("C:/ArcpyBook/data/Wildfires/NorthAmericaWildfires_2007275.txt","r")
                              
                               
                              
                              The paths are wrong for the hardcoded version and in comparison to the text in Step 6 of the example, but the hardcoded paths are then deleted in Step 7, so it does not really matter.
                              
                               
                              
                              In Step 8 there is a more severe error:
                              
                              One brace is placed wrong:
                              
                              …split(outputFC[1])
                              
                               
                              
                              Should be:
                              
                              …split(outputFC) [1]

                               

                               

                              Errata type: Others | CHapter 5 | Errata date: 14-6-2013

                               

                              “Creating a map book with …”
                              
                              In Step 5, a file is used that is named “Map_DataFrameCrime.pdf”
                              
                               This file was produced in an example earlier named “Exporting a map to a PDF File”.
                              
                              But in that example the name is different, there it is only “DataFrameCrime.pdf” in Step 8.
                              
                              It would be best to change the name in this example, because in the next one it used two times with the name
                              
                              “Map_DataFrameCrime.pdf”
                              
                               
                              
                              If one runs  the later script without changing names, the script shows an error and does not run successfully.

                               

                               

                              Errata type: Others | Chapter 6 | Errata date: 17-6-2013

                               

                              in Chapter 6, example “Setting environment variables …”
                              
                              in Step 4:
                              
                              one quotation mark (a double quote)  is at the wrong place
                              
                              arcpy.Buffer_analysis("Streams.shp", "Streams_Buff, '200 Feet'”)
                              
                               
                              
                              instead of how it should be:
                              
                              arcpy.Buffer_analysis("Streams.shp", "Streams_Buff", '200 Feet')

                               

                               

                              Errata type: Code | Chapter number: 9 | Errata date: 21-6-2013

                               

                              In Chap. 9 example „Updating rows …“
                              
                               
                              
                              The indentation in step 9 for the print-Statement is wrong. It must be on the same line as the else-Statement, otherwise it is only performed once and the cntr is only incremented once.

                               

                               

                              Errata type: Code| Chapter number: 9 | Errata date: 21-6-2013

                               

                              in the Example „Inserting rows with InsertCursor“ there is one more error:
                              
                              after the assignment of
                              
                              rowValues = …
                              
                              fc = …
                              
                              in the next statement
                              
                              fields …
                              
                              the “=” is missing
                              
                              It should be
                              
                              Fields = …

                               

                               

                              Errata type: Others| Chapter number: 5 | Page number: 106 | Errata date: 15-7-2013

                               

                              In Step 7 it should be "ExportToJPEG" instead of "ExportToPDF"

                              Errata type: Code| Chapter number: 9 | Page number: 178 | Errata date: 15-7-2013

                               

                              In Step 18 there is a line that states:
                              with da.InsertCursor("FireIncidents", ("SHAPE@
                              replace it by:
                              with arcpy.da.InsertCursor("FireIncidents", ("SHAPE@

                              Errata type: Code| Chapter number: 7 | Page number: 129 | Errata date: 15-7-2013

                              In Step 8 there is a line that states:
                              os.path.split(outputFC[1]), "point", fClassTemplate)
                              Replace it by:
                              os.path.split(outputFC)[1], "point", fClassTemplate)

                              Errata type: Code| Chapter number: 10 | Page number: 199 | Errata date: 30-01-2014

                              In step 7, code block, except Exception e:

                              Replace it by:

                              except Exception as e:

                              Sample chapters

                              You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                              Frequently bought together

                              Programming ArcGIS 10.1 with Python Cookbook +    Python Geospatial Development - Second Edition =
                              50% Off
                              the second eBook
                              Price for both: $38.15

                              Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                              What you will learn from this book

                              • 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

                              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.

                              Approach

                              This book is written in a helpful, practical style with numerous hands-on recipes and chapters to help you save time and effort by using Python to power ArcGIS to create shortcuts, scripts, tools, and customizations.

                              Who this book is 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(?).

                              Code Download and Errata
                              Packt Anytime, Anywhere
                              Register Books
                              Print Upgrades
                              eBook Downloads
                              Video Support
                              Contact Us
                              Awards Voting Nominations Previous Winners
                              Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                              Resources
                              Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software