- Categories:
ST_ASGEOJSON¶
Given a value of type GEOGRAPHY or GEOMETRY, return the GeoJSON representation of that value.
Syntax¶
Arguments¶
geography_or_geometry_expressionThe argument must be an expression of type GEOGRAPHY or GEOMETRY.
Returns¶
An OBJECT in GeoJSON format.
Usage notes¶
For GEOMETRY objects:
The returned GEOMETRY object uses the same coordinate system as the input GEOMETRY object.
Note that the GeoJSON specification requires that geometry be in the WGS84 coordinate system (SRID = 4326). However, the ST_ASGEOJSON function does not enforce this.
The function does not add the SRID or any other CRS information to the output.
Examples¶
GEOGRAPHY examples¶
The following example demonstrates the ST_ASGEOJSON function:
Casting the VARIANT output to VARCHAR results in the following:
GEOMETRY examples¶
The following example demonstrates the ST_ASGEOJSON function with a GEOMETRY object as input: