# Name:        EdgematchFeatures_example_script2.py
# Description: Performs edgematching spatial adjustment using links produced by
#              GenerateEdgematchLinks. The links go from input features to adjacent 
#              features. The links are then checked for intersecting conditions, which
#              might not be desired; they are finally used to adjust input features 
#              (a copy is made) to connect with the matched adjacent feautures.
# Author:      Esri
# -----------------------------------------------------------------------
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.overwriteOutput = True
env.workspace = r"D:\conflationTools\ScriptExamples\data.gdb"
# Set local variables
inFeatures = "roads1"
adjFeatures = "roads2"
gelOutput = "gelinks_out"
search_distance = "200 Feet"
match_fields = "NAME ROAD_NAME"
qaLocations = "qa_locations"
# Generate rubbersheet links
arcpy.GenerateEdgematchLinks_edit(inFeatures, adjFeatures, gelOutput, search_distance, match_fields)
# ====================================================================================
# Note 1:  The result of GenerateEdgematchLinks may contain errors; see tool reference.
#          Inspection and editing may be necessary to ensure correct links before using
#          them for edgematching.
#
#          One of the possible errors are undesired intersecting or touching links.  
#          Their locations can be found by the process below.
# ====================================================================================
# Find locations where links intersect or touch; the result contains coincident points
arcpy.Intersect_analysis(gelOutput, qaLocations, "", "", "POINT")
# Delete coincident points
arcpy.DeleteIdentical_management(qaLocations, "Shape")
# ====================================================================================
# Note 2:  At this point you can manually inspect locations in qaLocations; delete or
#          modify links as needed.
# ====================================================================================
# Make a copy of the inFeatures for edgematching
inFeature_Copy = inFeatures + "_Copy"
arcpy.CopyFeatures_management(inFeatures, inFeature_Copy)
# Use the links to adjust the copy of the input features
arcpy.EdgematchFeatures_edit(inFeature_Copy, gelOutput, "MOVE_ENDPOINT")