Skip to content

Instantly share code, notes, and snippets.

@arion
Created April 25, 2016 07:43
Show Gist options
  • Save arion/2a9aeefe6d60d55c88bac2f39691233b to your computer and use it in GitHub Desktop.
Save arion/2a9aeefe6d60d55c88bac2f39691233b to your computer and use it in GitHub Desktop.
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(lg.area)::json As geometry
, row_to_json((SELECT l FROM (SELECT id, name) As l
)) As properties
FROM geofences As lg ) As f ) As fc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment