wiki:SpatiaLite

Version 10 (modified by aperi2007, 10 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=yes -gt 65536 -gt

Some advertising: To avoid the lost of the third dimension exporting geometries you need use almost gdal 1.9.0 and spatialite library 3.0.0.
Also the exportation using the last sintax described don't export any field of type integer that is also a primary key. It don't lost the filed of type TEXT that are also primary keys. To avoid this lost you should use the "single table" call.

Note: See TracWiki for help on using the wiki.