Problem using SearchCursor with spatialReference and sortFields

Discussion created by rsarwas on Jul 8, 2010
I'm having trouble using the search cursor in a geoprocessing script, and I'm hoping for some help. My testing has shown that if I specify a sort order and a spatial reference system then the geometry returned is sorted but not projected.  If I omit either the spatial reference or the sort order parameter, then the data is returned correctly. I am using 9.3.1, with the ESRI provided python install. The behavior is the same if the script is run in-process, or externally.  It also doesn't matter if the feature class is in a shapefile or personal/file geodatabase (I have not tested SDE).

import arcgisscripting

f = open(r"C:\tmp\bugout.txt","w")

def showdata(title, pts):
  pt = pts.Next()
  while pt != None:
    f.write("\n  Place: "+str(pt.GetValue("place"))+
              "  X: "+str(pt.shape.getpart(0).X)+
              "  Y: "+str(pt.shape.getpart(0).Y))
    pt = pts.Next()

gp = arcgisscripting.create(9.3)

fclist = (r"C:\tmp\bug.shp") #,
#          r"C:\tmp\bug.mdb\bug",
#          r"C:\tmp\bug.gdb\bug")

sr2 = gp.CreateObject("spatialreference")
sr2.CreateFromFile(r"C:\Program Files\ArcGIS\Coordinate Systems"+
                   r"\Projected Coordinate Systems\Continental" + 
                    r"\North America\Alaska Albers Equal Area Conic.prj")

for fc in fclist:
  desc = gp.Describe(fc)
  sr = desc.SpatialReference
  f.write("\n  Input SR: "
  f.write("\n  Fields: ")
  for field in desc.fields:
    f.write( ", ")
  showdata("\nDefault view",
  showdata("\nProjected (" + sr2.Name + ") view",
           gp.SearchCursor(fc, "", sr2))
  showdata("\nSorted view",
           gp.SearchCursor(fc, "", "", "", "place A"))
  showdata("\nProjected/Sorted view",
           gp.SearchCursor(fc, "", sr2, "", "place A"))

The output from the above is:

  Input SR: GCS_North_American_1983
  Fields: FID, Shape, place, 

Default view
  Place: work  X: -155.584487535  Y: 63.6232686981
  Place: Home  X: -151.927977839  Y: 61.4293628809
Projected (NAD_1983_Alaska_Albers) view
  Place: work  X: -78407.4485127  Y: 1518342.34371
  Place: Home  X: 110176.445297  Y: 1273876.25765
Sorted view
  Place: Home  X: -151.927977839  Y: 61.4293628809
  Place: work  X: -155.584487535  Y: 63.6232686981
Projected/Sorted view
  Place: Home  X: -151.927977839  Y: 61.4293628809
  Place: work  X: -155.584487535  Y: 63.6232686981

The behavior is the same if I add a where clause or a field selection list, although those tests are omitted from the code for brevity.

I have attached my simple two point shape file for anyone who wants to test this, however any point file should work with minor tweaks to the code.

Can anyone confirm this problem, and/or test it with version 10.