[GIS] Snapping lines to points

arcgis-10.0arcgis-enginearcpysnapping

enter image description here

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.

Best Answer

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")
Related Question