Version 8 (modified by 13 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
This sintax need almost gdal 1.9.0 and spatialite 3.0.0 to avoid lost the 3rd dimension exporting the geometries.
Another point is the primary keys: The exportation of a full schema lost every primary key of integer type (don't lost the textual primary keys).
To avoid this lost you should use the "single table" call.