My PostGIS database contains OSM data from my country. For transportation reasons I want to export a spatial view I created from that data to a SpatiaLite database.

Is there any way to directly extract my PostGIS view to a SpatiaLite db without resorting to a man-in-the-middle (shapefile then SQLite) solution?

Im using Ubuntu Linux, with PostGIS 2.1 GDAL 191.


Here's a single cmd to export to shapefile:

ogr2ogr -f "ESRI Shapefile" <name-of-folder-to-be-created> \
PG:"dbname=dbname user=username password=pass" \
-sql "<sql query eg> select * from database where <whatever>"

If you get a getsrid(geom) error, load in your database the "legacy.sql"

psql -f /path/to/legacy.sql
  • I'm pretty sure that the DBManager plugin to QGIS can do this. – Micha Sep 9 '12 at 6:22


See here for more information and maybe here as well

|improve this answer|||||
  • this seems to be relevant. I will give it a try and then update with results – nickves Sep 8 '12 at 20:48
  • Hi! Have you managed to export with ogr2ogr? – Stéphane Henriod Sep 27 '12 at 5:51
  • yes I did. I had to load legacy.sql, but it works! – nickves Sep 27 '12 at 10:15

If you haven't done a lot of work in postgis, another alternative might be to import it directly from OSM into spatialite.

|improve this answer|||||

Your Answer

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

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