All pages
Powered by GitBook
1 of 34

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

WKB

Learn about Well-Known Binary (WKB) in MariaDB Server. This section details how to represent and store geometric data in a binary format, essential for efficient spatial data exchange and storage.

AsWKB

Synonym for ST_AsBinary. Converts a geometry value from its internal format to its Well-Known Binary (WKB) representation.

A synonym for ST_AsBinary().

This page is licensed: CC BY-SA / Gnu FDL

GeomCollFromWKB

Synonym for ST_GeomCollFromWKB. Constructs a GeometryCollection value from its WKB representation and an optional SRID.

A synonym for ST_GeomCollFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

LineFromWKB

Synonym for ST_LineFromWKB. Constructs a LineString value from its WKB representation and an optional SRID.

A synonym for ST_LineFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

GeomFromWKB

Synonym for ST_GeomFromWKB. Constructs a geometry value of any type from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

GeometryFromWKB

Synonym for ST_GeomFromWKB. Constructs a geometry value of any type from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

LineStringFromWKB

Synonym for ST_LineFromWKB. Constructs a LineString value from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

AsBinary

Synonym for ST_AsBinary. Converts a geometry value from its internal format to its Well-Known Binary (WKB) representation.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

GeometryCollectionFromWKB

Synonym for ST_GeomCollFromWKB. Constructs a GeometryCollection value from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

ST_GeomFromWKB
ST_GeomFromWKB
ST_LineFromWKB
ST_AsBinary()
ST_GeomCollFromWKB

MultiPointFromWKB

Synonym for ST_MultiPointFromWKB. Constructs a MultiPoint value from its WKB representation and an optional SRID.

A synonym for MPointFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

ST_MultiPointFromWKB

Constructs a MultiLineString value using its WKB representation and an optional SRID.

A synonym for ST_GeomFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

PolyFromWKB

Synonym for ST_PolyFromWKB. Constructs a Polygon value from its WKB representation and an optional SRID.

A synonym for ST_PolyFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

PointFromWKB

Synonym for ST_PointFromWKB. Constructs a Point value from its WKB representation and an optional SRID.

A synonym for ST_PointFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

ST_MultiPolygonFromWKB

Constructs a MultiPolygon value using its WKB representation and an optional SRID.

A synonym for ST_GeomFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

MultiLineStringFromWKB

Synonym for ST_MultiLineStringFromWKB. Constructs a MultiLineString value from its WKB representation and an optional SRID.

A synonym for MLineFromWKB().

This page is licensed: CC BY-SA / Gnu FDL

ST_AsWKB

Synonym for ST_AsBinary. Converts a geometry value from its internal format to its Well-Known Binary (WKB) representation.

A synonym for ST_AsBinary().

This page is licensed: CC BY-SA / Gnu FDL

ST_LineStringFromWKB

Synonym for ST_LineFromWKB. Constructs a LineString value from its WKB representation and an optional SRID.

A synonym for ST_LineFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

ST_GeometryFromWKB

Synonym for ST_GeomFromWKB. Constructs a geometry value of any type from its WKB representation and an optional SRID.

A synonym for ST_GeomFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

ST_GeomFromWKB

Constructs a geometry value of any type using its WKB representation and an optional SRID.

Syntax

Description

Constructs a geometry value of any type using its representation and SRID.

ST_GeomCollFromWKB

Constructs a GeometryCollection value from its WKB representation and an optional SRID.

Syntax

Description

Constructs a GEOMETRYCOLLECTION value using its representation and SRID.

ST_GeometryCollectionFromWKB

Synonym for ST_GeomCollFromWKB. Constructs a GeometryCollection value from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

MultiPolygonFromWKB

Synonym for ST_MultiPolygonFromWKB. Constructs a MultiPolygon value from its WKB representation and an optional SRID.

Synonym for .

This page is licensed: CC BY-SA / Gnu FDL

ST_LineFromWKB

Constructs a LineString value using its WKB representation and an optional SRID.

Syntax

Description

Constructs a LINESTRING value using its representation and SRID.

Well-Known Binary (WKB) Format

Understand the standard binary format for geometry. This overview explains how WKB represents spatial data types for storage and exchange.

WKB stands for Well-Known Binary, a format for representing geographical and geometrical data.

WKB uses 1-byte unsigned integers, 4-byte unsigned integers, and 8-byte double-precision numbers.

  • The first byte indicates the byte order. 00 for big endian, or 01 for little endian.

  • The next 4 bytes indicate the geometry type. Values from 1 to 7 indicate whether the type is Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, or GeometryCollection respectively.

