Spatialite and GPKG mode are enabled:

SELECT load_extension('mod_spatialite');
SELECT EnableGpkgMode();

Spatialite knows about gpkg_spatial_ref_sys (gpkgInsertEpsgSRID() uses it), and the table is populated:

sqlite> SELECT srs_name, srs_id FROM gpkg_spatial_ref_sys;
Undefined cartesian SRS|-1
Undefined geographic SRS|0
WGS 84 geodetic|4326
Amersfoort / RD New|28992

Yet when I try to use ST_Transform() it tries to look for (and fails to find) spatial_ref_sys:

sqlite> SELECT ST_Transform(gpkgMakePoint(5.140743, 51.630698, 4326), 28992);
unknown SRID: 4326      <no such table: spatial_ref_sys>
unknown SRID: 28992     <no such table: spatial_ref_sys>
Error: ST_Transform exception - unable to find the origin SRID.

What am I doing wrong? Does GPKG mode not support ST_Transform()? What is gpkgInsertEpsgSRID() for then?

Version info:

sqlite> SELECT spatialite_version(), sqlite_version();
  • 1
    SpatiaLite works internally on SpatiaLite geometries. For using the functions you must a) cast GPKG geometries into SpatiaLite geometries (happens to some extent automagically) and b) have all SpatiaLite support tables available. You need to execute also InitSpatialMetaData. gpkgInsertEpsgSRID() needs to be there because GPKG is not valid without GPKG metadata tables.
    – user30184
    Sep 30, 2021 at 14:12

1 Answer 1


As @user30184 says it is in fact necessary to have a separate spatial_ref_sys table. However, instead of using InitSpatialMetadata() and getting many other tables, the following SQL seems to have worked as well (for ST_Transform() at least).

CREATE TABLE spatial_ref_sys (
  auth_name  VARCHAR(256),
  auth_srid  INTEGER,
  srtext     VARCHAR(2048),
  proj4text  VARCHAR(2048)
INSERT INTO spatial_ref_sys SELECT
  srs_id AS srid,
  organization AS auth_name,
  organization_coordsys_id AS auth_srid,
  definition AS srtext,
FROM gpkg_spatial_ref_sys;
  • 1
    That is a good minimal solution. There is a "mode" switch in InitSpatialMetadata gaia-gis.it/gaia-sins/spatialite-sql-latest.html that control what happens but at least geometry_columns table is created by the same.
    – user30184
    Sep 30, 2021 at 16:40
  • thanks so much for this! i think i need to make a little script to run every time i enter the sqlite shell with a geopackage...the list of junk to "turn on" to be functional is becoming too long to remember. Oct 12, 2022 at 16:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.