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

# geometry.LineString

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

"Polyline" geometry.

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

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

## Constructor {#constructor-summary}

```javascript
geometry.LineString([coordinates[, options]])
```

**Parameters:**

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

Geometry coordinates. ||
|| [`options`](#param-options) | — | Type: Object

Geometry options. ||
|| [`options.coordRendering`](#param-options.coordRendering) | — | Type: String

String ID defining the algorithm for recalculating geometry coordinates as pixel coordinates. For the "Polyline" geometry, can accept one of two values: 
- shortestPath - Algorithm that considers projection cycling on the axes and generates pixel coordinates so that 	the distance between two neighboring points is minimal.
- straightPath - Algorithm that does not consider projection cycling. ||
|| [`options.geodesic`](#param-options.geodesic) | false | Type: Boolean

Enables display using geodesic lines. ||
|| [`options.pixelRendering`](#param-options.pixelRendering) | "jumpy" | Type: String

Method for calculating pixel coordinates of the shape in cycled projections. This option accepts one of the following values: 
- jumpy - The shape is placed as close as possible to the center of the map viewport, and can "jump" 	when the map is being moved.
- static - The shape is always located in the initial world and does not move when the map is moved. ||
|| [`options.projection`](#param-options.projection) | — | Type: [IProjection](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IProjection.md)

Projection. ||
|| [`options.simplification`](#param-options.simplification) | true | Type: Boolean

Enables simplification during rendering of a pixel geometry. ||
|#


**Example:**

```javascript
// Instantiates the point geometry (specifying coordinates).
var lineStringGeometry = new ymaps.geometry.LineString([
    [30, 50], [31, 51], [32, 52]
]);
// Instantiating the geo object and passing our geometry to the constructor.
var lineStringGeoObject = new ymaps.GeoObject({ geometry: lineStringGeometry });

lineStringGeometry.events.add('change', function (e) {
   alert([e.get('newCoordinates'), e.get('oldCoordinates')]);
});

// Changing vertexes via the geo object's "geometry" property (setting new coordinates for the second point on the line).
lineStringGeoObject.geometry
    .set(1, [20, 40])
    .remove(2);
// Or directly.
lineStringGeometry
    .set(1, [20, 40])
    .remove(2);
// You can also access lineStringGeometry via lineStringGeoObject.geometry.
```

## Fields {#properties-summary}

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

Inherited from [IEventEmitter](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events). ||
|| [options](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options) | [IOptionManager](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IOptionManager.md)| Options manager.

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

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [change](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.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.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#event-change). ||
|| [mapchange](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#event-mapchange)| Map reference changed. 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: 
- oldMap - Old map.
- newMap - New map.

Inherited from [IGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#event-mapchange). ||
|| [optionschange](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange)| Change to the object options.

Inherited from [ICustomizable](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange). ||
|| [pixelgeometrychange](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#event-pixelgeometrychange)| The pixel geometry changed. 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: 
- pixelGeometry - New [IPixelGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPixelGeometry.md) pixel geometry.

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

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [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/ILineStringGeometryAccess.md#get)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#get-param-index)) | Number[]
| Returns coordinates of the point with the specified index.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#get). ||
|| [getBounds](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getBounds)() | Number[][]\|null
| Returns coordinates of the two opposite corners of the area that surrounds the geometry. The first item in the array is the southwest corner of the area; the second item is the northeast corner.

Inherited from [IGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getBounds). ||
|| [getChildGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getChildGeometry)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getChildGeometry-param-index)) | [IPointGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPointGeometryAccess.md)
| Creates and returns an [IPointGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPointGeometryAccess.md) object for the specified vertex on the polyline.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getChildGeometry). ||
|| [getClosest](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getClosest)([anchorPosition](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getClosest-param-anchorPosition)) | Object
| Searches for a point on the polyline closest to the anchorPosition.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getClosest). ||
|| [getCoordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getCoordinates)() | Number[][]
| Returns an array of geometry coordinates.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getCoordinates). ||
|| [getDistance](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geometry.LineString.md#getDistance)(\[[from](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geometry.LineString.md#getDistance-param-from)[, [to](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geometry.LineString.md#getDistance-param-to)]]) | Number
| Returns the length of the specified line segment, or the whole line, if the delimiter is not set. ||
|| [getLength](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getLength)() | Integer
| Returns the number of points in the geometry.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#getLength). ||
|| [getMap](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getMap)() | [Map](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map.md)\|null
| Returns the current map.

Inherited from [IGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getMap). ||
|| [getPixelGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getPixelGeometry)(\[[options](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getPixelGeometry-param-options)]) | [IPixelGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IPixelGeometry.md)
| Returns the pixel geometry corresponding to the given geometry, its options, and the map state.

Inherited from [IGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#getPixelGeometry). ||
|| [getType](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometry.md#getType)() | String
| Returns the "LineString" string.

Inherited from [ILineStringGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometry.md#getType). ||
|| [insert](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#insert)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#insert-param-index), [coordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#insert-param-coordinates)) | [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md)
| Adds a new point with the specified index.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#insert). ||
|| [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/ILineStringGeometryAccess.md#remove)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#remove-param-index)) | Number[]
| Removes the point with the specified index.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#remove). ||
|| [set](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#set)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#set-param-index), [coordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#set-param-coordinates)) | [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md)
| Sets coordinates of the point with the specified index.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#set). ||
|| [setCoordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#setCoordinates)([coordinates](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#setCoordinates-param-coordinates)) | [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md)
| Sets an array of geometry coordinates.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#setCoordinates). ||
|| [setMap](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#setMap)([map](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#setMap-param-map))| Sets the map.

Inherited from [IGeometry](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IGeometry.md#setMap). ||
|| [splice](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#splice)([index](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#splice-param-index), [number](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#splice-param-number)) | Number[][]
| Deletes a defined number of points, starting from the specified index. New points can be added in place of the deleted ones. Coordinates of the new points can be passed as additional arguments after the "number" parameter.

Inherited from [ILineStringGeometryAccess](https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ILineStringGeometryAccess.md#splice). ||
|| [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). ||
|#

## Methods details {#method_detail}

### getDistance {#getDistance}

```javascript
{Number} getDistance([from[, to]])
```

**Returns** the length of the specified line segment, or the whole line, if the delimiter is not set.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`from`](#getDistance-param-from) | 0 | Type: Number

Specifies the start point for calculating the length. ||
|| [`to`](#getDistance-param-to) | — | Type: Number

Specifies the end point for calculating the length. If not specified, the last point is used. ||
|#


**Example:**

```javascript
var lineStringGeometry = new ymaps.geometry.LineString([[30, 50], [31, 51], [32, 52]]);
var geoObject = new ymaps.GeoObject({ geometry: lineStringGeometry });
myMap.geoObjects.add(geoObject);
// The total length of the line.
console.log(geoObject.geometry.getDistance());
// The length of the segment from the first to the second point.
console.log(geoObject.geometry.getDistance(0, 1));
```
