# Snapping lines to points

I have a layer containing a vector 'Line 1', that originates at point 'A' on a second layer. I also have point 'B' on a third layer. I want to create 'Line 2' that has the same angle and length of 'Line 1', but originates from point 'B'. And I want to repeat this for all vectors on the layer containing 'Line 1'.

i'm working with ArcGIS Engine 10 for .NET. I'm open to solutions working with just ArcGIS 10, so I can create the same geoprocessing tool in ArcGIS Engine.

-
From your diagram I am not clear exactly how you want to snap, and you don't mention your license level, but if you have ArcEditor or ArcInfo then the Snap tool may be worth looking at: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… – PolyGeo Jun 18 '12 at 1:43
i've ArcInfo licence, but the snapping that i'm trying to make, i think couldn't be done using this tool only. – geogeek Jun 18 '12 at 6:41

I have made an ArcPy code to virtually snap the lines, so the script calculates the bearing of the lines, snaps the origin of the vector, then build new lines from new snapped points using the bearing.

But I have noticed a weird error using the function `BearingDistanceToLine_management` in ArcPy. It adds an angle to the bearings. Without understanding the cause of the error, I have eliminated the difference by `180 - 57.935`

``````import arcpy

#arcpy.AddField_management("directions" , "bearing" , "FLOAT" )

arcpy.CalculateField_management("directions" , "bearing" , "180 - 57.935 + math.atan2(( !Shape.firstpoint.X! - !Shape.lastpoint.X! ),( !Shape.firstpoint.Y! - !Shape.lastpoint.Y! ) ) * (180 / math.pi)" , "PYTHON_9.3")

arcpy.Snap_edit("borne" ,  [["D_GPS", "VERTEX", "5"]] )

arcpy.MakeFeatureLayer_management("borne" , "borne_join")
#arcpy.AddField_management("borne_join" , "X" , "DOUBLE" )
#arcpy.AddField_management("borne_join" , "Y" , "DOUBLE" )

arcpy.CalculateField_management("borne_join" , "X" , "!Shape.lastpoint.X!" , "PYTHON_9.3")
arcpy.CalculateField_management("borne_join" , "Y" , "!Shape.lastpoint.Y!" , "PYTHON_9.3")

#arcpy.AddField_management("borne_join" , "distance" , "SHORT" )
arcpy.CalculateField_management("borne_join" , "distance" , "5" , "PYTHON_9.3")

arcpy.MakeFeatureLayer_management("directions" , "dir_join")

arcpy.AddJoin_management("dir_join" , "borne_id" , "borne_join" , "id" )

arcpy.BearingDistanceToLine_management("dir_join" , "new_dir" , "sde.sde.borne.X" , "sde.sde.borne.Y" , "sde.sde.borne.distance" , "METERS" , "sde.sde.directions.bearing" , "DEGREES"  , "GEODESIC" )

arcpy.Delete_management("borne_join")
arcpy.Delete_management("dir_join")
``````
-
for more detail concerning the errors in this script here is a question for this problem gis.stackexchange.com/q/27736/2969 – geogeek Jun 20 '12 at 21:47