Hi,I have a problem with dispersing geocoded points (randomely/)equally within a polygon. More specific I have geocoded adresses using zip codes and would like to disperse them within a polygon. I know that it is possible to disperse markers but I would like to disperse the points. Dispersing them randomely would be not a problem as it is i.e. possible with Geowizard.Therefore, i have searched the forums and have found some solutions for Avenue but in my ArcGIS 10 this obviously is not working. Based on the post here: http://arcpy.wordpress.com/2013/06/07/disperse-overlapping-points/#comment-220 I have tried to develop a script. But it is not working.Can anyone advice what could be changed to make it work? Is it necessary to have the x, y already in the tael definded as columns?Thank you very much!import random
import arcpy
arcpy.env.workspace = �??D:\�?�\database.gdb�?�
in_points = �??D:\�?�\�?�\geodatabase.gdb\Geocoding_Results.shp�?�
polygon = �??D:\�?�\geodatabase.gdb\zipcode.shp�?�
def point_in_poly(poly, x, y):
�??�?�"Returns if the point is inside the polygon.
Parameters:
poly: arcpy.Polygon() geometry
x: x coordinate (float)
y: y coordinate (float)
�??�?�"
pg = arcpy.PointGeometry(arcpy.Point(x, y), poly.spatialReference)
return poly.contains(pg)
def disperse_points(in_points, polygon):
�??�?�"Randomly disperse points inside a polygon.
Parameters:
in_points: Point feature class/layer (with or without selection)
polygon: arcpy.Polygon() geometry
�??�?�"
lenx = polygon.extent.width
leny = polygon.extent.height
with arcpy.da.UpdateCursor(in_points, "shape@xy") as points:
for p in points:
x = (random.random() * lenx) + polygon.extent.XMin
y = (random.random() * leny) + polygon.extent.YMin
inside = point_in_poly(polygon, x, y)
while not inside:
x = (random.random() * lenx) + polygon.extent.XMin
y = (random.random() * leny) + polygon.extent.YMin
inside = point_in_poly(polygon, x, y)
points.updateRow([(x, y)])