16.7.2020 |

Selecting (geo)json from postgis

Postgis does not support selecting feature collections, thus I had to build one on my own. This is the resulting query I used:

SELECT json_build_object(
    'type', 'FeatureCollection',
    'properties', json_build_object(),
    'features', json_agg(st_asgeojson(field.geometry)::json)
FROM field
WHERE farm_id = 'XYZ';

Useful postgis functions here are json_build_object() which creates a new object and json_agg() which creates a new array. Other json operations can be found in the postgres documentation.

Zur Übersicht

Mehr vom DevSquad...

Jan Sauer

Automate All The Things with Zapier

Jonathan Zbick

Customizing "Nicht planbar" in moco