Contents
How to get a GeoJSON feature from PostGIS?
I would like to get a geojson feature with properties from PostGIS. I have found an example to have a feature collection but I can’t make it works for just a feature.
How to return the geometry as a GeoJSON?
ST_AsGeoJSON — Return the geometry as a GeoJSON element. text ST_AsGeoJSON( record feature, text geomcolumnname, integer maxdecimaldigits=9, boolean pretty_bool=false); Return the geometry as a GeoJSON “geometry” object, or the row as a GeoJSON “feature” object.
Is the maxdecimaldigits argument used in GeoJSON?
(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 maxdecimaldigits argument may be used to reduce the maximum number of decimal places used in output (defaults to 9).
Is the aggregation on features function invalid in PostgreSQL?
@dbaston’s answer has been modified lately by @John Powell aka Barça, and it produces invalid geojsons on my end. As modified, the aggregation on features returns each feature nested inside a json object, which is invalid.
How to store GeoJSON featurecollection in PostgreSQL 9.3?
Assuming you have at least PostgreSQL version 9.3, you can use a few JSON functions and operators to extract the relevant parts of the GeoJSON specification required by ST_GeomFromGeoJSON to create geometries. Finds three geometries. The geom column has the geometry object, and the gid is the feature number.
How to build a JSON object in PostgreSQL?
This can be done a bit more simply with json_build_object in PostgreSQL 9.4+, which lets you build up a JSON by supplying alternating key/value arguments. For example: Things get even better in PostgreSQL 9.5+, where some new operators are added for the jsonb data type ( docs ).
How to create GeoJSON feature collections with JSON?
If you do a lot of web-based GIS applications, a common desire is to allow a user to draw out an area on the map and then do searches against that area and return back a FeatureCollection where each feature is composed of a geometry and attributes about that feature.
Is there a Z dimension for GeoJSON polygons?
In my view it doesn’t seem that the geometry has a Z dimension. Taking a look at the source code of PostGIS I found out how it parses SRIDs. Here is the correct way to specify the SRID in GeoJSON. The GeoJSON specification says that the coordinates of a polygon are an array of line strings.