[postgis-tickets] r17115 - [doc] ST_AsGeoJSON doc refresh
Darafei
komzpa at gmail.com
Thu Dec 20 09:38:57 PST 2018
Author: komzpa
Date: 2018-12-20 21:38:57 -0800 (Thu, 20 Dec 2018)
New Revision: 17115
Modified:
branches/2.5/NEWS
branches/2.5/doc/reference_output.xml
Log:
[doc] ST_AsGeoJSON doc refresh
Closes #4276
Modified: branches/2.5/NEWS
===================================================================
--- branches/2.5/NEWS 2018-12-21 05:36:59 UTC (rev 17114)
+++ branches/2.5/NEWS 2018-12-21 05:38:57 UTC (rev 17115)
@@ -23,6 +23,9 @@
- #4267, Enable Proj 6 deprecated APIs (Darafei Praliaskouski, Raúl Marín)
+ - #4276, ST_AsGeoJSON documentation refresh (Darafei Praliaskouski)
+
+
PostGIS 2.5.1
2018/11/18
Modified: branches/2.5/doc/reference_output.xml
===================================================================
--- branches/2.5/doc/reference_output.xml 2018-12-21 05:36:59 UTC (rev 17114)
+++ branches/2.5/doc/reference_output.xml 2018-12-21 05:38:57 UTC (rev 17115)
@@ -359,19 +359,15 @@
<refsection>
<title>Description</title>
- <para>Return the geometry as a Geometry Javascript Object Notation (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
+ <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 gj_version 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>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 third argument may be used to reduce the maximum number
- of decimal places used in output (defaults to 15).</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 'options' argument could be used to add Bbox or Crs
- in GeoJSON output:
+ <para>The last <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>
@@ -378,7 +374,7 @@
</listitem>
<listitem>
- <para>1: GeoJSON Bbox</para>
+ <para>1: GeoJSON BBOX</para>
</listitem>
<listitem>
@@ -405,28 +401,73 @@
<refsection>
<title>Examples</title>
- <para>GeoJSON format is generally more efficient than other formats for use in ajax mapping.
- One popular javascript client that supports this is Open Layers.
- Example of its use is <ulink
- url="http://openlayers.org/en/v3.10.1/examples/geojson.html">OpenLayers GeoJSON Example</ulink>
+
+
+ <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>
+ <listitem><para><ulink url="https://leafletjs.com/examples/geojson/">Leaflet GeoJSON Example</ulink></para></listitem>
+ <listitem><para><ulink url="https://www.mapbox.com/mapbox-gl-js/example/multiple-geometries/">Mapbox GL GeoJSON Example</ulink></para></listitem>
+ </itemizedlist>
</para>
- <programlisting>SELECT ST_AsGeoJSON(the_geom) from fe_edges limit 1;
+ <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(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)');
+(1 row)</programlisting>
+<para>You can also use it with 3D geometries:</para>
+<programlisting>SELECT ST_AsGeoJSON('LINESTRING(1 2 3, 4 5 6)');
st_asgeojson
-----------------------------------------------------------------------------------------
- {"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}
+ {"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}</programlisting>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
-</programlisting>
- </refsection>
+ <para><xref linkend="ST_GeomFromGeoJSON" />, <xref linkend="ST_AsMVT" />, <xref linkend="ST_AsGeobuf" /></para>
+ </refsection>
+
+
</refentry>
+
+
<refentry id="ST_AsGML">
<refnamediv>
<refname>ST_AsGML</refname>
More information about the postgis-tickets
mailing list