k1andrew

SearchCursor looping problem

Discussion created by k1andrew on Mar 30, 2011
Latest reply on Apr 1, 2011 by k1andrew
My script prints out 2 pieces of information from a table 1) property name 2) the bounding coordinates (hull rectangle) of that property; these coordinates are being reported out in lat/long, as defined by the spatial reference object. 

When I run the script, it successfully prints out all the different property names, however it lists the same bounding coordinates for all the features (whatever the coordinates are for the first feature),   like it's looping through the name just fine, but not the coordinates.

I'm trying to run this on a machine running Windows Server 2003 + ArcGIS 9.3.1

I have it working on my machine (Windows7 + ArcGIS10) but I can't translate it back for some reason.

Here it is:
# Import system modules
import sys, string, os, arcgisscripting, time

print "Start time: " + str(time.strftime("%H:%M:%S"))
sttime = time.time()

# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

# Set the TRACTS dataset variable
Tracts_Path = "E:\GISServices\data\gdbs\property_data.mdb\properties_2011"

# Create a spatial reference object
# Use a projection file to define the spatial reference's properties, this reprojects the results on the fly -- WGS84 is needed for Google Maps
SpatialRef = gp.CreateObject("spatialreference")
SpatialRef.CreateFromFile("C:\Program Files\ArcGIS\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj")

# Open a search cursor on the feature class
# Get the first row of the feature class
# Get the shape field
# Get the extent object

sc = gp.SearchCursor (Tracts_Path, "CONTRACKNAME IN ('Miller', 'Scott', 'Boyer')", SpatialRef)
row = sc.Next()
shape = row.Shape
tract = row.contrackname
extent = row.shape.extent

# Loop through each row of the feature class and print out properties of the extent object

while row:
        print row.CONTRACKNAME + "," + "%f" % (extent.xmin)+ "," + "%f" % (extent.ymin)+ "," + "%f" % (extent.xmax)+ "," + "%f" % (extent.ymax)
        row = sc.Next()
    
del row
del sc



The output looks like this:

Start time: 16:16:16
Boyer,-123.831606,40.021619,-123.822396,40.029524
Miller,-123.831606,40.021619,-123.822396,40.029524
Scott,-123.831606,40.021619,-123.822396,40.029524
End time: 16:16:17
Elapsed time (mins): 0.0114666660627

Outcomes