I have a feature class with a large amount of points. My purpose is to randomly move these points to see what happens as a result. Are there specific tools or Python programming methods to accomplish this?
You can manipulate individual point geometry using an Update Cursor. Accessing the SHAPE@XY token is by far the most efficient cursor-based approach. However, if you have a polygon of your area of interest, using a random point generator will likely be more efficient. In this example, I use a minimum and maximum threshold to set the limits for a random number. This random number is used to change the X and Y coordinates.
import arcpy, random # The input point feature class fc = r'C:\temp\points.shp' # Set the random number limits (units will be PCS units) min = -100 max = 100 # Start an update cursor to update the point geometry with arcpy.da.UpdateCursor(fc, ["SHAPE@XY"]) as cursor: for row in cursor: rand_x = random.randint(min, max) rand_y = random.randint(min, max) x = row + rand_x y = row + rand_y xy = (x,y) # The new coordinates row = xy cursor.updateRow(row)
Another approach would be to use the Field Calculator. Here is the code that you will need for the Field Calculator:
from random import randint,choice def RandMove(old_pnt,min_shift,max_shift): neg = [-1,1] #get the first point from the geometry object old_x = old_pnt.firstPoint.x old_y = old_pnt.firstPoint.y #calculate new coordinates new_x = old_x + (choice(neg) * randint(min_shift,max_shift)) new_y = old_y + (choice(neg) * randint(min_shift,max_shift)) #create a new point object and geometry to return new_pnt = arcpy.Point(new_x,new_y) pt = arcpy.PointGeometry(new_pnt) return pt
To use the Field Calculator, open the attribute table of your feature class and right click on the Shape field. Select the Python parser and click on the Show Codeblock check box, then past the above code into the Pre-Logic Script Code text box. The screen capture below shows what the Field Calculator should look like.
I'm not sure if this is any better than the approach by @Aaron but I think it's an interesting trick.