Near (Analysis)

Summary

Determines the distance from each feature in the input features to the nearest feature in the near features, within the search radius.

Illustration

Finding near feature by geometry type.

Usage

Syntax

Near_analysis (in_features, near_features, {search_radius}, {location}, {angle})
ParameterExplanationData 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
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.

  • NO_LOCATIONSpecifies that the x- and y-coordinates of the nearest location will not be written. This is the default.
  • LOCATIONSpecifies that the x- and y-coordinates of the nearest location will be written to NEAR_X and NEAR_Y fields.
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.

  • NO_ANGLESpecifies that the near angle values will not be written. This is the default.
  • ANGLESpecifies that the near angle values will be written to the NEAR_ANGLE field.
Boolean

Code Sample

Near example 1 (Python window)

The following Python interactive window script demonstrates how to use the Near function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data/city.gdb" 

## find the nearest road from each house
arcpy.Near_analysis('houses', 'roads')
Near example 2 (stand-alone Python script)

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

# Name: Near.py
# Description: Finds nearest features from input feature class to near feature class.

import arcpy
from arcpy import env

# Set workspace environment
env.workspace = "C:/data/city.gdb"

try:
    # set local variables
    in_features = "houses"
    near_features = "parks"
    
    # find features only within search radius
    search_radius = "5000 Meters"
    
    # find location nearest features
    location = "LOCATION"
    
    # avoid getting angle of neares features
    angle = "NO_ANGLE"
    
    # execute the function
    arcpy.Near_analysis(in_features, near_features, search_radius, location, angle)
    
    # get geoprocessing messages
    print arcpy.GetMessages()

except arcpy.ExecuteError:
    print arcpy.GetMessages(2)
    
except Exception as ex:
    print ex.args[0]

Environments

Related Topics

Licensing Information

ArcView: No
ArcEditor: No
ArcInfo: Yes

4/4/2012