ST_PolygonFromWKB

Synonym for ST_PolyFromWKB. Constructs a Polygon value from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

ST_MPolyFromWKB

Synonym for ST_MultiPolygonFromWKB. Constructs a MultiPolygon value from its WKB representation and an optional SRID.

A synonym for .

This page is licensed: CC BY-SA / Gnu FDL

ST_GeomCollFromWKB
MPolyFromWKB
ST_PolyFromWKB
ST_GeomFromWKB

PolygonFromWKB

Synonym for ST_PolyFromWKB. Constructs a Polygon value from its WKB representation and an optional SRID.

A synonym for ST_PolyFromWKB.

This page is licensed: CC BY-SA / Gnu FDL

ST_GeomFromWKB(), ST_GeometryFromWKB(), GeomFromWKB() and GeometryFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_GeomFromWKB(wkb[,srid])
ST_GeometryFromWKB(wkb[,srid])
GeomFromWKB(wkb[,srid])
GeometryFromWKB(wkb[,srid])
WKB
ST_GeomCollFromWKB(), ST_GeometryCollectionFromWKB(), GeomCollFromWKB() and GeometryCollectionFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_GeomCollFromWKB(wkb[,srid])
ST_GeometryCollectionFromWKB(wkb[,srid])
GeomCollFromWKB(wkb[,srid])
GeometryCollectionFromWKB(wkb[,srid])
WKB
ST_LineFromWKB(), LineFromWKB(), ST_LineStringFromWKB(), and LineStringFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_LineFromWKB(wkb[,srid])
LineFromWKB(wkb[,srid])
ST_LineStringFromWKB(wkb[,srid])
LineStringFromWKB(wkb[,srid])
WKB
The 8-byte floats represent the co-ordinates.

Take the following example, a sequence of 21 bytes each represented by two hex digits:

  • It's big endian

    • 000000000140000000000000004010000000000000

  • It's a POINT

    • 000000000140000000000000004010000000000000

  • The X co-ordinate is 2.0

    • 000000000140000000000000004010000000000000

  • The Y-co-ordinate is 4.0

    • 000000000140000000000000004010000000000000

This page is licensed: CC BY-SA / Gnu FDL

000000000140000000000000004010000000000000
SET @g = ST_AsBinary(ST_LineFromText('LINESTRING(0 4, 4 6)'));

