Skip to content
import { getNearestCoordinate, getNearestVertex, getNearestVertices, supportsCurves } from "@arcgis/core/geometry/operators/proximityOperator.js";
Since
ArcGIS Maps SDK for JavaScript 4.31

Find the closest vertices of the 2D geometry.

Proximity operator

See also
  • Sample - Geometry operator - proximity analysis

Type definitions

Options

Type definition

unit

Property
Type
LengthUnit | undefined

The length unit of the search radius and result distances. The default is the input geometry's spatial reference unit. An error will be thrown if this is set for Geographic Coordinate Systems.

GetNearestCoordinateOptions

Type definition
Supertypes
Options

calculateLeftRightSide

Property
Type
boolean | undefined

When the parameter is set to true, this function will calculate the left/right side of a polyline or polygon. Look for the result in the isRightSide property of the returned ProximityResult object.

Default value
false

testPolygonInterior

Property
Type
boolean | undefined

When geometry is a polygon, the function will test if point is inside of the polygon. Points that are inside of the polygon have zero distance to the polygon. When set to false, the function will not check if the point is inside of the polygon, but will only determine proximity to the boundary.

Default value
true

Functions

getNearestCoordinate

Function

Returns the nearest coordinate on the geometry to the given input point.

Signature
getNearestCoordinate (geometry: GeometryUnion, point: Point, options?: GetNearestCoordinateOptions): ProximityResult
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry.

point

The point used to search for the nearest coordinate in geometry.

options

Additional options.

Returns
ProximityResult

Returns the proximity result which contains the nearest coordinate on the input geometry to the given inputPoint.

Example
// Return the nearest result on a polygon to the given point
const proximityResult = proximityOperator.getNearestCoordinate(polygon, point);

getNearestVertex

Function

Returns the nearest vertex on the geometry.

Signature
getNearestVertex (geometry: GeometryUnion, point: Point, options?: Options): ProximityResult
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry.

point

The point used to search for the nearest coordinate in the input geometry.

options

Additional options.

Returns
ProximityResult

Returns the proximity result which contains the nearest vertex on the geometry to the given inputPoint.

Example
// Return the nearest vertex on a polygon to the given point
const proximityResult = proximityOperator.getNearestVertex(polygon, point);

getNearestVertices

Function

Returns vertices of the geometry that are closer to the given point than the given radius.

Signature
getNearestVertices (geometry: GeometryUnion, point: Point, searchRadius: number, maxVertexCountToReturn: number, options?: Options): ProximityResult[]
Parameters
ParameterTypeDescriptionRequired
geometry

The input geometry.

point

The point used to search for the nearest coordinate in geometry.

searchRadius

The planar distance from the inputPoint to search for vertices. Unless the unit option is set, the default is the geometry's spatial reference unit.

maxVertexCountToReturn

The maximum number of vertices that will be returned. Must be a positive number.

options

Additional options.

Returns
ProximityResult[]

Returns an array of proximity results which contain the nearest vertices on geometry to the given inputPoint that are less than or equal to the planar distance of search radius. The array is sorted by distance to the inputPoint with the closest point first. When there are more than the maxVertexCountToReturn vertices to return, it returns the closest vertices. The array will be empty when geometry is empty.

Example
// Return the nearest vertices on a polygon to the given point
const proximityResultsArray = proximityOperator.getNearestVertices(polygon, point, 100, 5);

Variables

supportsCurves

Variable

Indicates if the operator supports input geometries that contain curves. The value will always be true.

Type
boolean