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")
Best Answer
Snapping points to a line using ArcGIS geoprocessing tools
Assumptions:
You have a point layer and a line layer. You want a points to be snapped to the line layer.
Instructions
1. Use the
Near
tool to find snap locationsAnalysis Tools
->Proximity
->Near
Input features
, your line layer asNear features
. Make sure you tick theLocation
checkbox.NEAR_FID
,NEAR_DIST
,NEAR_X
andNEAR_Y
.2. Export the layer as a table
Table Options
button in the attribute table window, and chooseExport...
. Save it is a dbase (.dbf
) file.Yes
.3. Recreate the points layer from the table
Table of Contents
pane. You might need to switch tabs if you are using ArcGIS 9.3 to theSource
tab.Add XY Data
.NEAR_X
, and the Y field toNEAR_Y
. Adjust the coordinate system if appropriate.Data
->Export data...
to save the layer permanently as a shapefile.