2

I have some points and some features. These points fall outside the features. I want to connect each point with a line to the closest feature. How can this be done using ArcGIS 10.2?

I have checked around toolbox but didn't manage to find the right tool for it.

  • 1
    So you want to draw a line from your point feature to the closest other feature? – Branco Jun 30 '14 at 17:11
  • Correct! Exactly what I want to do. – dimitris Jun 30 '14 at 20:01
2

Not sure of the license level you have, but if you have an advanced license, you can run the Generate Near Table tool and feed the resulting table into the XY to Line tool to get the desired output.

  • Hey Kevin, thanks a lot for your prompt reply! I can use the Generate Near Table tool. But when I use it and open the table I only get the feature's ID, the distance, and the near xy coordinates of the closest point of the feature. So the xy coordinates of the point that I want to connect are missing from the table, so I can later use properly the XY to Line. Point 1 to connect to closest point of Feature 1. Many thanks! – dimitris Jun 30 '14 at 19:50
  • Sorry should have specified that you'll need to check the Location parameter in the Generate Near Table tool dialog. The result will then include both the from XY as well as the near XY. – Kevin R Dyke Jun 30 '14 at 20:04
  • I have checked the location but this "Specifies whether x- and y-coordinates of the nearest location of the near feature will be written to new fields NEAR_X and NEAR_Y, respectively" So the xy coordinates of the point do not appear in this table, rather than nearest xy coordinates of the feature. – dimitris Jun 30 '14 at 20:09
  • are you sure you're using version 10.2+ and not 10.1? It appears that the FROM_X, FROM_Y are included with the NEAR_X and NEAR_Y starting in 10.2. The quotation you mentioned is from the doc for 10.1 I believe. The 10.2 doc reads "Specifies whether x- and y-coordinates of the input feature's location and nearest location of the near feature will be written to the FROM_X, FROM_Y, NEAR_X, and NEAR_Y fields." – Kevin R Dyke Jun 30 '14 at 20:56
  • If you haven't got the input XY then add the fields to the table, run AddXY (resources.arcgis.com/en/help/main/10.1/index.html#//…) join to the input using input_fid and then calculate the fields across the join. – Michael Stimson Jun 30 '14 at 21:48
0

I've made a python script for that. Basicaly, we found the nearest point from all the points on our line feature. We group the created point by pair, then we create a line with those pairs. The last line add the created line to our initial line feature.

import arcpy 

fcpoint = r'mypoint'
fcline =  r'myline'
database = r'mydatabase'

# Set the workspace 
arcpy.env.workspace = database
arcpy.env.overwriteOutput = True

# find features only within search radius (no limit here)
search_radius = "" 
# find location nearest features
location = "LOCATION"
# avoid getting angle of neares features
angle = "NO_ANGLE"

# execute the function
arcpy.Near_analysis(fcpoint,fcline, search_radius, location, angle)

layer = arcpy.MakeXYEventLayer_management(fcpoint,'NEAR_X','NEAR_Y','point_on_line_temp','2056') #don't forget to precise your own SRID
arcpy.FeatureClassToFeatureClass_conversion(layer, database, 'point_on_line')
arcpy.Append_management (fcpoint, 'point_on_line', 'NO_TEST') 
arcpy.PointsToLine_management('point_on_line', 'line_from_point', "UNIQUE_ID_OF_MY_POINT", "", "NO_CLOSE") # Don't forget to give the unique ID of your point feature.
arcpy.AddField_management('line_from_point', 'CONNECTOR', 'FLOAT')
arcpy.AddField_management(fcline, 'CONNECTOR', 'FLOAT')

with arcpy.da.UpdateCursor('line_from_point', 'CONNECTOR') as cursor:
    for row in cursor:
        row[0] = 1
        cursor.updateRow(row)
del cursor

# Remove this line if you want the connected line as separated feature, this line merge the created line with fcline 
arcpy.Append_management('line_from_point',fcline, 'NO_TEST') 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.