Move Features

4654
12
10-08-2013 11:16 AM
JamesSmith7
New Contributor
I am attempting to select features within ArcMap, run the script, and move the selected features by a distance entered.  I am attempting to recreate the Editor Move Tool and the wheel.  I read through the documentation;  http://resources.arcgis.com/en/help/main/10.1/index.html#//01m80000000s000000.  But, the documetation dos not provide a script example.  I was thinking something along the lines of the following script.  An attribute error exists on the line reading, ext = lyr.extent.  I tried including a layer in the ListLayers function, but that did not solve the error. 

mxd = arcpy.mapping.MapDocument ("CURRENT")
df = arcpy.mapping.ListDataFrames (mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, df)

EW = arcpy.GetParameter(0)
NS = arcpy.GetParameter(1)

#orig extent
ext = lyr.extent
#mods
ext.XMin += EW
ext.XMax += EW
ext.YMin += NS
ext.YMax += NS
#new extent
lyr.extent = ext
Tags (2)
0 Kudos
12 Replies
JamesSmith7
New Contributor
What am I not seeing?

rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))

def shift_features(in_features, EWmove=None, NSmove=None):
 in_features = rai
 point.X += EWmove
 point.Y += NSmove
 with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
  for row in cursor:
   cursor.updateRow([[row[0][0] + (EWmove or 0), row[0][1] + (NSmove or 0)]])
 return

arcpy.RefreshActiveView()
0 Kudos
NeilAyres
MVP Alum
rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))

def shift_features(in_features, EWmove=None, NSmove=None):
 in_features = rai
 point.X += EWmove
 point.Y += NSmove
 with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
  for row in cursor:
   cursor.updateRow([[row[0][0] + (EWmove or 0), row[0][1] + (NSmove or 0)]])
 return

arcpy.RefreshActiveView()


shouldn't this be...

rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))

def shift_features(in_features, EWmove=None, NSmove=None):
    rai = in_features
        with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
            for row in cursor:
                cursor.updateRow([[row[0][0] + (EWmove), row[0][1] + (NSmove)]])
return

arcpy.RefreshActiveView()


Cheers,
Neil
0 Kudos
JamesSmith7
New Contributor
rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))

def shift_features(in_features, EWmove=None, NSmove=None):
 in_features = rai
 point.X += EWmove
 point.Y += NSmove
 with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
  for row in cursor:
   cursor.updateRow([[row[0][0] + (EWmove or 0), row[0][1] + (NSmove or 0)]])
 return

arcpy.RefreshActiveView()


shouldn't this be...

rai = arcpy.mapping.ListLayers(mxd, "Railroads", df)[0]
EWmove = float(arcpy.GetParameter(0))
NSmove = float(arcpy.GetParameter(1))

def shift_features(in_features, EWmove=None, NSmove=None):
    rai = in_features
        with arcpy.da.UpdateCursor(rai, ['SHAPE@XY']) as cursor:
            for row in cursor:
                cursor.updateRow([[row[0][0] + (EWmove), row[0][1] + (NSmove)]])
return

arcpy.RefreshActiveView()


Cheers,
Neil


Neither of these two approaches work.  They both run with no results or errors.  The other suggestion by Matt works.  So, I am going to modify Matt's suggestion.  I appreciate the help.
0 Kudos