All Products
Search
Document Center

ApsaraDB RDS:ST_AsGeoJSON

Last Updated:Mar 28, 2026

Returns the GeoJSON representation of a geometry or geography object.

Syntax

text  ST_AsGeoJSON(geometry  geom , integer  maxdecimaldigits , integer  options);
text  ST_AsGeoJSON(geography  geog , integer  maxdecimaldigits , integer  options);
text  ST_AsGeoJSON(integer  gjVersion , geometry  geom , integer  maxdecimaldigits , integer  options);
text  ST_AsGeoJSON(integer  gjVersion , geography  geog , integer  maxdecimaldigits , integer  options);

Parameters

ParameterDescription
geomThe geometry object to convert.
geogThe geography object to convert.
maxdecimaldigitsMaximum number of decimal places to retain in the output coordinates. Default value: 15.
optionsControls what additional members to include in the GeoJSON output. Valid values: 0 (default), 1, 2, 4. See the options table below for details.
gjVersionThe GeoJSON specification version. If specified, set to 1.

Options values

ValueDescription
0No additional members. This is the default.
1Include the bbox (bounding box) member.
2Include the coordinate reference system (CRS) using a short expression, for example, EPSG:4326.
4Include the CRS using a long expression, for example, urn:ogc:def:crs:EPSG::4326.

Usage notes

  • Supports 3D objects. The Z coordinate of the input geometry is preserved in the output.

Examples

Convert a geometry object to GeoJSON

SELECT ST_AsGeoJSON('LINESTRING(1 2, 3 4)');
                   st_asgeojson
---------------------------------------------------
 {
     "type":"LineString",
  "coordinates":[[1,2],[3,4]]
 }
(1 row)

Related topics