Show Navigation | Hide Navigation
You are here:
Geoprocessing > Automating your work with scripts > Scripting object: Properties and Methods > Properties and Methods

SearchCursor method

Release 9.3
Last modified January 19, 2010
E-mail This Topic Printable Version Give Us Feedback

Print all topics in : "Properties and Methods"


Related Topics

Note: This topic was updated for 9.3.1.

Establishes a cursor for searching through field rows. A search cursor can be used to retrieve rows. This method returns an enumeration object that will, in turn, hand out row objects.

Syntax


object.SearchCursor(InputValue As String, {WhereClause} As String, {SpatialReference} As Object, {FieldList} As String, {SortFields} As String) As Object

{} = optional

Part Description
object The instantiated geoprocessor object.
InputValue The table, feature class, or shapefile containing rows to be searched.
WhereClause Optional. An expression that limits the number of rows to be searched. For further information on WHERE clauses and Structured Query Language (SQL) statements, see About building an SQL statement.
SpatialReference Optional. The spatial reference of the input table, feature class, or shapefile.
FieldList Optional. Fields to be included in the cursor. By default, all fields are used.
SortFields Optional. Fields used to sort the rows. Ascending and descending order for each field is denoted by A and D.


Examples



Find the county with the largest population for each state in the United States.

import arcgisscripting
gp = arcgisscripting.create(9.3)

# Open a searchcursor
#   Input: c:/us/counties.shp
#   FieldList:  NAME; STATE_NAME; POP2000
#   SortFields: STATE_NAME A; POP2000 D
#
rows = gp.searchcursor("c:/us/counties.shp","","","NAME; STATE_NAME; POP2000",            "STATE_NAME A; POP2000 D")

# Get the first feature in the searchcursor
#
row = rows.next()
currentstate = ""

# Iterate through the rows in the cursor
#
while row:
    if currentstate != row.STATE_NAME:
        currentstate = row.STATE_NAME

        # Print out the state name, county, and population
        #
        print "State: %s, County: %s, population: %i" %                 (row.STATE_NAME, row.NAME, row.POP2000)
    row = rows.next()


Please visit the Feedback page to comment or give suggestions on ArcGIS Desktop Help.
Copyright © Environmental Systems Research Institute, Inc.