ST_ASGEOJSON()

All functions > GEOSPATIAL > ST_ASGEOJSON()

Returns the GeoJSON representation of a geometry or geography.

Signatures

To GeoJSON

Returns: GeoJSON string

ST_ASGEOJSON(geo: T) → VARCHAR
sql
ParameterTypeRequiredDescription
geoTYesGeometry or geography value

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY

Signature notes:

  • Accepts any sub kind
  • Works on both GEOMETRY and GEOGRAPHY values
  • The text is engine-defined (spacing, key order, number spelling): compare two results as JSON values with JSON_PARSE
  • Returns NULL if the input is NULL

Availability

StatusBackends
Not availableclickhouse, mysql

Examples

FeatureQL
RETURN
    -- Point to GeoJSON
    f1 := ST_ASGEOJSON(ST_GEOMPOINT(1.0, 2.0))
;
Result
f1 JSON
{"type":"Point","coordinates":[1.0,2.0]}