I'm new to Python programming in ArcGIS, and I'm currently trying to write a script which I think is beyond me right now.
Script should take each point from first layer and:
Snap this point to nearest point from second layer (with given
distance)If in given radius there is no point, only line, it should snap to this line
If there are two points in radius it should snap to the closest one
If distance between points from first and second layer is 0, no snapping is needed
It's hard for me to come up with the right solution. I thought of doing for loop which will iterate through points in first layer and for every point it should check the distance to points/lines in second layer and then snap to it. But the problem may be a huge amount of points in both layers, and maybe there is a faster and easier way of doing it.
Situation where point should snap to nearest point
Situation where point should snap to nearest line if there is no point in distance
EDIT:
I know that I could do it with tools from ArcToolbox but the problem is that it has to be done with a script which can work with hundreds of points in both layers.
So far in my code there is nearly nothing. Just some thoughts of doing it using cursor and for loop.
import arcpy
arcpy.env.workspace =
layer1 = path to layer1
layer2 = path to layer1
cursor = arcpy.SearchCursor(layer1)
cursor2 = arcpy.SearchCursor(layer2)
tol = 0,3
for row in cursor:
##getting 1 point from first layer
for row in cursor2:
## getting all points from layer 2
## measure distance between these two points
dd =
if dd <= tol
## the same again but with other point from layer1