ST_GeomFromGeoJSON

更新时间:
复制 MD 格式

Constructs a geometry object from a GeoJSON geometry fragment.

Syntax

geometry ST_GeomFromGeoJSON(text geomjson);
geometry ST_GeomFromGeoJSON(json geomjson);
geometry ST_GeomFromGeoJSON(jsonb geomjson);

Parameters

ParameterTypeDescription
geomjsontext, json, or jsonbThe GeoJSON geometry fragment to parse.

Usage notes

  • Pass a GeoJSON geometry fragment (for example, {"type":"Point","coordinates":[...]}), not a complete GeoJSON Feature or FeatureCollection document. Passing a full GeoJSON document returns an error.

  • 3D geometries are fully supported. The z-coordinate is preserved in the returned geometry object.

Examples

2D point

SELECT ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[116,40]}'));
   st_astext
---------------
 POINT(116 40)
(1 row)