I've a website where I'm giving the functionality of creating and editing line features. I'm using Leaflet-Draw plugin for drawing, PostGIS for storing the data and GeoJSON to display it on map.

My next task is to add the Export functionality. I've search around and found that using ogr2ogr I can convert a PostGIS table to shapefile. But this query works in FWTools, how can I run it on server. Another way I found is to use pgsql2shp. But I don't know where to run this command. I run this in Postgres console and SQL Editor but getting error.

The thing is I want to know

What is the best way in my case to export data to shapefile and how to perform it?


1 Answer 1


Just install GDAL and run it from Bash / terminal.

ogr2ogr -f "ESRI Shapefile" mydata.shp PG:"host=myhost user=myloginname dbname=mydbname password=mypassword" "mytable"

Or do not even bother with GDAL and just use something like below in terminal.

# pgsql2shp -f myfile -p 5555 my_db roads_table
  • Ok, with luck, I'm able to run secund query. But this is creating a Shapefile locally on my system. How to run this query on server?
    – muzaffar
    Commented Nov 16, 2014 at 7:11
  • This part is not really GIS specific but far more about your server structure. The simple answer is run the query on the server. Commented Nov 17, 2014 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.