MCPcopy Create free account
hub / github.com/shapely/shapely / set_precision

Function set_precision

shapely/_geometry.py:868–959  ·  view source on GitHub ↗

Return 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

(geometry, grid_size, mode="valid_output", **kwargs)

Source from the content-addressed store, hash-verified

866
867@multithreading_enabled
868def set_precision(geometry, grid_size, mode="valid_output", **kwargs):
869 """Return geometry with the precision set to a precision grid size.
870
871 By default, geometries use double precision coordinates (grid_size = 0).
872
873 Coordinates will be rounded if the precision grid specified is less precise
874 than the input geometry. Duplicated vertices will be dropped from lines and
875 polygons for grid sizes greater than 0. Line and polygon geometries may
876 collapse to empty geometries if all vertices are closer together than
877 ``grid_size`` or if a polygon becomes significantly narrower than
878 ``grid_size``. Spikes or sections in polygons narrower than ``grid_size``
879 after rounding the vertices will be removed, which can lead to multipolygons
880 or empty geometries. Z values, if present, will not be modified.
881
882 Notes
883 -----
884 * subsequent operations will always be performed in the precision of the
885 geometry with higher precision (smaller "grid_size"). That same precision
886 will be attached to the operation outputs.
887 * input geometries should be geometrically valid; unexpected results may
888 occur if input geometries are not.
889 * the geometry returned will be in
890 :ref:`mild canonical form <canonical-form>`, and the order of vertices can
891 change and should not be relied upon.
892 * returns None if geometry is None.
893
894 Parameters
895 ----------
896 geometry : Geometry or array_like
897 Geometry or geometries to set the precision of.
898 grid_size : float
899 Precision grid size. If 0, will use double precision (will not modify
900 geometry if precision grid size was not previously set). If this
901 value is more precise than input geometry, the input geometry will
902 not be modified.
903 mode : {'valid_output', 'pointwise', 'keep_collapsed'}, default 'valid_output'
904 This parameter determines the way a precision reduction is applied on
905 the geometry. There are three modes:
906
907 1. `'valid_output'` (default): The output is always valid. Collapsed
908 geometry elements (including both polygons and lines) are removed.
909 Duplicate vertices are removed.
910 2. `'pointwise'`: Precision reduction is performed pointwise. Output
911 geometry may be invalid due to collapse or self-intersection.
912 Duplicate vertices are not removed. In GEOS this option is called
913 NO_TOPO.
914
915 .. note::
916
917 'pointwise' mode requires at least GEOS 3.10. It is accepted in
918 earlier versions, but the results may be unexpected.
919 3. `'keep_collapsed'`: Like the default mode, except that collapsed
920 linear geometry elements are preserved. Collapsed polygonal input
921 elements are removed. Duplicate vertices are removed.
922 **kwargs
923 See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
924
925 See Also

Callers

nothing calls this directly

Calls 1

get_valueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…