名前

ST_AsGeoJSON — GeoJSON要素としてジオメトリを返します.

概要

text ST_AsGeoJSON(geometry g1);

text ST_AsGeoJSON(geography g1);

text ST_AsGeoJSON(geometry g1, integer max_decimal_digits);

text ST_AsGeoJSON(geography g1, integer max_decimal_digits);

text ST_AsGeoJSON(geometry g1, integer max_decimal_digits, integer options);

text ST_AsGeoJSON(geography g1, integer max_decimal_digits, integer options);

text ST_AsGeoJSON(integer version, geometry g1);

text ST_AsGeoJSON(integer version, geography g1);

text ST_AsGeoJSON(integer version, geometry g1, integer max_decimal_digits);

text ST_AsGeoJSON(integer version, geography g1, integer max_decimal_digits);

text ST_AsGeoJSON(integer version, geometry g1, integer max_decimal_digits, integer options);

text ST_AsGeoJSON(integer version, geography g1, integer max_decimal_digits, integer options);

説明

Geometry Javascript Object Notation (GeoJSON)要素としてジオメトリを返します(GeoJSON specifications 1.0を参照して下さい).二次元と三次元のジオメトリの両方をサポートします.GeoJSONはSFS1.1ジオメトリ型のみサポートします(たとえば曲線サポートはありません).

versionパラメータは,指定する場合は1でなければなりません.

第三引数は,出力の最大有効桁数を減らすために使われることがあります(デフォルトは15です).

最後の'options'引数は,GeoJSON出力の中にBboxまたはCrsを追加するために使います.与える値は次の通りです.

  • 0: オプションなし(デフォルト値)

  • 1: GeoJSON Bbox

  • 2: GeoJSON Short CRS (たとえば EPSG:4326)

  • 4: GeoJSON Long CRS (たとえば urn:ogc:def:crs:EPSG:4326)

一つ目の形式: ST_AsGeoJSON(geom) / 精度=15桁 version=1 options=0

二つ目の形式: ST_AsGeoJSON(geom, precision) / version=1 options=0

三つ目の形式: ST_AsGeoJSON(geom, precision, options) / version=1

四つ目の形式: ST_AsGeoJSON(version, geom) / precision=15 options=0

五つ目の形式: ST_AsGeoJSON(version, geom, precision) /options=0

六つ目の形式: ST_AsGeoJSON(version, geom, precision,options)

初出バージョン: 1.3.4

初出バージョン: 1.5.0 ジオグラフィサポートが導入されました.

この関数は三次元をサポートします.Zインデクスを削除しません.

GeoJSON書式は一般的にAjaxマッピングでの使用に効果的です.OpenLayersはこれをサポートする有名なJavaSciprクライアントです.使用例がOpenLayers GeoJSON Exampleにあります.

SELECT ST_AsGeoJSON(the_geom) from fe_edges limit 1;
					   st_asgeojson
-----------------------------------------------------------------------------------------------------------

{"type":"MultiLineString","coordinates":[[[-89.734634999999997,31.492072000000000],
[-89.734955999999997,31.492237999999997]]]}
(1 row)
--3d point
SELECT ST_AsGeoJSON('LINESTRING(1 2 3, 4 5 6)');

st_asgeojson
-----------------------------------------------------------------------------------------
 {"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}