0
votes

Can anyone help me how to convert to geojson the result of the query from ST_DWithin (objects within a certain radius)? im lost how to use ST_AsGeoJSON.

1
What have you tried? There are examples in the manual. - Mike T
I tried this one: SELECT ST_AsGeoJSON(geocolumn) FROM geotable WHERE ST_DWithin(geocolumn, 'POINT(1000 1000)', 100.0); but the result is a list of geojsons, is there a way to combine all those geojsons into one? thanks :) - noobprog

1 Answers

0
votes

Use an aggregate function like ST_Collect to group the geometries:

SELECT ST_AsGeoJSON(ST_Collect(geocolumn))
FROM geotable
WHERE ST_DWithin(geocolumn, 'POINT(1000 1000)', 100.0);

The result will either be a MULTI- geometry, or GEOMETRYCOLLECTION.