wiki:SpatiaLite

Version 7 (modified by martinl, 11 years ago) ( diff )

SpatiaLite

SpatiaLite is a relatively new GIS file format based on SQLite, which uses a single file to store multiple layers and data tables. It is an alternative format to ESRI Shapefiles, which have several legacy issues (such as storage types and lengths of column names, etc.) Furthermore it is simple to distribute and run, as there is only one file.

Exporting from PostGIS to SpatiaLite

Use ogr2ogr built with SQLite options.

To create the SpatiaLite file and export the first layer:

$ ogr2ogr -f SQLite -dsco SPATIALITE=yes myfile.sqlite PG:"dbname=mydb user=myuser password=mypass" myschema.mytable

And for additional layer/tables:

$ ogr2ogr -f SQLite -update myfile.sqlite b PG:"dbname=mydb user=myuser password=mypass" myschema.my2ndtable

To load all the tables of a schema from Postgres to Spatialite (with or without geometry) and without the views:

$ ogr2ogr --config PG_LIST_ALL_TABLES YES --config PG_SKIP_VIEWS YES -f "SQLite" mydb.sqlite -progress PG:"dbname='mydb' \
  active_schema=myschema schemas=myschema host='localhost' port='5432' user='myuser' password='mypass' " -lco LAUNDER=yes \
  -dsco SPATIALITE=yes -lco SPATIAL_INDEX=no
Note: See TracWiki for help on using the wiki.