Guide: run locallypostgis sql → geojson
PostGIS to GeoJSON with ogr2ogr
How to export a PostGIS table to GeoJSON with ogr2ogr.
The GDAL worker behind this site has no database connection. On your own computer ogr2ogr reads from PostGIS with the PostgreSQL driver and writes GeoJSON. We could not test this command: our test environment had no PostGIS server.
Guide: run this conversion locally with GDAL
The GDAL worker behind this site has no database connection. Run the command below with GDAL on your computer.
What the command does
- ogr2ogr connects with a PG: connection string and reads the table named after it.
- -t_srs EPSG:4326 writes longitude/latitude as RFC 7946 expects; without it the coordinates stay in the table's coordinate system.
GDAL command to run locally
sh — gdal
$ogr2ogr -f GeoJSON output.geojson PG:"host=localhost dbname=gis user=postgres" public.roads -t_srs EPSG:4326
Not run by us: no PostGIS server was available in the test environment. The connection string follows the GDAL documentation of the PostgreSQL driver.
Limits
- This command was not tested by us.