全部產品
Search
文件中心

PolarDB:ST_AsGeoJSON

更新時間:Jul 06, 2024

返回給定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)