返回給定Geometry對象或Geography對象的GeoJSON表示。

語法

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);

參數

參數名稱 描述
geom 目標Geometry對象。
maxdecimaldigits 最大小數位數。默認為15。
options 在輸出的Geojson中添加信息。默認為0:
  • 0:不添加。
  • 1:BBOX。
  • 2:Geojson CRS短表達式(如EPSG:4326)。
  • 4:Geojson CRS長表達式(如urn:ogc:def:crs:EPSG::4326)。
geog 目標Geography對象。
gjVersion 指定Geojson規范的版本,如果指定,則必須為1。

描述

該函數支持3D對象,并且不會丟棄Geometry對象的z-index。

示例

Geometry對象的Geojson表示:
SELECT ST_AsGeoJSON('LINESTRING(1 2, 3 4)');
                   st_asgeojson
---------------------------------------------------
 {
     "type":"LineString",
  "coordinates":[[1,2],[3,4]]
 }
(1 row)