[postgis-tickets] r17423 - Re-add ST_GeoJSON documentation
Paul Ramsey
pramsey at cleverelephant.ca
Wed May 1 02:32:41 PDT 2019
Author: pramsey
Date: 2019-05-01 14:32:41 -0700 (Wed, 01 May 2019)
New Revision: 17423
Modified:
trunk/doc/reference_output.xml
Log:
Re-add ST_GeoJSON documentation
Modified: trunk/doc/reference_output.xml
===================================================================
--- trunk/doc/reference_output.xml 2019-05-01 20:12:19 UTC (rev 17422)
+++ trunk/doc/reference_output.xml 2019-05-01 21:32:41 UTC (rev 17423)
@@ -546,6 +546,13 @@
<funcsynopsis>
<funcprototype>
<funcdef>text <function>ST_AsGeoJSON</function></funcdef>
+ <paramdef><type>record </type> <parameter>feature</parameter></paramdef>
+ <paramdef choice="opt"><type>text </type> <parameter>geomcolumnname</parameter></paramdef>
+ <paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
+ <paramdef choice="opt"><type>boolean </type> <parameter>prettyprint=false</parameter></paramdef>
+ </funcprototype>
+ <funcprototype>
+ <funcdef>text <function>ST_AsGeoJSON</function></funcdef>
<paramdef><type>geometry </type> <parameter>geom</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>maxdecimaldigits=15</parameter></paramdef>
<paramdef choice="opt"><type>integer </type> <parameter>options=0</parameter></paramdef>
@@ -562,15 +569,12 @@
<refsection>
<title>Description</title>
- <para>Return the geometry as a GeoJSON element. (Cf <ulink
- url="http://geojson.org/geojson-spec.html">GeoJSON specifications 1.0</ulink>). 2D and 3D Geometries are both supported. GeoJSON only support SFS 1.1 geometry type (no curve
- support for example).</para>
+ <para>Return the geometry as a GeoJSON "geometry" object, or the row as a GeoJSON "feature" object. (Cf <ulink
+ url="https://tools.ietf.org/html/rfc7946">GeoJSON specifications RFC 7946</ulink>). 2D and 3D Geometries are both supported. GeoJSON only support SFS 1.1 geometry types (no curve support for example).</para>
- <para>The <varname>gj_version</varname> parameter is the major version of the GeoJSON spec. If specified, must be 1. This represents the spec version of GeoJSON.</para>
+ <para>The <varname>maxdecimaldigits</varname> argument may be used to reduce the maximum number of decimal places used in output (defaults to 15). If you are using EPSG:4326 and are outputting the geometry only for display, <varname>maxdecimaldigits</varname>=6 can be a good choice for many maps.</para>
- <para>The third argument may be used to reduce the maximum number of decimal places used in output (defaults to 15). If you are using EPSG:4326 and are outputting the geometry only for display, <varname>maxdecimaldigits</varname>=6 can be a good choice for many maps.</para>
-
- <para>The last <varname>options</varname> argument could be used to add BBOX or CRS in GeoJSON output:
+ <para>The <varname>options</varname> argument could be used to add BBOX or CRS in GeoJSON output:
<itemizedlist>
<listitem>
<para>0: means no option (default value)</para>
@@ -589,16 +593,11 @@
</listitem>
</itemizedlist>
</para>
- <para>Version 1: ST_AsGeoJSON(geom) / maxdecimaldigits=15 version=1 options=0</para>
- <para>Version 2: ST_AsGeoJSON(geom, maxdecimaldigits) / version=1 options=0</para>
- <para>Version 3: ST_AsGeoJSON(geom, maxdecimaldigits, options) / version=1</para>
- <para>Version 4: ST_AsGeoJSON(gj_version, geom) / maxdecimaldigits=15 options=0</para>
- <para>Version 5: ST_AsGeoJSON(gj_version, geom, maxdecimaldigits) / options=0</para>
- <para>Version 6: ST_AsGeoJSON(gj_version, geom, maxdecimaldigits, options)</para>
<para>Availability: 1.3.4</para>
<para>Availability: 1.5.0 geography support was introduced.</para>
<para>Changed: 2.0.0 support default args and named args.</para>
+ <para>Changed: 3.0.0 support records as input</para>
<para>&Z_support;</para>
</refsection>
@@ -605,7 +604,6 @@
<refsection>
<title>Examples</title>
-
<para>GeoJSON format is popular among web mapping frameworks.
<itemizedlist>
<listitem><para><ulink url="https://openlayers.org/en/latest/examples/geojson.html">OpenLayers GeoJSON Example</ulink></para></listitem>
@@ -615,37 +613,18 @@
</para>
<para>You can test and view your GeoJSON data online on <ulink url="http://geojson.io/">geojson.io</ulink>.</para>
- <para>ST_AsGeoJSON only builds geometry. You need to build the rest of Feature from your Postgres table yourself:</para>
- <programlisting>
-select row_to_json(fc)
-from (
- select
- 'FeatureCollection' as "type",
- array_to_json(array_agg(f)) as "features"
- from (
- select
- 'Feature' as "type",
- ST_AsGeoJSON(ST_Transform(way, 4326), 6) :: json as "geometry",
- (
- select json_strip_nulls(row_to_json(t))
- from (
- select
- osm_id,
- "natural",
- place
- ) t
- ) as "properties"
- from planet_osm_point
- where
- "natural" is not null
- or place is not null
- limit 10
- ) as f
-) as fc;
- st_asgeojson
------------------------------------------------------------------------------------------------------------
-{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[23.569251,51.541599]},"properties":{"osm_id":3424148658,"place":"locality"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.625174,51.511718]},"properties":{"osm_id":4322036818,"place":"locality"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.613928,51.5417]},"properties":{"osm_id":242979330,"place":"hamlet"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.586361,51.563272]},"properties":{"osm_id":3424148656,"place":"locality"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.605488,51.553886]},"properties":{"osm_id":242979323,"place":"village"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.6067,51.57609]},"properties":{"osm_id":242979327,"place":"village"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.636533,51.575683]},"properties":{"osm_id":5737800420,"place":"locality"}},{"type":"F
eature","geometry":{"type":"Point","coordinates":[23.656733,51.518733]},"properties":{"osm_id":5737802397,"place":"locality"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.672542,51.504584]},"properties":{"osm_id":242979320,"place":"hamlet"}},{"type":"Feature","geometry":{"type":"Point","coordinates":[23.574094,51.63389]},"properties":{"osm_id":242979333,"place":"village"}}]}
- </programlisting>
+ <programlisting>SELECT ST_AsGeoJSON(t.*)
+FROM (VALUES
+ (1, 'one', 'POINT(1 1)'::geometry),
+ (2, 'two', 'POINT(2 2)'),
+ (3, 'three', 'POINT(3 3)'))
+AS t(id, name, geom);
+ st_asgeojson
+-----------------------------------------------------------------------------------------------------------------
+ {"type": "Feature", "geometry": {"type":"Point","coordinates":[1,1]}, "properties": {"id": 1, "name": "one"}}
+ {"type": "Feature", "geometry": {"type":"Point","coordinates":[2,2]}, "properties": {"id": 2, "name": "two"}}
+ {"type": "Feature", "geometry": {"type":"Point","coordinates":[3,3]}, "properties": {"id": 3, "name": "three"}}
+</programlisting>
<programlisting>SELECT ST_AsGeoJSON(geom) from fe_edges limit 1;
st_asgeojson
More information about the postgis-tickets
mailing list