Commit 3a89f61f authored by Darafei Praliaskouski's avatar Darafei Praliaskouski

[doc] ST_AsGeoJSON doc refresh

Closes #4276


git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17115 b70326c6-7e19-0410-871a-916f4a2858ee
parent b7de0058
Pipeline #40950180 passed with stage
in 21 minutes and 58 seconds
......@@ -23,6 +23,9 @@ XXXX/XX/XX
- #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
......
......@@ -359,26 +359,22 @@ CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)
<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>
</listitem>
<listitem>
<para>1: GeoJSON Bbox</para>
<para>1: GeoJSON BBOX</para>
</listitem>
<listitem>
......@@ -405,28 +401,73 @@ CIRCULARSTRING(220268 150415 1,220227 150505 2,220227 150406 3)
<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":"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(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]]}
</programlisting>
{"type":"LineString","coordinates":[[1,2,3],[4,5,6]]}</programlisting>
</refsection>
<refsection>
<title>See Also</title>
<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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment