Starting with the Spatialite application, can a new Geopackage file be created, or is Spatialite only capable of working with existing Geopackage files?
-
Do you mean the spatialite-gui application or the command line tool? With spatialite-gui you can only create SpatiaLite databases but with the command line utility it should be bossible to creata also GeoPackages. – user30184 May 21 '18 at 15:58
-
I'm more interested in the CLI, but it would be useful to note if it isn't possible via the GUI for example – Andy Harfoot May 21 '18 at 16:01
-
1There seems to be something about how to do it with CLI tool in thread groups.google.com/forum/#!msg/spatialite-users/rBKeuXLpQv8/… or perhaps they used SQLite plus mod_spatialite. – user30184 May 21 '18 at 16:02
Thanks to @user30184 and ultimately Sandro Furieri in this post:
Creating a crystal-clear GPKG not containing any spatialite specific table is really simple.
You simply have to avoid using either spatialite CLI or spatialite GUI because both tools will always create a new DB-file specifically inteded for SpatiaLite. Anyway a third option exists, and is straighforward.
A) edit the SQL scriptd prepare by Jukka add the following statement before the very first line: SELECT load_extension('mod_spatialite');
B) now you simply have to execute from the shell: sqlite3 test.gpkg
this way you'll get an absolutely clean GPKG
So the answer in the strictest sense is no.
EDIT 1:
In place of the script mentioned in the quote above, there is a Spatialite function gpkgCreateBaseTables
that appears to initialise the requisite Geopackage metadata tables.
EDIT 2:
The following commands generate a clean GPKG (using SQLite 3.17.0 and mod_spatialite.dll 4.3.0):
C:\>sqlite3.exe SL3_Test.gpkg
sqlite>SELECT load_extension('mod_spatialite');
sqlite>SELECT gpkgCreateBaseTables();
sqlite>.exit
You can create a new GeoPackage with Spatialite. All you need to do is make sure you create the required MetaData tables (and triggers to populate them).
There must be a gpkg_contents
table and a gpkg_spatial_ref_sys
. You also need to set the application_id
to GPKG
.
However in most cases it will be easier to use a library or tool designed to do it, one is available in most languages.
-
This approach would work, but will generate a sqlite DB that contains both spatialite and geopackage default tables that might cause problems with some applications. I guess the spatialite tables could then be dropped, but Sandro's approach is much cleaner. – Andy Harfoot May 22 '18 at 8:28