Description
In ArcGIS Online, the Find Nearest tool requires two inputs: an input feature layer, and near feature layer. Both input layers cannot be the same layer. In some instances, it may be desirable to find the first nearest location within the same layer. This can be done by duplicating the layer in the map viewer and using the duplicated layer as one of the input layers. However, when running the tool with both the layer and the duplicated layer as inputs, the data in the table shows zero values for the distance. In some cases, the following error is returned:
Error:
Find Nearest failed.
Cause
This issue occurs because the closest point identified by the tool is identical to the origin point. This results in null linear distance geometry, hence no features can be created.
Solution or Workaround
As a workaround, set the limit number of the nearest locations to two (2) locations before running the Find Nearest tool, and filter the results with a linear distance of more than zero. Follow the steps below:
- Set the limit number of nearest locations to two locations.
- Open the Find Nearest tool by clicking Analysis > Use Proximity > Find Nearest.
- Select the layer as the input feature layer, and the duplicate layer as the near feature layer.
- Set Limit the number of nearest locations to 2.
- Click Run Analysis. Two new layers are created in the Contents pane.
- Filter the results with a linear distance of more than zero.
- View the table of the output layer containing the connecting lines between the nearest locations.
- In the table, click the Options button > Filter.
- Select Straight Line Distance for the first drop-down field.
- Select is greater than for the second drop-down field.
- Enter 0 as the value in the text field. Click Apply Filter. The first nearest location and its distance value are displayed in the table.