UpdateCursor not respecting spatial reference

Discussion created by k1andrew on Sep 14, 2011
Latest reply on Sep 18, 2011 by stacyrendall
I have a script that reports out the bounding coordinates (hull rectangle) for features in a fc, using a print statement.

I changed the script to use and UpdateCursor to write the coordinates to the fc instead of printing it out in the Python window.

When I comment out the update rows line, the results print out correctly, using the spatial reference (wgs84), but when I uncomment the update rows line, the results print out in their native coordinates and the spatial reference is not used.

Here is the script:

# Import system modules
import arcinfo, time, arcpy

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

# Set the path to the Tracts dataset
Tracts_Path = r"C:\Scratch_Katie\Test.mdb\CA_TNC_TRACTS"

# Create a spatial reference object and use a projection file to define the spatial reference's properties, this will be used
# to reproject the results on the fly to WGS84 the spatial reference object is a parameter specified in the searchcursor object

prjFile = r"C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj"
sr = arcpy.SpatialReference(prjFile)

# Open a update cursor update rows with coordinates transformed into wgs84, also print out information

rows = arcpy.UpdateCursor (Tracts_Path,"DEALTRACKER_ID is not NULL",sr)

for row in rows:
# when these two lines are commented out this script prints out the coordinates in wgs84, when they are uncomments the script
# prints out the coordinates in their native coordinate system, and the spatial reference is ignored
#  row.EXTENT_COORDS = "?extent=" + str(row.shape.extent.XMin) + "," + str(row.shape.extent.YMin) + "," + str(row.shape.extent.XMax) + "," + str(row.shape.extent.YMax)
#  rows.updateRow(row)
  print row.TRACTNAME
  print row.DEALTRACKER_ID
  print "?extent=" + str(row.shape.extent.XMin) + "," + str(row.shape.extent.YMin) + "," + str(row.shape.extent.XMax) + "," + str(row.shape.extent.YMax)

del rows
del Tracts_Path
del sr

print "End time: " + str(time.strftime("%H:%M:%S"))
endtime = time.time()
print "Elapsed time (mins): " + str((endtime - sttime)/60)