Skip to content

Geometry Output

Idan Sheinberg edited this page Dec 16, 2022 · 3 revisions

ST_AsText

Description: Serialize geometry data to WKT format
Input Argument #1: Geometry (WKB)
Output: Text (WKT)

SELECT ST_AsText(
  ST_GeomFromText(
    'POINT (121.0 22.5)'
  )
)

Result

POINT (121.0 22.5)

ST_AsEWKT

Description: Serialize geometry data to EWKT format
Input Argument #1: Geometry (WKB)
Output: Text (EWKT)

SELECT ST_AsEWKT(
  ST_GeomFromText(
    'POINT (121.0 22.5)',3857
  )
)

Result

SRID=3857;POINT (121.0 22.5)

ST_AsGeoJson

Description: Serialize geometry data to GeoJson format
Input Argument #1: Geometry (WKB)
Output: Text (GeoJson)

SELECT ST_AsGeoJson(
  ST_GeomFromText(
    'LINESTRING (121.0 22.5, 90.0 -10.2)'
  )
)

Result

{"type":"LineString","coordinates":[[121,22.5],[90,-10.2]],"crs":{"type":"name","properties":{"name":"EPSG:4326"}}}
Clone this wiki locally