to_wkb(geometry, hex=False, output_dimension=3, byte_order=- 1, include_srid=False, flavor='extended', **kwargs)#

Converts to the Well-Known Binary (WKB) representation of a Geometry.

The Well-Known Binary format is defined in the OGC Simple Features Specification for SQL.

The following limitations apply to WKB serialization:

  • linearrings will be converted to linestrings

  • a point with only NaN coordinates is converted to an empty point

  • for GEOS <= 3.7, empty points are always serialized to 3D if output_dimension=3, and to 2D if output_dimension=2

  • for GEOS == 3.8, empty points are always serialized to 2D

geometryGeometry or array_like
hexbool, default False

If true, export the WKB as a hexidecimal string. The default is to return a binary bytes object.

output_dimensionint, default 3

The output dimension for the WKB. Supported values are 2 and 3. Specifying 3 means that up to 3 dimensions will be written but 2D geometries will still be represented as 2D in the WKB represenation.

byte_orderint, default -1

Defaults to native machine byte order (-1). Use 0 to force big endian and 1 for little endian.

include_sridbool, default False

If True, the SRID is be included in WKB (this is an extension to the OGC WKB specification). Not allowed when flavor is “iso”.

flavor{“iso”, “extended”}, default “extended”

Which flavor of WKB will be returned. The flavor determines how extra dimensionality is encoded with the type number, and whether SRID can be included in the WKB. ISO flavor is “more standard” for 3D output, and does not support SRID embedding. Both flavors are equivalent when output_dimension=2 (or with 2D geometries) and include_srid=False. The from_wkb function can read both flavors.


For other keyword-only arguments, see the NumPy ufunc docs.


>>> from shapely import Point
>>> point = Point(1, 1)
>>> to_wkb(point, byte_order=1)
>>> to_wkb(point, hex=True, byte_order=1)