Skip to main content
This method is not recommended. Please use Sedona GeoJSON data source to write GeoJSON files. Return the GeoJSON string representation of a geometry The type parameter (Since: v1.6.1) takes the following options -
  • “Simple” (default): Returns a simple GeoJSON geometry.
  • “Feature”: Wraps the geometry in a GeoJSON Feature.
  • “FeatureCollection”: Wraps the Feature in a GeoJSON FeatureCollection.

Signatures

ST_AsGeoJSON (A: Geometry)
ST_AsGeoJSON (A: Geometry, type: String)

Parameters

A
Geometry
required
The input geometry.
type
String
The output type.

Return type

A string representation.

Examples

Simple GeoJSON

SELECT ST_AsGeoJSON(ST_GeomFromWKT('POLYGON((1 1, 8 1, 8 8, 1 8, 1 1))'))
{
  "type":"Polygon",
  "coordinates":[
    [[1.0,1.0],
      [8.0,1.0],
      [8.0,8.0],
      [1.0,8.0],
      [1.0,1.0]]
  ]
}

Feature GeoJSON

{
  "type":"Feature",
  "geometry": {
      "type":"Polygon",
      "coordinates":[
        [[1.0,1.0],
          [8.0,1.0],
          [8.0,8.0],
          [1.0,8.0],
          [1.0,1.0]]
      ]
  }
}

FeatureCollection GeoJSON

{
  "type":"FeatureCollection",
  "features": [{
      "type":"Feature",
      "geometry": {
          "type":"Polygon",
          "coordinates":[
            [[1.0,1.0],
              [8.0,1.0],
              [8.0,8.0],
              [1.0,8.0],
              [1.0,1.0]]
          ]
      }
    }
  ]
}