{: .no_toc }
- TOC {:toc}
Problem is incorrect order of columns, so trying to load an integer into a geometry field. Better error messages would make this more obvious.
https://gis.stackexchange.com/questions/311955/error-parse-error-invalid-geometry-postgis
SELECT jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', to_jsonb(row) - 'gid' - 'geom'
) FROM (SELECT * FROM input_table) row;
SELECT jsonb_build_object(
'type', 'FeatureCollection',
'features', jsonb_agg(features.feature)
)
FROM (
SELECT jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', to_jsonb(inputs) - 'gid' - 'geom'
) AS feature
FROM (SELECT * FROM input_table) inputs) features;
https://gis.stackexchange.com/questions/398394/get-bounds-as-geojson
SELECT JSONB_BUILD_OBJECT(
'type', 'FeatureCollection',
'features', JSONB_AGG(ST_AsGeoJSON(q.*)::JSONB)
) AS fc
FROM (
SELECT 1 AS id,
ST_Envelope(ST_Expand('POINT(0 0)'::GEOMETRY, 1)) AS geom
) q;
https://gist.github.com/geozelot/b2e5cd65dd7f85ec381aeee14e0149ae
SELECT ST_AsFeatureCollection(q.*) AS geojson
FROM (
SELECT 1 AS id,
ST_Envelope(ST_Expand('POINT(0 0)'::GEOMETRY, 1)) AS geom
) q;