From 5cedb987713e0e0466a2619698162977e8fe1967 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Wed, 1 May 2019 21:32:41 +0000 Subject: [PATCH] Re-add ST_GeoJSON documentation git-svn-id: http://svn.osgeo.org/postgis/trunk@17423 b70326c6-7e19-0410-871a-916f4a2858ee --- doc/reference_output.xml | 69 ++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 45 deletions(-) diff --git a/doc/reference_output.xml b/doc/reference_output.xml index 84d1d83ba..47e45edc5 100644 --- a/doc/reference_output.xml +++ b/doc/reference_output.xml @@ -544,6 +544,13 @@ POINT(111.11 1.11) + + text ST_AsGeoJSON + record feature + text geomcolumnname + integer maxdecimaldigits=15 + boolean prettyprint=false + text ST_AsGeoJSON geometry geom @@ -562,15 +569,12 @@ POINT(111.11 1.11) Description - Return the geometry as a GeoJSON element. (Cf GeoJSON specifications 1.0). 2D and 3D Geometries are both supported. GeoJSON only support SFS 1.1 geometry type (no curve - support for example). - - The gj_version parameter is the major version of the GeoJSON spec. If specified, must be 1. This represents the spec version of GeoJSON. + Return the geometry as a GeoJSON "geometry" object, or the row as a GeoJSON "feature" object. (Cf GeoJSON specifications RFC 7946). 2D and 3D Geometries are both supported. GeoJSON only support SFS 1.1 geometry types (no curve support for example). - 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, maxdecimaldigits=6 can be a good choice for many maps. + The maxdecimaldigits 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, maxdecimaldigits=6 can be a good choice for many maps. - The last options argument could be used to add BBOX or CRS in GeoJSON output: + The options argument could be used to add BBOX or CRS in GeoJSON output: 0: means no option (default value) @@ -589,23 +593,17 @@ POINT(111.11 1.11) - Version 1: ST_AsGeoJSON(geom) / maxdecimaldigits=15 version=1 options=0 - Version 2: ST_AsGeoJSON(geom, maxdecimaldigits) / version=1 options=0 - Version 3: ST_AsGeoJSON(geom, maxdecimaldigits, options) / version=1 - Version 4: ST_AsGeoJSON(gj_version, geom) / maxdecimaldigits=15 options=0 - Version 5: ST_AsGeoJSON(gj_version, geom, maxdecimaldigits) / options=0 - Version 6: ST_AsGeoJSON(gj_version, geom, maxdecimaldigits, options) Availability: 1.3.4 Availability: 1.5.0 geography support was introduced. Changed: 2.0.0 support default args and named args. + Changed: 3.0.0 support records as input &Z_support; Examples - GeoJSON format is popular among web mapping frameworks. OpenLayers GeoJSON Example @@ -615,37 +613,18 @@ POINT(111.11 1.11) You can test and view your GeoJSON data online on geojson.io. - ST_AsGeoJSON only builds geometry. You need to build the rest of Feature from your Postgres table yourself: - -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"}}]} - + 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"}} + SELECT ST_AsGeoJSON(geom) from fe_edges limit 1; st_asgeojson -- 2.40.0