# How the GeometryCollectionFromWKB() function works in Mariadb?

The `GeometryCollectionFromWKB()`

function is a spatial function that creates a geometry collection from a well-known binary (WKB) representation.

The `GeometryCollectionFromWKB()`

function is a spatial function that creates a geometry collection from a well-known binary (WKB) representation. It is an alias for the `GeomCollFromWKB()`

function, which means they have the same functionality and syntax. It can be useful for storing or manipulating multiple geometries of different types as a single object.

## Syntax

The syntax of the `GeometryCollectionFromWKB()`

function is as follows:

```
GeometryCollectionFromWKB(wkb, [srid])
```

The `wkb`

parameter is a binary string that contains the well-known binary representation of the geometry collection. The function returns a geometry collection object that contains the geometries specified by the WKB string.

The optional `srid`

parameter is an integer that specifies the spatial reference system identifier (SRID) of the geometry collection. The function assigns the SRID to the geometry collection object if the parameter is provided. Otherwise, the SRID is set to 0 by default.

## Examples

The following example shows how to use the `GeometryCollectionFromWKB()`

function to create a geometry collection from a WKB string.

```
SELECT AsText(GeometryCollectionFromWKB(AsWKB(GEOMETRYCOLLECTION(POINT(1, 1), LINESTRING(POINT(2, 2), POINT(3, 3)))))) AS geom;
```

The output is:

```
+----------------------------------------------------+
| geom |
+----------------------------------------------------+
| GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(2 2,3 3)) |
+----------------------------------------------------+
```

The function returns a geometry collection object that contains a point, a linestring, and a polygon. The object is stored as a binary string in the internal format of Mariadb.

## Related Functions

Some of the functions that are related to the `GeometryCollectionFromWKB()`

function are:

`GeomCollFromWKB()`

: This function creates a geometry collection from a well-known binary (WKB) representation. It is the same as the`GeometryCollectionFromWKB()`

function, which means they have the same functionality and syntax. For example,`GeomCollFromWKB(0x0000000007000000030101000000000000000000F03F000000000000F03F01020000000200000000000000000000400000000000004040000000000000404003000000000500000000000000000010400000000000001040000000000000104000000000000014400000000000001440000000000000144000000000000010400000000000001040000000000000104000000000000001040)`

returns the same geometry collection object as the example 1.`GeomCollFromText()`

: This function creates a geometry collection from a well-known text (WKT) representation. It is similar to the`GeometryCollectionFromWKB()`

function, except that it takes a text string instead of a binary string as the input. For example,`GeomCollFromText('GEOMETRYCOLLECTION(POINT(1 1), LINESTRING(2 2, 3 3), POLYGON((4 4, 5 4, 5 5, 4 5, 4 4)))')`

returns the same geometry collection object as the example 1.`NumGeometries()`

: This function returns the number of geometries in a geometry collection. It can be used to iterate over the elements of a geometry collection. For example,`NumGeometries(GeometryCollectionFromWKB(0x0000000007000000030101000000000000000000F03F000000000000F03F01020000000200000000000000000000400000000000004040000000000000404003000000000500000000000000000010400000000000001040000000000000104000000000000014400000000000001440000000000000144000000000000010400000000000001040000000000000104000000000000001040))`

returns 3.

## Conclusion

The `GeometryCollectionFromWKB()`

function is a useful function for creating a geometry collection from a well-known binary representation. It can be used for storing or manipulating multiple geometries of different types as a single object. It can also be combined with other spatial functions to achieve various spatial operations.