Using Python, I want to join one point feature (centroid node) to the closest 4 links (polylines), but spreading the search in the 4 directions around my point, so that I have:

  • 1 centroid-link connector North-East,
  • 1 centroid-link connector North-West,
  • 1 centroid-link connector South-West,
  • 1 centroid-link connector South-East.

I am now using the following statement to join the centroid node point with the closest link:

arcpy.MakeFeatureLayer_management(connectors_out, "connector_layer", "[CONNECTOR] = 1")
arcpy.SpatialJoin_analysis(centroid_point, "connector_layer", conn_link, "JOIN_ONE_TO_MANY", "KEEP_COMMON", "", "CLOSEST", max_Dist, "DistOut")
  • Do you want to join the centroid to the closest polyline along each of those exact bearings? Or just in each quadrant?
    – dmahr
    Jul 1, 2015 at 13:35
  • Just in each quadrant, so that I do not have just one link as join result, but the 4 closest links in the 4 quadrants (within the specified max dist). Thanks.
    – Phil
    Jul 1, 2015 at 13:47

1 Answer 1


A workflow using the Generate Near Table tool will generally (but not always, see below) get your desired result. It will create a table describing listing the nearest n features to each input feature within a specified distance, as well as the bearing angle between the input feature and each near feature:

parameters = {} #Dictionary of parameters, will be unpacked by keyword
parameters["in_features"] = centroid_point #Input features previously declared
parameters["near_features"] = "connector_layer" #Near features; same coordinate system as above
parameters["out_table"] = "near_output" #Output near table
parameters["search_radius"] = "1000" #Search radius; depends on linear units of coordinate system
parameters["location"] = "LOCATION" #Write locations of near points to table
parameters["angle"] = "ANGLE" #Write angle of bearing between input and near features to table
parameters["closest"] = "ALL" #Find more than just the closest feature
parameters["closest_count"] = 100 #Number of near features to find
parameters["method"] = "GEODESIC" #Produces geographic angle with north = 0 rather than arithmetic angle with east = 0
arcpy.GenerateNearTable_analysis(**parameters) #Run tool by unpacking parameters

Below is what the output table will look like. The quadrant field is new and can be generated from field calculator using the following expression: 4-int((( !NEAR_ANGLE! -90.0) % 360.0)/90.0) and returns the mathematical quadrants where 1 is northeast, 2 is northwest, 3 is southwest, and 4 is southeast.

| 1      | 1        | 51.5      | 20         | 1        |
| 1      | 2        | 33.1      | 110        | 4        |
| 1      | 3        | 27.8      | 120        | 4        |
| 1      | 4        | 88.5      | 200        | 3        |
| 1      | 5        | 17.0      | 290        | 2        |

In this example, lines 2 and 3 are both near point 1 and located in quadrant 4 (the southeast quadrant). But line 3 is closer at only 27.8 units away instead of 33.1, so that's the feature we want to include for that quadrant. You can perform this identification process in Excel, using Summary Statistics (with IN_FID and QUADRANT as case fields and NEAR_DIST as a MIN statistics field), or using Python with some basic dictionaries.

Please note that this tool requires an ArcGIS for Desktop Advanced license (formerly ArcInfo). See below for a possible workaround using arcpy.

The weakness of the approach outlined above is that the output of the Generate Near Table tool will only include the nearest features, not the nearest features for each for each quadrant around the input point. This is a subtle difference, but it can make a difference. Consider the situation illustrated here with MS Paint, where the input point is in blue and two lines are in red and orange:


Point A is the closest point in the northeast quadrant, while Point B is the closest point in the northwest quadrant. Point C is also in the northwest quadrant, but it's farther away than Point B. Unfortunately, the Generate Near Table Tool will only identify Point A and Point C; it will not identify Point B because Point A is closer on that feature.

To get around this, you could split the red line along the quadrant boundaries. This sounds easy, but it would be a bit of work to get it running. You'd have to make a grid (perhaps using Create Fishnet) and intersect your lines with the grid (splitting them) before running Generate Near Table. Unfortunately, this process would have to be repeated for each input point, since the location of the quadrant boundaries change.

An alternative that may be faster is to use the clip method of the arcpy.Polyline() class to clip the lines, and then use the angleAndDistanceTo method to get the distance to the point. More generally, this can be used as a workaround for those who lack ArcGIS for Desktop Advanced licenses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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