round_geometry¶
- geodetic_engine.geodesy.geometry.round_geometry(geometry, decimals=None, *, grid_size=None, validate='warn')[source]¶
Round a geometry’s coordinates, or those of an array of geometries.
decimalsrounds every coordinate half up, by its shortest decimal form: with 2 decimals,2.675is2.68and-0.125is-0.13.-0.0becomes0.0. Every vertex is kept, which can make a polygon invalid.grid_sizesnaps to a grid instead, withshapely.set_precision, which keeps polygons valid but can remove vertices. Rounding twice gives what rounding once does.- Parameters:
geometry (
Any) – A Shapely geometry or None, or a sequence or array of them.decimals (
int|Sequence[int|None] |None, default:None) – One number for every axis, or one per axis in the order x, y, z, m, None keeping that axis.grid_size (
float|None, default:None) – The grid to snap to, instead ofdecimals.validate (
Literal['off','warn','raise'], default:"warn") – What to do when rounding todecimalsmakes a valid geometry invalid:"off","warn"(aGeometryValidityWarning) or"raise".
- Return type:
- Returns:
The rounded geometry, or a numpy array of them.
- Raises:
GeometryError – If
validate="raise"and a geometry became invalid, orgrid_sizeis asked for geometries with M values.ValueError – If both
decimalsandgrid_sizeare given, or either is not valid.
Example
>>> round_geometry(shapely.Point(2.675, -0.125), 2).wkt 'POINT (2.68 -0.13)'