!!!note This method is not recommended. Please use Sedona GeoJSON data source to write GeoJSON files.
Introduction: Return the GeoJSON string representation of a geometry
The type parameter (Since: v1.6.1) takes the following options -
Format:
ST_AsGeoJSON (A: Geometry)
ST_AsGeoJSON (A: Geometry, type: String)
Return type: String
Since: v1.0.0
SQL Example (Simple GeoJSON):
SELECT ST_AsGeoJSON(ST_GeomFromWKT('POLYGON((1 1, 8 1, 8 8, 1 8, 1 1))'))
Output:
{ "type":"Polygon", "coordinates":[ [[1.0,1.0], [8.0,1.0], [8.0,8.0], [1.0,8.0], [1.0,1.0]] ] }
SQL Example (Feature GeoJSON):
Output:
{ "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]] ] } }
SQL Example (FeatureCollection GeoJSON):
Output:
{ "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]] ] } } ] }