linestrings(coords, y=None, z=None, indices=None, handle_nan=HandleNaN.allow, out=None, **kwargs)#

Create an array of linestrings.

This function will raise an exception if a linestring contains less than two points.


An array of lists of coordinate tuples (2- or 3-dimensional) or, if y is provided, an array of lists of x coordinates

yarray_like, optional
zarray_like, optional
indicesarray_like, optional

Indices into the target array where input coordinates belong. If provided, the coords should be 2D with shape (N, 2) or (N, 3) and indices should be an array of shape (N,) with integers in increasing order. Missing indices result in a ValueError unless out is provided, in which case the original value in out is kept.

handle_nanshapely.HandleNaN or {‘allow’, ‘skip’, ‘error’}, default ‘allow’

Specifies what to do when a NaN or Inf is encountered in the coordinates:

  • ‘allow’: the geometries are created with NaN or Inf coordinates. Note that this can result in unexpected behaviour in subsequent operations, and generally it is discouraged to have non-finite coordinate values. One can use this option if you know all coordinates are finite and want to avoid the overhead of checking for this.

  • ‘skip’: the coordinate pairs where any of x, y or z values are NaN or Inf are ignored. If this results in ignoring all coordinates for one geometry, an empty geometry is created.

  • ‘error’: if any NaN or Inf is detected in the coordinates, a ValueError is raised. This option ensures that the created geometries have all finite coordinate values.

    Added in version 2.1.0.

outndarray, optional

An array (with dtype object) to output the geometries into.


See NumPy ufunc docs for other keyword arguments. Ignored if indices is provided.


  • Usage of the y and z arguments will prevents lazy evaluation in dask. Instead provide the coordinates as a (..., 2) or (..., 3) array using only coords.


>>> linestrings([[[0, 1], [4, 5]], [[2, 3], [5, 6]]]).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6)>]
>>> linestrings([[0, 1], [4, 5], [2, 3], [5, 6], [7, 8]], indices=[0, 0, 1, 1, 1]).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6, 7 8)>]