Skip To Content

Generate Near Table

Summary

Calculates distances and other proximity information between features in one or more feature class or layer. Unlike the Near tool, which modifies the input, Generate Near Table writes results to a new stand-alone table and supports finding more than one near feature.

Learn more about how proximity is calculated by geoprocessing tools

Illustration

Generate Near Table

Usage

  • The output table will have the following fields:

    Field NameDescription
    IN_FID

    The ObjectID of the input feature.

    NEAR_FID

    The ObjectID of the nearest feature.

    NEAR_DIST

    The distance from the input feature to the near feature. The value of this field is in the linear unit of the input feature's coordinate system, or Meters when the Method parameter is set to GEODESIC and the input is in a geographic coordinate system.

    NEAR_FC

    The catalog path to the feature class that contains the near feature. This field is only added to the output table if multiple Near Features are specified.

    NEAR_RANK

    An integer value ranking all near features based on their proximity to an individual input feature. The closest feature will get a NEAR_RANK value of 1, the second closest will get a NEAR_RANK value of 2, and so on.

    The following fields will be added to the output table if the Location parameter is checked (location parameter set to LOCATION in Python). The unit of the values of the fields depend on what method is selected on the Method parameter. If set to PLANAR, the value is in the linear unit of the input feature's coordinate system. If set to GEODESIC, the value is in the geographic cooordinate system associated with the input feature's coordinate system.

    Field NameDescription
    FROM_X

    X-coordinate of the location on the input feature which is closest to the near feature.

    FROM_Y

    Y-coordinate of the location on the input feature which is closest to the near feature.

    NEAR_X

    X-coordinate of the location on the near feature which is closest to the input feature.

    NEAR_Y

    Y-coordinate of the location on the near feature which is closest to the input feature.

    The following field will be added to the output table if the Angle parameter is checked (angle parameter set to ANGLE in scripting).

    FieldDescription
    NEAR_ANGLE

    Angle of the line at the FROM_X and FROM_Y location which connects the input features to the near feature.

  • When the input and near feature intersect, the following values are written to the output table:

    • NEAR_ANGLE and NEAR_DIST will be set to 0.0.
    • FROM_X and FROM_Y will be identical to NEAR_X and NEAR_Y and will be a location within the intersection of the two features.

  • The values in the NEAR_DIST field is in the linear unit of the input features coordinate system. If the input is in a geographic coordinate system and Method parameter is set to GEODESIC, NEAR_DIST units will be meters.

  • The output table can be joined back to the input features using the IN_FID or to the near features using the NEAR_FID.

  • If a Search Radius is specified and no near feature is found, no record will be output.

  • If no Search Radius is specified, all near features will be considered as candidates.

  • If no Search Radius is specified and Find only closest features is unchecked (closest set to ALL in Python), and Maximum number of closest is left to default (0 or empty), the output table will contain distance calculations between all input features and all near features. This kind of process can take quite a long time and can create a large output table. For example, if you have 1,000 input features and 1,000 near features, the output table will contain 1,000,000 records.

  • The same feature class or layer may be used as both input and near features. In this situation, the input feature being evaluated is excluded from the near features candidates to avoid all features being closest to themselves.

  • When using the Planar option for the Method parameter, the input features should be in a projection that is appropriate for distance measurement, such as an equidistant projections.

    Learn more about Coordinate systems and projections

  • To visualize the FROM_X, FROM_Y, NEAR_X, and NEAR_Y locations, the output table can be used as input to the Make XY Event Layeror XY To Line tools.

Syntax

GenerateNearTable_analysis (in_features, near_features, out_table, {search_radius}, {location}, {angle}, {closest}, {closest_count}, {method})
ParameterExplanationData Type
in_features

The input features that can be point, polyline, polygon, or multipoint type.

Feature Layer
near_features
[near_features,...]

One or more layer of feature class containing near feature candidates. The near features can be of point, polyline, polygon, or multipoint. If multiple layers or feature classes is specified, a field named NEAR_FC is added to the input table and will store the paths of the source feature class containing the nearest feature found. The same feature class or layer may be used as both input and near features.

Feature Layer
out_table

The output table containing the result of the analysis.

Table
search_radius
(Optional)

The radius used to search for near features. If no value is specified, all near features will be candidates. If a distance is entered, but the unit is left blank or set to Unknown, the units of the coordinate system of the input features are used. If the Geodesic option is used in the Method parameter, a linear unit such as Kilometers or Miles should be used.

Linear unit
location
(Optional)

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.

  • NO_LOCATION Locations will not be written to the output table. This is the default.
  • LOCATION Locations will be written to the output table.
Boolean
angle
(Optional)

Specifies whether the near angle will be calculated and written to a NEAR_ANGLE field in the output table. A near angle measures direction of the line connecting an input feature to its nearest feature at their closest locations. When the PLANAR method is used in the method parameter, the angle is within the range of -180° to 180°, with 0° to the east, 90° to the north, 180° (or -180°) to the west, and -90° to the south. When the GEODESIC method is used, the angle is within the range of -180° to 180°, with 0° to the north, 90° to the east, 180° (or -180°) to the south, and -90° to the west.

  • NO_ANGLENEAR_ANGLE will not be added to the output table. This is the default.
  • ANGLENEAR_ANGLE will be added to the output table.
Boolean
closest
(Optional)

Specifies whether to return only the closest features or multiple features.

  • CLOSESTOnly the closest near feature will be written to the output table. This is the default.
  • ALLMultiple near features will be written to the output table (a limit can be specified in the closest_count parameter).
Boolean
closest_count
(Optional)

Limit the number of near features reported for each input feature. This parameter is ignored if the closest parameter is set to CLOSEST.

Long
method
(Optional)

Determines whether to use a shortest path on a spheroid (geodesic) or a flat earth (planar). It is strongly suggested to use Geodesic method with data stored in a coordinate system which is not appropriate for distance measurements (for example, Web Mercator and any geographic coordinate system), or any dataset which spans a large geographic area.

  • PLANARUses planar distances between the features. This is the default.
  • GEODESICUses geodesic distances between features. This method takes into account the curvature of the spheroid and correctly deals with data near the dateline and poles.
String

Code sample

GenerateNearTable example 1 (Python window)

The following demonstrates how to use the GenerateNearTable function in the Python window.

import arcpy

arcpy.env.workspace = "C:/data/input/gnt.gdb"

arcpy.GenerateNearTable_analysis("campsites", ["parks", "trails"], "better_sites")
GenerateNearTable example 2 (stand-alone Python script)

The following Python script demonstrates how to use the GenerateNearTable function in a stand-alone script.

# Name: GenerateNearTable.py
# Description: Finds 3 nearest in the near feature class from the input feature class.


# import system modules
import arcpy

# set workspace environment
arcpy.env.workspace = "C:/data/input/gnt.gdb"

# set required parameters 
in_features = "campsites"
near_features = ["parks", "trails"]
out_table = "near_parks_trails"

# optional parameters
search_radius = '1500 Meters'
location = 'NO_LOCATION'
angle = 'NO_ANGLE'
closest = 'ALL'
closest_count = 3

# find crime locations within the search radius
arcpy.GenerateNearTable_analysis(in_features, near_features, out_table, search_radius, 
                                 location, angle, closest, closest_count)

Licensing information

  • ArcGIS Desktop Basic: No
  • ArcGIS Desktop Standard: No
  • ArcGIS Desktop Advanced: Yes

Related topics