All Products
Search
Document Center

PolarDB: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.
maxdecimaldigitsThe maximum number of decimal places to retain in the output coordinates. Default value: 15.
optionsAdditional members to include in the GeoJSON output. Valid values: 0 (default, no additional members), 1 (include the bbox bounding box member), 2 (include the coordinate reference system (CRS) using a short expression, such as EPSG:4326), 4 (include the CRS using a long expression, such as urn:ogc:def:crs:EPSG::4326).
gjVersionThe version of the GeoJSON specification. If specified, set this to 1.

Usage notes

ST_AsGeoJSON preserves Z coordinates for 3D geometries and does not drop the Z coordinate of the input geometry.

Examples

Convert a LineString geometry to its GeoJSON representation:

SELECT ST_AsGeoJSON('LINESTRING(1 2, 3 4)');

Output:

{
    "type":"LineString",
    "coordinates":[[1,2],[3,4]]
}

(1 row)