Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Donald Eric Pimpler, Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Donald Eric Pimpler, Eric Pimpler

Overview of this book

Table of Contents (22 chapters)
Programming ArcGIS with Python Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Deleting rows with UpdateCursor


In addition to being used to edit rows in a table or feature class, UpdateCursor can also be used to delete rows. Keep in mind that when rows are deleted outside an edit session, the changes are permanent.

Getting ready

In addition to updating records, UpdateCursor can also delete records from a table or feature class. The UpdateCursor object is created in the same way in either case, but instead of calling updateRow(), you call deleteRow() to delete a record. You can also apply a where clause to UpdateCursor, to limit the records returned. In this recipe, we'll use an UpdateCursor object that has been filtered using a where clause to delete records from our FireIncidents feature class.

How to do it…

Follow these steps to create an UpdateCursor object that will be used to delete rows from a feature class:

  1. Open IDLE and create a new script.

  2. Save the script to C:\ArcpyBook\Ch8\DeleteWildfires.py.

  3. Import the arcpy and os modules:

    import arcpy
    import os
  4. Set the workspace...