]> granicus.if.org Git - postgis/commitdiff
Re-add ST_GeoJSON documentation
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 1 May 2019 21:32:41 +0000 (21:32 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 1 May 2019 21:32:41 +0000 (21:32 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@17423 b70326c6-7e19-0410-871a-916f4a2858ee

doc/reference_output.xml

index 84d1d83baf6c4d0f6981aecae2d9ab2f9bfb15eb..47e45edc5e449b3ce975c7e6062372e199fdb101 100644 (file)
@@ -544,6 +544,13 @@ POINT(111.11 1.11)
 
          <refsynopsisdiv>
                <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>
@@ -562,15 +569,12 @@ POINT(111.11 1.11)
          <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>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>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 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 <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 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,23 +593,17 @@ POINT(111.11 1.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>
 
          <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 @@ POINT(111.11 1.11)
                </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":"Feature","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