> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ocient.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Conversion Functions

export const OcientGeo = "OcientGeo™";

export const IETF = "IETF®";

{OcientGeo} conversion functions transform a specified operand to a different data type.

## ST\_ASBINARY

Alias of ST\_ASWKB.

Returns the well-known binary (WKB) representation of the specified geography.

**Syntax**

```sql SQL theme={null}
ST_ASBINARY(geo [, XDR_or_NDR ] )
```

| **Argument** | **Data** **Type**                   | **Description**                                                                                                                                                                                                           |
| ------------ | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `geo`        | `POINT`, `LINESTRING`, or `POLYGON` | The geospatial object used to calculate the dimensions.                                                                                                                                                                   |
| `XDR_or_NDR` | `CHAR`                              | Optional. This argument determines whether the resulting WKB is in little endian (NDR) or big endian (XDR) format. <br />If you specify this argument, it must be either `XDR` or `NDR`. Otherwise, it defaults to `NDR`. |

**Example**

```sql SQL theme={null}
SELECT ST_ASBINARY(ST_POINT(2, 2), 'NDR');
```

*Output*: `010100000000000000000000400000000000000040`

## ST\_ASGEOJSON

Returns the GeoJSON representation of the specified geography using the [IETF standards](https://datatracker.ietf.org/doc/html/rfc7946).

```sql SQL theme={null}
 ST_ASGEOJSON( geo [, planar_conversion ] )
```

| **Argument**        | **Data** **Type**                   | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------- | ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `geo`               | `POINT`, `LINESTRING`, or `POLYGON` | The geospatial object used to create a GeoJSON representation.  <br />ℹ️ The GeoJSON specification has certain requirements for a `LINESTRING` and `POLYGON` . <br />In keeping with this specification, a `POLYGON` instance that represents a `LINESTRING` results in a `LINESTRING` GeoJSON instance. <br />Similarly, a `POLYGON` instance that represents a  `POINT` results in a `POINT` GeoJSON instance. <br />A `LINESTRING` instance that represents a `POINT` results in a `POINT` GeoJSON instance. <br />Unlike the GeoJSON specification, a specified `POLYGON` does not need to follow the Right-Hand Rule. If a specified `POLYGON` contains any holes that are not valid `POLYGON` objects, then the function omits those holes in the resulting GeoJSON instance.                                                                                                          |
| `planar_conversion` | `BOOLEAN`                           | Optional. A Boolean value that determines if the geodesic edges of the specified geography are converted to planar representation before the function applies the GeoJSON format. {IETF} standards state that all GeoJSON objects are to be interpreted as explicitly planar. This argument allows preservation of the original geodesic shape.<br />If `planar_conversion` is specified `TRUE`, points will be added such that the resulting GeoJSON represents a planar shape within 10m of the original geospatial object. Additionally, if the original geospatial object crossed the international dateline, it will be split at the point where it crosses. This will generate a GeoJSON object of either `MultiLineString` or `MultiPolygon`  type, depending on the original type of the geospatial object.<br />If you do not specify this argument, the value defaults to `FALSE`. |

**Examples**

This example converts a `POINT` value into a GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_POINT(2, 2), false);
```

*Output*:

```Text Text theme={null}
{"type":"Point","coordinates":[2,2]}
```

This example converts an empty `POINT` value.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_POINTFROMTEXT('POINT EMPTY'), false);
```

*Output*:

```Text Text theme={null}
{"type":"Point","coordinates":[]}
```

This example converts a `LINESTRING` value into a GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_LINESTRING(ST_POINT(1.234, 2),ST_POINT(3.456, 5));
```

*Output*:

```Text Text theme={null}
{"type":"LineString","coordinates":[[1.234,2],[3.456,5]]}
```

This example again converts a `LINESTRING` value.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_LINESTRING(ARRAY[ST_POINT(1.234, 2)]);
```

*Output*:

```Text Text theme={null}
{"type":"Point","coordinates":[1.234,2]}
```

This example converts an empty `LINESTRING` value into a GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_LINEFROMTEXT('LINESTRING EMPTY'), false);
```

*Output*:

```Text Text theme={null}
{"type":"LineString","coordinates":[]}
```

This example converts a `POLYGON` value into a GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(
    ST_POLYGON(
        ARRAY [ST_POINT(1.234, 2),ST_POINT(3.456, 5),ST_POINT(5.678,         2),ST_POINT(1.234, 2)],
        ARRAY [ARRAY[ST_POINT(2,2.5),ST_POINT(2.1,2.6),ST_POINT(2.2,2.5),ST_POINT(2,2.5)],
        ARRAY [ST_POINT(3,2.5),ST_POINT(3.1,2.6),ST_POINT(3.2,2.5),ST_POINT(3,2.5)]]), false);
```

*Output*:

```Text Text theme={null}
{"type":"Polygon","coordinates":[[[1.234,2],[3.456,5],[5.678,2],[1.234,2]],[[2,2.5],[2.1,2.6],[2.2,2.5],[2,2.5]],[[3,2.5],[3.1,2.6],[3.2,2.5],[3,2.5]]]}
```

This example again converts a `POLYGON` value.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(
    ST_POLYGON(
        ARRAY [ST_POINT(1.234, 2),ST_POINT(3.456, 5),ST_POINT(5.678, 2),ST_POINT(1.234, 2)],
        ARRAY [ARRAY[ST_POINT(2,2.5),ST_POINT(2.1,2.6),ST_POINT(2.2,2.5),ST_POINT(3,2.5)],
        ARRAY [ST_POINT(3,2.5),ST_POINT(3.2,2.5),ST_POINT(3,2.5)]]), false);
