shapely.set_coordinates

shapely.set_coordinates#

set_coordinates(geometry, coordinates)#

Adapts the coordinates of a geometry array in-place.

If the coordinates array has shape (N, 2), all returned geometries will be two-dimensional, and the third dimension will be discarded, if present. If the coordinates array has shape (N, 3), the returned geometries preserve the dimensionality of the input geometries.

Warning

The geometry array is modified in-place! If you do not want to modify the original array, you can do set_coordinates(arr.copy(), newcoords).

Parameters:
geometryGeometry or array_like
coordinates: array_like

See also

transform

Returns a copy of a geometry array with a function applied to its coordinates.

Examples

>>> from shapely import LineString, Point
>>> set_coordinates(Point(0, 0), [[1, 1]])
<POINT (1 1)>
>>> set_coordinates([Point(0, 0), LineString([(0, 0), (0, 0)])], [[1, 2], [3, 4], [5, 6]]).tolist()
[<POINT (1 2)>, <LINESTRING (3 4, 5 6)>]
>>> set_coordinates([None, Point(0, 0)], [[1, 2]]).tolist()
[None, <POINT (1 2)>]

Third dimension of input geometry is discarded if coordinates array does not include one:

>>> set_coordinates(Point(0, 0, 0), [[1, 1]])
<POINT (1 1)>
>>> set_coordinates(Point(0, 0, 0), [[1, 1, 1]])
<POINT Z (1 1 1)>