Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Eric Pimpler

Overview of this book

The book kicks off with the fundamentals of starting to use Python with ArcGIS, followed by recipes on managing map documents and layers, including how to find and fix broken data links in these files. In the second part of the book, you will learn to create custom geoprocessing tools and how to use the Attribute and Location tools to select specific features. The third part of the book covers topics for advanced users including the REST API, and also teaches you how to use Python with ArcGIS Pro. The book finishes with appendices covering how to automate Python scripts, and the five things that should be at the back of every GIS programmer's mind.
Table of Contents (17 chapters)
16
Index

Getting a list of fields in a feature class or table


Feature classes and tables contain one or more columns of attribute information. You can get a list of the fields in a feature class through the ListFields() function.

Getting ready

The ListFields() function returns a list containing individual Field objects for each field in a feature class or table. Some functions, such as ListFields() and ListIndexes(), require an input dataset to operate on. You can use a wildcard or field type to constrain the list that is returned. Each Field object contains various read-only properties including Name, AliasName, Type, Length, and others.

How to do it…

Follow these steps to learn how to return a list of fields in a feature class.

  1. Open IDLE and create a new script window.

  2. Save the script as C:\ArcpyBook\Ch9\ListOfFields.py.

  3. Import the arcpy module:

    import arcpy
  4. Set the workspace:

    arcpy.env.workspace = "C:/ArcpyBook/data/CityOfSanAntonio.gdb"
  5. Call the ListFields() method on the Burglary feature class inside a...