Generate Near Table (Analysis)
Summary
Determines the distances from each feature in the input features to one or more nearby features in the near features, within the search radius. The results are recorded in the output table.
Illustration
Usage
-
This tool behaves the same as the Near tool. However, instead of updating the input features, it creates a new output table. Moreover, it can find as many near features as specified by the Maximum number of closest matches parameter.
The output table contains three fields—IN_FID, NEAR_FID and NEAR_DIST—by default. Additional fields are added to output depending on the optional parameters selected as explained in the parameter entry.
-
The output table can be joined back to the input feature class or a near feature class using the INPUT_FID or NEAR_FID fields.
-
Both input features and near features can be point, multipoint, line, or polygon.
-
The default option for this tool is to find the distance from each input feature to the closest near feature. Choose the ALL option, that is, uncheck the Find only closest feature parameter to create a table containing the distance between all input to all near features.
-
The values for NEAR_FID and NEAR_DIST will be -1 if no feature is found within the search radius.
-
If no value for Search Radius is specified, a radius is used large enough so that all near features can be incorporated in the distance calculation. If the default search radius is used (no radius is specified) the output table can be quite large. For example, calculating distances from 1,000 points in one feature class to 1,000 points in another feature class can produce an output table containing 1 million records. Use the search radius to limit the number of output records.
-
Both Input Features and Near Features can be the same dataset. In that case, when the input and near features are the same record, that result will be skipped so as not to report that each feature is 0 units from itself.
The input features can be a layer on which you have performed a selection. The selected features will be used and updated during the execution of the tool. The remaining features will have the values of the newly created fields (such as NEAR_FID and NEAR_DIST) set to -1.
The distances calculated by this tool are in the unit of the coordinate system of the input features. If your input is in a geographic coordinate system and you want output distances to be measured in a linear unit (as opposed to decimal degrees), you must first project your input to a projected coordinate system using the Project tool. For best results, use an equidistant projection or a projection intended for your study area (UTM, for example).
Syntax
Parameter | Explanation | Data Type |
in_features |
The input features that can be point, polyline, polygon, or multipoint type. | Feature Layer |
near_features [near_features,...] |
Value used to find the nearest features from input features. There can be one or more entries of near features; each entry can be of point, polyline, polygon, or multipoint type. When multiple entries of near features are specified, a new field, NEAR_FC, is added to the input table to store the paths of the source feature class that contains the nearest features. | Feature Layer |
out_table |
The output table that will contain the proximity information—such as IN_FID, NEAR_FID, and NEAR_DIST—and other attributes—such as location (NEAR_X, NEAR_Y) and angle (NEAR_ANGLE)—of the near feature and the NEAR_FC, if necessary. | Table |
search_radius (Optional) |
Specifies the radius used to search for candidate near features. The near features within this radius are considered for calculating the nearest feature. If no value is specified, that is, the default (empty) radius is used, all near features are considered for calculation. The unit of the search radius defaults to the units of the coordinate system of the input features. The units can be changed to any other unit. However, this has no impact on the units of NEAR_DIST which is based on the units of the coordinate system of the input features. | Linear unit |
location (Optional) |
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.
| Boolean |
angle (Optional) |
Specifies whether the near angle values in decimal degrees will be calculated and written to a new field, NEAR_ANGLE. A near angle measures from the x-axis (horizontal axis) to the direction of the line connecting an input feature to its nearest feature at their closest locations, and it is within the range of 0 to 180 or 0 to -180 decimal degrees - 0 to the east, 90 to the north, 180 (-180°) to the west, and -90 to the south.
| Boolean |
closest (Optional) |
Determines whether to locate and return only the closest features or all the features within the search radius.
| Boolean |
closest_count (Optional) |
Find only the specified number of closest features. This parameter will not be used if the Find only closest feature option is checked. | Long |
Code Sample
The following snippet 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")
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 from arcpy import env # set workspace environment env.workspace = "C:/data/input/gnt.gdb" # set required parameters inFeatures = "campsites" nearFeatures = ["parks", "trails"] outTable = "near_parks_trails" # optional parameters searchRadius = '1500 Meters' location = 'NO_LOCATION' angle = 'NO_ANGLE' closest = 'ALL' closestCount = 3 # find crime locations within the search radius arcpy.GenerateNearTable_analysis(inFeatures, nearFeatures, outTable, searchRadius, location, angle, closest, closestCount)