bmancell

Help with Search Cursor

Discussion created by bmancell on Dec 14, 2010
Latest reply on Dec 16, 2010 by bmancell
Hello,
I'm trying to create a Python script which disperses selected point features. I'm running the script on the Shape field using the Field Calculator parser. What I would like the script to do is iterate over the shapefile and assign a counter value to each selected feature. This value would then be used to determine the direction in which the point will be moved (the dispDist variable determines the dispersal distance). If I select one feature the point will move 0.01 to the north (as expected). However, if I select two or more features they all move to the same position (rather than disperse according to their cntr id). I think the problem lies with the search cursor, but I'm not sure. Does any one see what I'm doing wrong here? Thanks!
codeblock:
import arcpy
def pointDisperse(shape, lat, long):
 point = shape.getPart(0)
 dispDist=0.01
 cntr = 0
 rows = arcpy.SearchCursor("pyDisperse")
 row = rows.next()
 while row:
  cntr += 1
  row = rows.next()
 if cntr == 1:
  point.Y = lat+dispDist
  return point
 elif cntr == 2:
  point.X = long+dispDist
  return point
 elif cntr == 3:
  point.Y = lat+dispDist
  point.X = long+dispDist
  return point
 elif cntr == 4:
  point.Y = lat-dispDist
  point.X = long+dispDist
  return point
 elif cntr == 5:
  point.Y = lat-dispDist
  return point
 elif cntr == 6:
  point.Y = lat-dispDist
  point.X = long-dispDist
  return point
 elif cntr == 7:
  point.X = long-dispDist
  return point
 elif cntr == 8:
  point.Y = lat+dispDist
  point.X = long+dispDist
  return point
 del row, rows


expression:
pyDisperse(!SHAPE!, !lat!, !long!)

Outcomes