8

I have a table with geospatial objects, in particular, polygons. I know that I can generate from one row a geoJSON string using ST_AsGeoJSON(http://www.postgis.org/docs/ST_AsGeoJSON.html). But I would like to generate one geoJSON from all the table. Is this possible? How can I do it?

Thanks in advance

nanounanue
  • 537
  • 1
  • 5
  • 11
  • 3
    If you use PostgreSQL 9.2 or higher, you'll find here some explaniations. – Basti Nov 04 '13 at 14:26
  • 1
    See this related question to generate GeoJSON using PostGIS http://gis.stackexchange.com/questions/76319/what-is-the-most-common-way-of-displaying-geodata-from-postgis-on-leaflet – ThomasG77 Nov 04 '13 at 23:37

2 Answers2

8

Already make a comment but in addition if you choose OGR2OGR, the way to export to GeoJSON is the following:

If you want to keep original SRS

ogr2ogr -f "GeoJSON" yourdataoutputname.geojson PG:"host=localhost user=username dbname=yourdatabasename password=yourpassword" "yourpostgistable"

If you want to convert to default SRS for GeoJSON (EPSG 4326)

ogr2ogr -f "GeoJSON" yourdataoutputname.geojson -t_srs EPSG:4326 PG:"host=localhost user=username dbname=yourdatabasename password=yourpassword" "yourpostgistable"
ThomasG77
  • 30,725
  • 1
  • 53
  • 93
1

i think, you need generate row by row with this function ST_AsGeoJSON or export database/table with org2ogr

user23621
  • 11
  • 1