SearchCursor method |
|
|
Release 9.3
Last modified January 19, 2010 |
Print all topics in : "Properties and Methods" |
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.
| 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. |
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()