7

I have a simple "region" table: id (TEXT), name (TEXT), geom (MULTIPOLYGON). Here's the query I can use to extract a GeoJSON FeatureCollection:

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(region.geom)::json AS geometry, 
       row_to_json((SELECT l FROM (SELECT id, name) AS l
   )
 ) AS properties
FROM region) AS f) AS fc;

Is there any equivalent query that can be used to extra TopoJSON instead? I'm aware of AsTopoJSON but no idea how to use.

  • Sadly it is quite complicated. postgis.net/docs/AsTopoJSON.html has an example though, have you tried it? – bugmenot123 Jul 28 '15 at 12:54
  • 3
    Unfortunately I was confused by that example literally from the first line :(. I'm thinking I'll just use the topojson package within node.js to transform the GeoJSON once I have retrieved it from PostGIS using the above query. – rgareth4 Jul 29 '15 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.