---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/IPolygonGeometryAccess.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# IPolygonGeometryAccess

Extends [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md).

Interface for accessing the "Polygon" geometry.

[Constructor](#constructor-summary) | [Fields](#properties-summary) | [Events](#events-summary) | [Methods](#methods-summary)

## Constructor {#constructor-summary}

```javascript
IPolygonGeometryAccess()
```

## Fields {#properties-summary}

#|
|| **Name** | **Type** | **Description** ||
|| [events](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#events) | [IEventManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventManager.md) | Event manager for the object.

Inherited from [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#events). ||
|#

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [change](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#event-change) | Changed coordinates. Instance of the [Event](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- oldCoordinates - Old coordinates
- newCoordinates - New coordinates.
- oldFillRule - Old fill rule.
- newFillRule - New fill rule. ||
|#

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [contains](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#contains)([position](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#contains-param-position)) | Boolean | Checks whether the passed point is located inside the polygon. ||
|| [freeze](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#freeze)() | [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md) | Switches the object to "frozen" mode.

Inherited from [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#freeze). ||
|| [get](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#get)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#get-param-index)) | Number[][] | Returns coordinates of the contour with the specified index. ||
|| [getChildGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getChildGeometry)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getChildGeometry-param-index)) | [ILinearRingGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILinearRingGeometryAccess.md) | Creates and returns an [ILinearRingGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILinearRingGeometryAccess.md) object for the specified contour. ||
|| [getClosest](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getClosest)([anchorPosition](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getClosest-param-anchorPosition)) | Object | Searches for the point nearest to "anchorPosition" on the polygon contour. ||
|| [getCoordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getCoordinates)() | Number[][][] | Returns an array of geometry coordinates. ||
|| [getFillRule](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getFillRule)() | String | Returns ID of the fill rule. ||
|| [getLength](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#getLength)() | Integer | Returns the number of contours in the geometry. ||
|| [insert](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#insert)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#insert-param-index), [path](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#insert-param-path)) | [IPolygonGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md) | Adds a new contour with the specified index. ||
|| [isFrozen](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#isFrozen)() | Boolean | Returns true if the object is in "frozen" mode, otherwise false.

Inherited from [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#isFrozen). ||
|| [remove](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#remove)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#remove-param-index)) | [ILinearRingGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILinearRingGeometryAccess.md) | Removes the contour with the specified index. ||
|| [set](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#set)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#set-param-index), [path](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#set-param-path)) | [IPolygonGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md) | Sets coordinates of the contour with the specified index. ||
|| [setCoordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#setCoordinates)([coordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#setCoordinates-param-coordinates)) | [IPolygonGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md) | Sets an array of geometry coordinates. ||
|| [setFillRule](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#setFillRule)([fillRule](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#setFillRule-param-fillRule)) | [IPolygonGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md) | Sets the polygon's fill rule. ||
|| [splice](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#splice)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#splice-param-index), [number](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPolygonGeometryAccess.md#splice-param-number)) | [ILinearRingGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILinearRingGeometryAccess.md)[] | Deletes a defined number of contours, starting from the specified index. New contours can be added in place of the deleted ones. Coordinates of the new contours can be passed as additional arguments after the "number" parameter. ||
|| [unfreeze](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#unfreeze)() | [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md) | Switches the object to active mode.

Inherited from [IFreezable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IFreezable.md#unfreeze). ||
|#

## Events details {#event_detail}

### change {#change}

Changed coordinates. Instance of the [Event](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md) class. Names of fields that are available via the [Event.get](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Event.md#get) method: 
- oldCoordinates - Old coordinates
- newCoordinates - New coordinates.
- oldFillRule - Old fill rule.
- newFillRule - New fill rule.

## Methods details {#method_detail}

### contains {#contains}

```javascript
{Boolean} contains(position)
```

Checks whether the passed point is located inside the polygon.

**Returns** indicator for whether the point belongs to the polygon.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`position`](#contains-param-position)[*](*star) | — | Type: Number[]

Coordinates of a point. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
var myPolygon = new ymaps.geometry.Polygon([
    [[69, 45], [68, 55], [86, 56]]
]);

// This method only works with a map that is set correctly.
myPolygon.options.setParent(myMap.options);
myPolygon.geometry.setMap(myMap);

// Checking whether the click point is inside the polygon with the geometry set above.
myMap.events.add('click', function (e) {
    alert(myPolygon.geometry.contains(e.get('coords')) ? 'Hit!' : 'Miss!');
});
```

### get {#get}

```javascript
{Number[][]} get(index)
```

**Returns** coordinates of the contour with the specified index.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#get-param-index)[*](*star) | — | Type: Integer

Contour index. ||
|#

\* Mandatory parameter/option.

### getChildGeometry {#getChildGeometry}

```javascript
{ILinearRingGeometryAccess} getChildGeometry(index)
```

Creates and returns an [ILinearRingGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILinearRingGeometryAccess.md) object for the specified contour.

**Returns** the geometry object that corresponds to the specified contour.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#getChildGeometry-param-index)[*](*star) | — | Type: Integer

Contour index. ||
|#

\* Mandatory parameter/option.

### getClosest {#getClosest}

```javascript
{Object} getClosest(anchorPosition)
```

Searches for the point nearest to "anchorPosition" on the polygon contour.

**Returns** an object with the following fields: 
- position - The point on the polygon contour that is nearest to "anchorPosition".
- distance - Distance from "anchorPosition" to "position".
- closestPointIndex - Index of the polygon vertex closest to "position".
- nextPointIndex - Index of the polygon vertex that follows "position".
- prevPointIndex - Index of the polygon vertex that precedes "position".
- pathIndex - Index of the polygon contour that the found point is associated with.
The "nextPointIndex" and "prevPointIndex" fields may be omitted if "position" coincides with one of the polygon vertexes.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`anchorPosition`](#getClosest-param-anchorPosition)[*](*star) | — | Type: Number[]

Coordinates of a point for which the nearest vertex on the polygon contour is calculated. ||
|#

\* Mandatory parameter/option.

**Example:**

```javascript
var myPolygon = new ymaps.Polygon([
    [[69, 45], [68, 55], [86, 56], [87, 43]],
    [[60, 48], [62, 60], [80, 62], [80, 48]]
]);
var myPoint = new ymaps.Placemark([74, 52]);
// Constructing the shortest normal from the polygon contour to the point.
var normalVec = new ymaps.Polyline([
    myPolygon.geometry.getClosest(myPoint.geometry.getCoordinates()).position,
    myPoint.geometry.getCoordinates()
]);

myMap.geoObjects
    .add(myPolygon)
    .add(myPoint)
    .add(normalVec);
```

### getCoordinates {#getCoordinates}

```javascript
{Number[][][]} getCoordinates()
```

**Returns** an array of geometry coordinates.

### getFillRule {#getFillRule}

```javascript
{String} getFillRule()
```

**Returns** ID of the fill rule.

**Example:**

```javascript
var myPolygon = new ymaps.Polygon([
    [[69, 45], [68, 55], [86, 56], [87, 43]],
    [[60, 48], [62, 60], [80, 62], [80, 48]]
]);
var middlePoint = [74, 52];

myMap.geoObjects.add(myPolygon);

// Checking a point that falls on the intersection of two contours
// by default (with the value fillRule == 'evenOdd') forms an opening (hole).
alert(myPolygon.geometry.contains(middlePoint)); // => false

// After setting the value to 'nonZero', all intersections are also "filled in",
// so now the point is in the polygon.
myPolygon.geometry.setFillRule('nonZero');
alert(myPolygon.geometry.contains(middlePoint)); // => true
```

### getLength {#getLength}

```javascript
{Integer} getLength()
```

**Returns** the number of contours in the geometry.

### insert {#insert}

```javascript
{IPolygonGeometryAccess} insert(index, path)
```

Adds a new contour with the specified index.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#insert-param-index)[*](*star) | — | Type: Integer

Contour index. ||
|| [`path`](#insert-param-path)[*](*star) | — | Type: Number[][]

Contour coordinates. ||
|#

\* Mandatory parameter/option.

### remove {#remove}

```javascript
{ILinearRingGeometryAccess} remove(index)
```

Removes the contour with the specified index.

**Returns** the deleted contour.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#remove-param-index)[*](*star) | — | Type: Integer

Contour index. ||
|#

\* Mandatory parameter/option.

### set {#set}

```javascript
{IPolygonGeometryAccess} set(index, path)
```

Sets coordinates of the contour with the specified index.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#set-param-index)[*](*star) | — | Type: Integer

Contour index. ||
|| [`path`](#set-param-path)[*](*star) | — | Type: Number[][]

Contour coordinates. ||
|#

\* Mandatory parameter/option.

### setCoordinates {#setCoordinates}

```javascript
{IPolygonGeometryAccess} setCoordinates(coordinates)
```

Sets an array of geometry coordinates.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`coordinates`](#setCoordinates-param-coordinates)[*](*star) | — | Type: Number[][][]

Geometry coordinates. ||
|#

\* Mandatory parameter/option.

### setFillRule {#setFillRule}

```javascript
{IPolygonGeometryAccess} setFillRule(fillRule)
```

Sets the polygon's fill rule.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`fillRule`](#setFillRule-param-fillRule)[*](*star) | — | Type: String

ID of the fill rule. ||
|#

\* Mandatory parameter/option.

### splice {#splice}

```javascript
{ILinearRingGeometryAccess[]} splice(index, number)
```

Deletes a defined number of contours, starting from the specified index. New contours can be added in place of the deleted ones. Coordinates of the new contours can be passed as additional arguments after the "number" parameter.

**Returns** the deleted contours.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`index`](#splice-param-index)[*](*star) | — | Type: Integer

The index to start from for removing and adding contours. ||
|| [`number`](#splice-param-number)[*](*star) | — | Type: Integer

The number of contours to be deleted. ||
|#

\* Mandatory parameter/option.

[*star]: Mandatory parameter/option.