Introduction: Return the GeoJSON string representation of a geometry
The type parameter takes the following options -
Format:
ST_AsGeoJSON (A:geometry)
ST_AsGeoJSON (A:geometry, type: String)
Return type: String
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]] ] } } ] }