文档

ST_AsGeoJSON

更新时间:

返回给定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)
  • 本页导读 (1)
文档反馈