Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
I'm pretty sure that the DBManager plugin to QGIS can do this. – Micha Sep 9 '12 at 6:22
up vote 5 down vote accepted


See here for more information and maybe here as well



share|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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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