SELECT ST_AsText(ST_GeomFromWKB(@g));
+-------------------------------+
| ST_AsText(ST_GeomFromWKB(@g)) |
+-------------------------------+
| LINESTRING(0 4,4 6)           |
+-------------------------------+
SET @g = ST_AsBinary(ST_GeomFromText('GEOMETRYCOLLECTION(
   POLYGON((5 5,10 5,10 10,5 5)),POINT(10 10))'));

SELECT ST_AsText(ST_GeomCollFromWKB(@g));
+----------------------------------------------------------------+
| ST_AsText(ST_GeomCollFromWKB(@g))                              |
+----------------------------------------------------------------+
| GEOMETRYCOLLECTION(POLYGON((5 5,10 5,10 10,5 5)),POINT(10 10)) |
+----------------------------------------------------------------+
SET @g = ST_AsBinary(ST_LineFromText('LineString(0 4,4 6)'));

SELECT ST_AsText(ST_LineFromWKB(@g)) AS l;
+---------------------+
| l                   |
+---------------------+
| LINESTRING(0 4,4 6) |
+---------------------+

ST_AsBinary

Converts a value in internal geometry format to its WKB representation and returns the binary result.

Syntax

ST_AsBinary(g)
AsBinary(g)
ST_AsWKB(g)
AsWKB(g)

Description

Converts a value in internal geometry format to its WKB representation and returns the binary result.

ST_AsBinary(), AsBinary(), ST_AsWKB() and AsWKB() are synonyms,

Examples

This page is licensed: GPLv2, originally from

MPolyFromWKB

Synonym for ST_MultiPolygonFromWKB. Constructs a MultiPolygon value from its WKB representation and an optional SRID.

Syntax

MPolyFromWKB(wkb[,srid])
MultiPolygonFromWKB(wkb[,srid])

Description

Constructs a MULTIPOLYGON value using its WKB representation and SRID.

MPolyFromWKB() and MultiPolygonFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from

MPointFromWKB

Synonym for ST_MultiPointFromWKB. Constructs a MultiPoint value from its WKB representation and an optional SRID.

Syntax

MPointFromWKB(wkb[,srid])
MultiPointFromWKB(wkb[,srid])

Description

Constructs a MULTIPOINT value using its WKB representation and SRID.

MPointFromWKB() and MultiPointFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from

ST_PolyFromWKB

Constructs a Polygon value using its WKB representation and an optional SRID.

Syntax

ST_PolyFromWKB(wkb[,srid])
ST_PolygonFromWKB(wkb[,srid])
PolyFromWKB(wkb[,srid])
PolygonFromWKB(wkb[,srid])

Description

Constructs a POLYGON value using its WKB representation and SRID.

ST_PolyFromWKB(), ST_PolygonFromWKB(), PolyFromWKB() and PolygonFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from

ST_PointFromWKB

Constructs a Point value using its WKB representation and an optional SRID.

Syntax

Description

Constructs a value using its representation and .

SET @poly = ST_GeomFromText('POLYGON((0 0,0 1,1 1,1 0,0 0))');
SELECT ST_AsBinary(@poly);

SELECT ST_AsText(ST_GeomFromWKB(ST_AsWKB(@poly)));
+--------------------------------------------+
| ST_AsText(ST_GeomFromWKB(ST_AsWKB(@poly))) |
+--------------------------------------------+
| POLYGON((0 0,0 1,1 1,1 0,0 0))             |
+--------------------------------------------+
fill_help_tables.sql
SET @g = ST_AsBinary(MPointFromText('MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))'));

SELECT ST_AsText(MPolyFromWKB(@g))\G
*************************** 1. row ***************************
ST_AsText(MPolyFromWKB(@g)): MULTIPOLYGON(((28 26,28 0,84 0,84 42,28 26),(52 18,66 23,73 9,48 6,52 18)),((59 18,67 18,67 13,59 13,59 18)))
fill_help_tables.sql
SET @g = ST_AsBinary(MPointFromText('MultiPoint( 1 1, 2 2, 5 3, 7 2, 9 3, 8 4, 6 6, 6 9, 4 9, 1 5 )'));

SELECT ST_AsText(MPointFromWKB(@g));
+-----------------------------------------------------+
| ST_AsText(MPointFromWKB(@g))                        |
+-----------------------------------------------------+
| MULTIPOINT(1 1,2 2,5 3,7 2,9 3,8 4,6 6,6 9,4 9,1 5) |
+-----------------------------------------------------+
fill_help_tables.sql
SET @g = ST_AsBinary(ST_PolyFromText('POLYGON((1 1,1 5,4 9,6 9,9 3,7 2,1 1))'));

SELECT ST_AsText(ST_PolyFromWKB(@g)) AS p;
+----------------------------------------+
| p                                      |
+----------------------------------------+
| POLYGON((1 1,1 5,4 9,6 9,9 3,7 2,1 1)) |
+----------------------------------------+
fill_help_tables.sql
ST_PointFromWKB() and PointFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from fill_help_tables.sql

ST_PointFromWKB(wkb[,srid])
PointFromWKB(wkb[,srid])
POINT
WKB
SRID
SET @g = ST_AsBinary(ST_PointFromText('POINT(0 4)'));

SELECT ST_AsText(ST_PointFromWKB(@g)) AS p;
+------------+
| p          |
+------------+
| POINT(0 4) |
+------------+

MLineFromWKB

Synonym for ST_MultiLineStringFromWKB. Constructs a MultiLineString value from its WKB representation and an optional SRID.

Syntax

MLineFromWKB(wkb[,srid])
MultiLineStringFromWKB(wkb[,srid])

Description

Constructs a MULTILINESTRING value using its WKB representation and SRID.

MLineFromWKB() and MultiLineStringFromWKB() are synonyms.

Examples

This page is licensed: GPLv2, originally from

SET @g = ST_AsBinary(MLineFromText('MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48))'));

SELECT ST_AsText(MLineFromWKB(@g));
+--------------------------------------------------------+
| ST_AsText(MLineFromWKB(@g))                            |
+--------------------------------------------------------+
| MULTILINESTRING((10 48,10 21,10 0),(16 0,16 23,16 48)) |
+--------------------------------------------------------+
fill_help_tables.sql

ST_MPointFromWKB

Synonym for ST_MultiPointFromWKB. Constructs a MultiPoint value from its WKB representation and an optional SRID.

A synonym for ST_GeomFromWKB.

This page is licensed: CC BY-SA / Gnu FDL