I am trying to output a PostgreSQL9.6 query to geojson as in this answer:
SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', to_jsonb(row) - 'gid' - 'geom'
) AS feature
FROM (SELECT * FROM paris.plots LIMIT 100) row) features;
I get an error on geojsonlint.com that the polygons should follow teh counterclock-wise rule.
A comment under the answer notes that polygons should be forced to be forced to be reorderd counter-clock wise with ST_ForcePolygonCCW
. Hence I updated my code to:
SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(feature)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(ST_ForcePolygonCCW(geom))::jsonb,
'properties', to_jsonb(row) - 'gid' - 'geom'
) AS feature
FROM (SELECT * FROM paris.plots LIMIT 100) row) features;
I get an error:
Kernel error: ERROR: function st_forcepolygonccw(geometry) does not exist
But the function is listed in the Postgis references. Any idea?