SQL-query should return GeoJSON FeatureCollection

المشرف العام

Administrator
طاقم الإدارة
I'm trying to return a GeoJSON FeatureCollection object from a SQL-query with PostgreSQL 9.3 and PostGIS 2.1.

This is my query so far:

SELECT row_to_json(fc) AS p FROM (SELECT 'FeatureCollection' AS type, array_to_json(array_agg(f)) AS features FROM (SELECT 'Feature' AS type, ST_AsGeoJSON("wkb_geometry")::json AS geometry FROM "4547cd00-b570-4504-9796-cf2f61dbebe4") AS f) AS fc;I'm getting the error:

ERROR: parse error - invalid geometryHowever, if I just run this query:

SELECT ST_AsGeoJSON("wkb_geometry")::json AS geometry FROM "4547cd00-b570-4504-9796-cf2f61dbebe4";It works and print out a nice geometry.If I ignore the ST_AsGeoJSON it also prints out a result, but not something I can use as a GeoJSON FeatureCollection, as I need the type and coordinates seperated into JSON.



أكثر...
 
أعلى