```

*Output*:

```Text Text theme={null}
{"type":"Polygon","coordinates":[[[1.234,2],[3.456,5],[5.678,2],[1.234,2]]]}
```

This example converts a two-point `POLYGON`, which results in a `LINESTRING` type in the GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(
        ST_POLYGON(
            ST_LINESTRING(ST_POINT(1.234, 2), ST_POINT(3.456, 5))),
        false);
```

*Output*:

```Text Text theme={null}
{"type":"LineString","coordinates":[[1.234,2],[3.456,5]]}
```

This example converts a single-point `POLYGON`, which results in a `POINT` type in the GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_POLYGON(ST_POINT(1.234, 2)), false);
```

*Output*:

```Text Text theme={null}
{"type":"Point","coordinates":[1.234,2]}
```

This example converts an empty `POLYGON` value into a GeoJSON representation.

```sql SQL theme={null}
SELECT ST_ASGEOJSON(ST_POLYGONFROMTEXT('POLYGON EMPTY'), false);
```

*Output*:

```Text Text theme={null}
{"type":"Polygon","coordinates":[]}
```

## ST\_ASLATLONTEXT

Returns a string that represents geographic coordinates of a specified `POINT` in the specified format.

```sql SQL theme={null}
ST_ASLATLONTEXT(point, [ output_format ] )
```

| **Argument**    | **Data** **Type** | **Description**                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| --------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `point`         | `POINT`           | A POINT value used to calculate geographic coordinates. <br />If `point` is NULL, then this function returns NULL.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `output_format` | `CHAR`            | Optional. A string that includes option flags to set the format and decimal precision for the output of the coordinates. <br />Option flags must be uppercase to be recognized. Accepted option flags are: <br />`D` — Represents coordinate degrees. If you specify a format string for `output_format`, this value is required. If `M` is omitted, this option flag sets the decimal precision. <br />`M` — Represents minutes of latitude or longitude distance. If `S` is omitted, this option flag sets the decimal precision. <br />`S` — Represents seconds of latitude or longitude distance.<br />`C` — Represents the cardinal direction. If you specify this value, the appropriate cardinal direction is represented as N/S/E/W. If you omit this value, coordinates that are south or west are represented as negative values while east or north remain positive values. <br />For all option flags besides `C`, you can repeat the option characters and use them with decimal points to set the format and decimal precision. The number of characters after the decimal point indicates the precision, while the number of characters before the decimal indicates the total width of the formatted number, including the decimal POINT.<br />If the formatted number is shorter than the requested width, the system pads the value with leading spaces. <br />Characters other than `D`, `M`, `S`, `C`, and `.` are passed through as string characters. <br />If you do not specify `output_format` or leave it as empty, the value defaults to the format `D°M''S.SSS"C`. |

**Example**

```sql SQL theme={null}
SELECT ST_ASLATLONTEXT(ST_POINT(10.2342342,-2.32498), 'D.D degrees MM.MM minutes C');
```

*Output*: `'2.0 degrees  19.50 minutes S 10.0 degrees  14.05 minutes E'`

## ST\_ASTEXT

Alias of ST\_ASWKT and ST\_EWKT.

Returns the well-known text (WKT) representation of the specified geography.

If you use `ST_ASEWKT`, the database prepends the resultant string with `SRID=4326;`.

```sql SQL theme={null}
ST_ASTEXT(geo)
```

| **Argument** | **Data** **Type**                   | **Description**                                                                                                                                                                                                                                                                                                                                |
| ------------ | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `geo`        | `POINT`, `LINESTRING`, or `POLYGON` | A geospatial object that is to be returned as a WKT value. <br />If you specify a `LINESTRING` or `POLYGON` that contains a single `POINT`, the function returns the WKT representation as a `POINT`. <br />If you specify a `POLYGON` that has an exterior that is not closed, the function returns the WKT representation as a `LINESTRING`. |

**Example**

```sql SQL theme={null}
SELECT ST_ASTEXT(ST_POLYGON(ST_LINESTRING('LINESTRING(1 2, 1 3, 1 3, 1 2)')));
```

*Output*: `POLYGON((1 2, 1 3, 1 3, 1 2))`

## ST\_ASEWKT

For usage, see [ST\_ASTEXT](#st_astext).

## ST\_ASWKT

Alias of [ST\_ASTEXT](#st_astext).

## ST\_ASWKB

Alias of [ST\_ASBINARY](#st_asbinary).

## ST\_GEOHASH

Returns a string that represents the geohash of the input `POINT`.  This function also accepts an optional second argument to specify the length of the geohash result.

If you specify any argument as NULL, then the function returns NULL.

```sql SQL theme={null}
ST_GEOHASH(point [, precision ] )
```

| **Argument** | **Data** **Type** | **Description**                                                                                                                                                                                                                    |
| ------------ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `point`      | `POINT`           | A `POINT` value that is to be converted into a geohash.                                                                                                                                                                            |
| `precision`  | `INTEGER`         | Optional. A numeric value that specifies the geohash precision, which determines the length of the output string. <br />This number must be in the range of 1 to 20. If you do not specify this value, `precision` defaults to 20. |

**Example**

```sql SQL theme={null}
SELECT ST_GEOHASH(ST_POINT(-126, 48));
```

*Output*: `c0w3hc0w3hf1s70w3hf1s70w3`

## Related Links

[Geospatial Data Types](/data-types#geospatial-data-types)

[Attribute Functions](/attribute-functions)
