Relevant changes introduced in version 4.0.0
SpatiaLite Version 4.0.0 introduces several relevant changes; many of these may potentially pose severe cross-version compatibility issues.Accordingly to the above premise, a good comprehension of any related detail will surely allow you to successfully master and resolve any transition issue.
You are warmly encouraged to carefully read this short note.
Changes affecting the "spatial_ref_sys" Metadata table
old layout Version 3.1.0 and any earlier |
new layout Version 4.0.0 and any subsequent |
Notes |
srs_wkt TEXT | srtext TEXT |
|
Please note well: there is a further relevant change affecting "spatial_ref_sys" which is absolutely worth to be noticed.
Now any SpatiaLite database always supports the two following SRS implicit definitions:
srid | auth_name | auth_srid | ref_sys_name | proj4text | srtext |
-1 | NONE | -1 | Undefined - Cartesian | Undefined | |
0 | NONE | 0 | Undefined - Geographic Long/Lat | Undefined |
- the first one (-1) identifies any generic, unqualified SRS of the Cartesian type (i.e. planar and using metric coordinates).
- the second one (0) now identifies any generic, unqualified SRS of the Geographic type (i.e. spherical or based on some ellipsoid, and consequently using coordinates expressed as longitude and latitude angles).
Please note: now the default SRID isn't any longer assumed to be -1 as in any earlier version.
Now the default SRID is always assumed to be 0, accordingly to the most recent international standard specifications.
Changes affecting the "geometry_columns" Metadata table
old layout Version 3.1.0 and any earlier |
new layout Version 4.0.0 and any subsequent |
Notes |
type TEXT | geometry_type INTEGER |
|
coord_dimension TEXT | coord_dimension INTEGER |
|
old layout
- both type and coord_dimension values were required in order to fully qualify a Geometry.
- e.g. a Geometry declaring type='LINESTRING' and coord_dimension='XY' was assumed to be a LINESTRING (2D).
- and a Geometry declaring type='MULTILINESTRING' and coord_dimension='XYZM' was assumed to be a MULTILINESTRING ZM (3D + Measure), and so on.
new layout
- now the geometry_type value alone contains any information required in order to fully qualify the Geometry.
- supported values for geometry_type are as follows:
- 0 corresponds to GEOMETRY XY
- 1 corresponds to POINT XY
- 2 corresponds to LINESTRING XY
- 3 corresponds to POLYGON XY
- 4 corresponds to MULTIPOINT XY
- 5 corresponds to MULTILINESTRING XY
- 6 corresponds to MULTIPOLYGON XY
- 7 corresponds to GEOMETRYCOLLECTION XY
- 1000, 1001, ... , 1007 respectively correspond to GEOMETRY XYZ, POINT XYZ, ... , GEOMETRYCOLLECTION XYZ
- 2000, 2001, ... , 2007 respectively correspond to GEOMETRY XYM, POINT XYM, ... , GEOMETRYCOLLECTION XYM
- 3000, 3001, ... , 3007 respectively correspond to GEOMETRY XYZM, POINT XYZM, ... , GEOMETRYCOLLECTION XYZM
- the coord_dimension is completely redundant, and doesn't provide any further information at all.
Expected values are:
- 2 for XY
- 3 for XYZ or XYM
- 4 for XYZM
- in other words geometry_type values in the range 0, ... , 7 necessarily imply coord_dimension=2.
- values in the range 1000, ... , 1007 or 2000, ... , 2007 imply coord_dimension=3.
- and finally values in the range 3000, ... , 3007 always imply coord_dimension=4.
very important notice
Please note well: now both f_table_name and f_geometry_column columns (and any similar column used for views and virtual tables metadata tables) are always assumed to be expressed as lowercase values. And they are expected not to contain any single or double quote character.A full set of Triggers enforces such constraints: this is obviously intended as a mean effectively guaranteeing a strong relational consistency.
When using the SpatiaLite's own C APIs (or SQL functions) this facet will be transparently handled, but this could be a strong issue for third party components attempting to directly access the metadata tables by skipping the C APIs or the SQL supporting functions.
In this case adopting the following approach as a general rule will surely be a good solution:
INSERT INTO geometry_columns (f_table_name, f_geometry_column, ...) VALUES (Lower('MyTable'), Lower('MyGeom'), ..); SELECT * FROM geomety_columns WHERE f_table_name = Lower('MyTable'); |
Changes affecting the "views_geometry_columns" Metadata table
old layout Version 3.1.0 and any earlier |
new layout Version 4.0.0 and any subsequent |
Notes |
n.a. | read_only INTEGER |
|
Changes affecting the "virts_geometry_columns" Metadata table
old layout Version 3.1.0 and any earlier |
new layout Version 4.0.0 and any subsequent |
Notes |
type TEXT | geometry_type INTEGER |
|
n.a. | coord_dimension INTEGER |
|
Metadata and statistic infos available in 4.0.0
Version 4.0.0 now supports a richer set of metadata and statistics information supporting Spatial Tables.You can learn more about this topic by reading this Wiki page
A closely related topic (although not being metadata or statics infos at all, strictly speaking) is the brand new SQL Log facility: you can learn more on this by reading this Wiki page
Changes affecting the VirtualSpatialIndex interface
Version 4.0.0 is now able to directly access a Spatial Index supporting a Spatial View. Imagine a View defined as follows:CREATE TABLE groups ( group_id INTEGER PRIMARY KEY AUTOINCREMENT, group_name TEXT NOT NULL); |
CREATE TABLE items ( item_id INTEGER PRIMARY KEY AUTOINCREMENT, group_id INTEGER NOT NULL, item_name TEXT NOT NULL, CONSTRAINT fk_item FOREIGN KEY (group_id) REFERENCES groups (group_id)); |
SELECT AddGeometryColumn('items', 'geom', 4326, 'POINT', 'XY'); |
SELECT CreateSpatialIndex('items', 'geom'); |
CREATE VIEW items_view AS SELECT i.ROWID AS ROWID, i.item_id AS item_id, i.item_name AS item_name, i.group_id AS group_id, g.group_name AS group_name, i.geom AS Geometry FROM items AS i JOIN groups AS g ON (g.group_id = i.group_id); |
INSERT INTO views_geometry_columns (view_name, view_geometry, view_rowid, f_table_name, f_geometry_column, read_only) VALUES ('items_view', 'Geometry', 'ROWID', 'items', 'geom', 1); |
When using version 4.0.0 both the following Spatial queries are exactly equivalent, and take full profit from the Spatial Index:
indirectly accessing the Table's Spatial Index (as already supporting on earlier versions) |
SELECT * FROM items_view WHERE ROWID IN ( SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'items' AND f_geometry_column = 'geom' AND search_frame = BuildMbr(11, 42, 12, 43, 4326) ); |
directly accessing the View's Spatial Index (new feature introduced in 4.0.0) |
SELECT * FROM items_view WHERE ROWID IN ( SELECT ROWID FROM SpatialIndex WHERE f_table_name = 'items_view' AND f_geometry_column = 'Geometry' AND search_frame = BuildMbr(11, 42, 12, 43, 4326) ); |
Changes affecting Spatial SQL Functions
- InitSpatialMetaData() this SQL function has the same identical signature as before. Anyway on version 4.0.0 all Metadata tables will be created accordingly to the latest specification (i.e. the one explained on this document).
- CheckSpatialMetaData() unchanged signature, but now return different results:
- 0 no valid Spatial Metadata tables were identified.
- 1 legacy Medatata tables were identified (i.e. created by version 3.1.0 or any earlier).
- 2 FDO/OGR Metadata tables were identified.
- 3 current Medatata tables were identified (i.e. created by version 4.0.0 or any subsequent).
- two further functions are now available, specifically supporting VirtualShapes: RegisterVirtualGeometry() and DropVirtualGeometry().
- UpdateLayerStatistics() works exactly as before; but if version 4.0.0 Metadata are detected a richer set of statistical infos is generated, and a further optimization is now introduced, avoiding to recalculate any still valid statistic info (by evaluating the appropriate timestamp values).
Any other SQL function has the same identical signature as before, and will automagically detect the actual format of Metadata tables, thus consequently applying the appropriate actions:
- AddGeometryColumn()
- DiscardGeometryColumn()
- RecoverGeometryColumn()
- CreateSpatialIndex()
- DisableSpatialIndex()
- RecoverSpatialIndex()
- ... and so on ...
Please note: any Spatial SQL function creating a new Geometry (e.g. ST_GeomFromText() and friends) will now assume SRID = 0 if no SRID value was explicitly specified.
Important notice
There is a small change affecting both AddGeometryColumn and RecoverGeometryColumn; now the coord_dimension argument is considered an optional one. Anyway the old syntax supported by previos versions is still considered to be fully valid.The following table enumerates all the legal declarations accepted by version 4.0.0 and assumed to be exactly equivalent (only the POINT case is shown, but you can easily expand this schema to any other Geometry Type).
Please note: the new syntax introduced by version 4.0.0 is represented as bold. The old syntax already supported by earlier versions is in italic.
POINT | 2D, XY | AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 2); AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 'XY') AddGeometryColumn('tbl', 'geom', 4326, 'POINT'); |
3D, XYZ | AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 3); AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 'XYZ') AddGeometryColumn('tbl', 'geom', 4326, 'POINTZ') AddGeometryColumn('tbl', 'geom', 4326, 'POINTZ', 3); AddGeometryColumn('tbl', 'geom', 4326, 'POINTZ', 'XYZ'); | |
2D + measure, XYM | AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 'XYM'); AddGeometryColumn('tbl', 'geom', 4326, 'POINTM'); AddGeometryColumn('tbl', 'geom', 4326, 'POINTM', 'XYM'); | |
3D + measure, XYZM | AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 4); AddGeometryColumn('tbl', 'geom', 4326, 'POINT', 'XYZM') AddGeometryColumn('tbl', 'geom', 4326, 'POINTZM'); AddGeometryColumn('tbl', 'geom', 4326, 'POINTZM', 4); AddGeometryColumn('tbl', 'geom', 4326, 'POINTZM', 'XYZM'); |
Conclusion
When using any appropriate Spatial SQL function the transition toward version 4.0.0 will be absolutely smooth and painless:- any new DB created by version 4.0.0 will support the new Metadata tables.
- accessing any existing DB created by any previous version will raise no errors at all, because libspatialite 4.0.0 is fully capable to transparently handle the oldest Metadata tables as appropriate.
- rather obviously, no previous version (earlier than 4.0.0) will be able to handle any DB created by version 4.0.0
- but on the other way any previous version will still be able to handle any DB touched by version 4.0.0, if the DB was originally created using an earlier version, and thus primed accordingly to legacy Metadata specifications.
libspatialite 4.0.0 carefully avoids to pollute in any way an existing DB (if this actually happens it should be considered as a serious bug, and should be immediately reported asking for any required corrective action).
The spatialite_convert CLI tool
In order to ensure as far as possible a smooth and painless transition between different versions, a further CLI tool is now supported.Syntax: spatialite_convert -d db_pathname -v 4
Executing this command will perform the following actions:
- the exact type of Metadata tables will be identified.
- if valid legacy Metadata tables will be detected, then they'll be dropped and replaced by the corresponding tables required by version 4.0.0
- Please note: this isn't a DB copy, but is an in-lieu conversion.
This practically means that even in the case of some huge sized DB, a very short time will be required, because only the Metadata tables will be affected by the conversion.
The whole conversion will be absolutely safe, because will be confined within a single Transaction: in the worst case (some exceptional and unexpected error) you still get back the original DB absolutely unaffected by any change at all.
spatialite_convert -d db_pathname -v 3
spatialite_convert -d db_pathname -v 2
Conversion will work the opposite way as well:
- if valid 4.0.0 Metadata tables will be detected, then they'll be dropped and replaced by the corresponding tables required by some previous version.
Both version 3.x.x (-v 3) and version 2.3.1 (-v 2) are supported. - This allows you to recover a DB perfectly usable by any other earlier version, even when the original DB was actually created using version 4.0.0
- Rather obviously you can use spatialite_convert in order to convert any DB between version 2.3.1 and 3.x.x as well (both directions).
- Known limits: a DB can be converted to version 2.3.1 only if it uniquely contains 2D XY Geometries, because version 2.3.1 was completely unable to handle 3D Geometries.
Changes affecting GUI and CLI tools
You can learn more about this topic by reading this Wiki pageNew Spatial SQL functions supporting tessellations
You can learn more about this topic by reading this Wiki pageNew Spatial SQL functions based on liblwgeom
liblwgeom is an open source library developed in C language, and released under the GPLv2 license terms. This library was initially intended simply as the generic geometry handling section of PostGIS.Anyway, starting since PostGIS 2.0, liblwgeom is now installed as a self-standing library. In other words: PostGIS depends on liblwgeom, but liblwgeom doesn't depends at all on PostGIS.
So any other open source software can now freely re-use many interesting methods implemented in liblwgeom.
You can learn more about this topic by reading this Wiki page
Connecting SpatiaLite to the most exoteric datasources using VirtualOGR
You can learn more about this topic by reading this Wiki pageComparative Benchmark: the Clipping Contest
You can learn more about this topic by reading this Wiki pageback