Categories:

Geospatial Functions, Conversion Functions

TO_GEOGRAPHY

Parses an input and returns a value of type GEOGRAPHY.

See also:

TRY_TO_GEOGRAPHY , ST_GEOGRAPHYFROMWKB , ST_GEOGRAPHYFROMWKT

Syntax

Use one of the following:

TO_GEOGRAPHY( <varchar_expression> )

TO_GEOGRAPHY( <binary_expression> )

TO_GEOGRAPHY( <variant_expression> )

Arguments

varchar_expression

The argument must be a string expression that represents a valid geometric object in one of the following formats:

  • WKT (well-known text).

  • WKB (well-known binary) in hexadecimal format (without a leading 0x).

  • EWKT (extended well-known text).

  • EWKB (extended well-known binary) in hexadecimal format (without a leading 0x).

  • GeoJSON.

binary_expression

The argument must be a binary expression in WKB or EWKB format.

variant_expression

The argument must be an OBJECT in GeoJSON format.

Returns

The function returns a value of type GEOGRAPHY.

Usage Notes

  • Issues an error if the input cannot be parsed as one of the supported formats (WKT, WKB, EWKT, EWKB, GeoJSON).

  • Issues an error if the input format is EWKT or EWKB and the SRID is not 4326. See the note on EWKT and EWKB handling.

  • To construct a GEOGRAPHY object from WKT or EWKT input, you can also use ST_GEOGRAPHYFROMWKT.

  • To construct a GEOGRAPHY object from WKB or EWKB input, you can also use ST_GEOGRAPHYFROMWKB.

Examples

This shows a simple use of the TO_GEOGRAPHY function with VARCHAR data:

select TO_GEOGRAPHY('POINT(-122.35 37.55)');
+--------------------------------------+
| TO_GEOGRAPHY('POINT(-122.35 37.55)') |
|--------------------------------------|
| POINT(-122.35 37.55)                 |
+--------------------------------------+