shapely.to_wkt#
- to_wkt(geometry, rounding_precision=6, trim=True, output_dimension=None, old_3d=False, **kwargs)#
Convert to the Well-Known Text (WKT) representation of a Geometry.
The Well-known Text format is defined in the OGC Simple Features Specification for SQL.
The following limitations apply to WKT serialization:
only simple empty geometries can be 3D, empty collections are always 2D
- Parameters:
- geometryGeometry or array_like
Geometry or geometries to convert to WKT.
- rounding_precisionint, default 6
The rounding precision when writing the WKT string. Set to a value of -1 to indicate the full precision.
- trimbool, default True
If True, trim unnecessary decimals (trailing zeros).
- output_dimensionint, default None
The output dimension for the WKT string. Supported values are 2, 3 and 4 for GEOS 3.12+. Default None will automatically choose 3 or 4, depending on the version of GEOS. Specifying 3 means that up to 3 dimensions will be written but 2D geometries will still be represented as 2D in the WKT string.
- old_3dbool, default False
Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT (ie. “POINT Z (10 20 30)”) is returned, but with
old_3d=True
the WKT will be formatted in the style “POINT (10 20 30)”.- **kwargs
See NumPy ufunc docs for other keyword arguments.
Notes
The defaults differ from the default of the GEOS library. To mimic this, use:
to_wkt(geometry, rounding_precision=-1, trim=False, output_dimension=2)
Examples
>>> from shapely import Point >>> to_wkt(Point(0, 0)) 'POINT (0 0)' >>> to_wkt(Point(0, 0), rounding_precision=3, trim=False) 'POINT (0.000 0.000)' >>> to_wkt(Point(0, 0), rounding_precision=-1, trim=False) 'POINT (0.0000000000000000 0.0000000000000000)' >>> to_wkt(Point(1, 2, 3), trim=True) 'POINT Z (1 2 3)' >>> to_wkt(Point(1, 2, 3), trim=True, output_dimension=2) 'POINT (1 2)' >>> to_wkt(Point(1, 2, 3), trim=True, old_3d=True) 'POINT (1 2 3)'