Jika Anda mencari solusi yang tidak memerlukan pengembangan alat .NET, Anda dapat menggunakan skrip python di bawah ini untuk mencapai apa yang Anda cari. Saya memiliki kebutuhan yang persis sama dan menulis skrip berikut sebagai solusinya. Konfigurasikan sebagai alat ArcCatalog dengan 4 parameter, atau komentar parameter dan batalkan komentar pada variabel hardcoded dan jalankan secara langsung.
# CreateLineFromNearestVertexToFeature.py
# Author: Jeff Berry
# Description: Creates a line between the nearest vertext on source features
# to the nearest feature in target feature class.
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
from arcpy import env
# Local variables:
# 1. SourceFC - Feature Class
# 2. TargetFC - Feature Class
# 3. Output_gdb - Geodatabase
# 4. Output_fc - String
SourceFC = arcpy.GetParameterAsText(0)
TargetFC = arcpy.GetParameterAsText(1)
Output_gdb = arcpy.GetParameterAsText(2)
Output_fc = arcpy.GetParameterAsText(3)
## Alternatively setup hardcoded variables
##SourceFC = "Buildings"
##TargetFC = "WaterMains"
##Output_gdb = "D:\\New File Geodatabase.gdb"
##Output_fc = "lines_output"
SourceFeaturePoints = "SrcFtrPoints"
arcpy.env.workspace = Output_gdb
# Process: Feature Vertices To Points
arcpy.FeatureVerticesToPoints_management(SourceFC, SourceFeaturePoints, "ALL")
# Process: Near
arcpy.Near_analysis(SourceFeaturePoints, TargetFC, "1000 Feet", "LOCATION", "NO_ANGLE")
# Process: Create Feature Class...
#arcpy.CreateFeatureclass_management(Output_gdb, Output_fc, "POLYLINE", "", "DISABLED", "DISABLED", "", "", "0", "0", "0")
rows = arcpy.SearchCursor(SourceFeaturePoints)
lstIDs = []
for row in rows:
lstIDs.append(row.ORIG_FID)
uniqueOBJIDS = set(lstIDs)
newLineList = []
shapeName = arcpy.Describe(SourceFeaturePoints).shapeFieldName
for objID in uniqueOBJIDS:
rows = arcpy.SearchCursor(SourceFeaturePoints, "\"NEAR_DIST\" = (SELECT MIN( \"NEAR_DIST\") FROM SrcFtrPoints WHERE \"ORIG_FID\" = " + str(objID) + ")")
for row in rows:
arrayLine = arcpy.Array()
ftr = row.getValue(shapeName)
pointStart = ftr.firstPoint
pointEnd = arcpy.Point(row.NEAR_X, row.NEAR_Y)
arrayLine.add(pointStart)
arrayLine.add(pointEnd)
plyLine = arcpy.Polyline(arrayLine)
newLineList.append(plyLine)
arcpy.CopyFeatures_management(newLineList, Output_fc)
arcpy.Delete_management(SourceFeaturePoints, "FeatureClass")
del rows
del row
del SourceFeaturePoints
del Output_fc
del Output_gdb
arcpy.ClearEnvironment("workspace")