set_precision(geometry, grid_size, mode='valid_output', **kwargs)#

Returns geometry with the precision set to a precision grid size.

By default, geometries use double precision coordinates (grid_size = 0).

Coordinates will be rounded if the precision grid specified is less precise than the input geometry. Duplicated vertices will be dropped from lines and polygons for grid sizes greater than 0. Line and polygon geometries may collapse to empty geometries if all vertices are closer together than grid_size or if a polygon becomes significantly narrower than grid_size. Spikes or sections in polygons narrower than grid_size after rounding the vertices will be removed, which can lead to multipolygons or empty geometries. Z values, if present, will not be modified.


  • subsequent operations will always be performed in the precision of the geometry with higher precision (smaller “grid_size”). That same precision will be attached to the operation outputs.

  • input geometries should be geometrically valid; unexpected results may occur if input geometries are not.

  • the geometry returned will be in mild canonical form, and the order of vertices can change and should not be relied upon.

  • returns None if geometry is None.

geometryGeometry or array_like

Precision grid size. If 0, will use double precision (will not modify geometry if precision grid size was not previously set). If this value is more precise than input geometry, the input geometry will not be modified.

mode{‘valid_output’, ‘pointwise’, ‘keep_collapsed’}, default ‘valid_output’

This parameter determines the way a precision reduction is applied on the geometry. There are three modes:

  1. ‘valid_output’ (default): The output is always valid. Collapsed geometry elements (including both polygons and lines) are removed. Duplicate vertices are removed.

  2. ‘pointwise’: Precision reduction is performed pointwise. Output geometry may be invalid due to collapse or self-intersection. Duplicate vertices are not removed. In GEOS this option is called NO_TOPO.


    ‘pointwise’ mode requires at least GEOS 3.10. It is accepted in earlier versions, but the results may be unexpected.

  3. ‘keep_collapsed’: Like the default mode, except that collapsed linear geometry elements are preserved. Collapsed polygonal input elements are removed. Duplicate vertices are removed.


See NumPy ufunc docs for other keyword arguments.

See also



>>> from shapely import LineString, Point
>>> set_precision(Point(0.9, 0.9), 1.0)
<POINT (1 1)>
>>> set_precision(Point(0.9, 0.9, 0.9), 1.0)
<POINT Z (1 1 0.9)>
>>> set_precision(LineString([(0, 0), (0, 0.1), (0, 1), (1, 1)]), 1.0)
<LINESTRING (0 0, 0 1, 1 1)>
>>> set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="valid_output")
>>> set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="pointwise")
<LINESTRING (0 0, 0 0, 0 0)>
>>> set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="keep_collapsed")
<LINESTRING (0 0, 0 0)>
>>> set_precision(None, 1.0) is None