Skip to content

Commit

Permalink
Add a WKT column to tbl_srs
Browse files Browse the repository at this point in the history
proj string definitions of CRSes are lossy, so we need to gradually
transition to WKT definitions instead
  • Loading branch information
nyalldawson committed Dec 12, 2019
1 parent 3d4b5fb commit 4e4cd31
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Binary file modified resources/qgis.db
Binary file not shown.
Binary file modified resources/srs.db
Binary file not shown.
Binary file modified resources/srs6.db
Binary file not shown.
46 changes: 44 additions & 2 deletions src/core/qgsapplication.cpp
Expand Up @@ -1886,6 +1886,7 @@ bool QgsApplication::createDatabase( QString *errorMessage )

// qgis.db is missing tbl_srs, create it
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
"description text NOT NULL,"
Expand All @@ -1896,7 +1897,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean);"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);", nullptr, nullptr, &errmsg ) != SQLITE_OK )
{
if ( errorMessage )
Expand All @@ -1907,6 +1909,43 @@ bool QgsApplication::createDatabase( QString *errorMessage )
return false;
}
}
else
{
// test if wkt column exists in database
res = sqlite3_exec( database.get(), "SELECT wkt FROM tbl_srs LIMIT 0", nullptr, nullptr, &errmsg );
if ( res != SQLITE_OK )
{
// need to add wkt column
sqlite3_free( errmsg );
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"DROP TABLE IF EXISTS tbl_srs_bak;"
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
"description text NOT NULL,"
"projection_acronym text NOT NULL,"
"ellipsoid_acronym NOT NULL,"
"parameters text NOT NULL,"
"srid integer,"
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
"INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
"DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )
{
if ( errorMessage )
{
*errorMessage = tr( "Migration of private qgis.db failed.\n%1" ).arg( QString::fromUtf8( errmsg ) );
}
sqlite3_free( errmsg );
return false;
}
}
}

res = sqlite3_exec( database.get(), "SELECT acronym FROM tbl_projection LIMIT 0", nullptr, nullptr, &errmsg );
if ( res != SQLITE_OK )
Expand Down Expand Up @@ -1936,6 +1975,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
{
// epsg column exists => need migration
if ( sqlite3_exec( database.get(),
"DROP INDEX IF EXISTS idx_srsauthid;"
"DROP TABLE IF EXISTS tbl_srs_bak;"
"ALTER TABLE tbl_srs RENAME TO tbl_srs_bak;"
"CREATE TABLE tbl_srs ("
"srs_id INTEGER PRIMARY KEY,"
Expand All @@ -1947,7 +1988,8 @@ bool QgsApplication::createDatabase( QString *errorMessage )
"auth_name varchar,"
"auth_id varchar,"
"is_geo integer NOT NULL,"
"deprecated boolean);"
"deprecated boolean,"
"wkt text);"
"CREATE INDEX idx_srsauthid on tbl_srs(auth_name,auth_id);"
"INSERT INTO tbl_srs(srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) SELECT srs_id,description,projection_acronym,ellipsoid_acronym,parameters,srid,'','',is_geo,0 FROM tbl_srs_bak;"
"DROP TABLE tbl_srs_bak", nullptr, nullptr, &errmsg ) != SQLITE_OK )
Expand Down

0 comments on commit 4e4cd31

Please sign in to comment.