Skip to content

Commit

Permalink
crssync: also update 'deprecated' flag (fixes #18905)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 19, 2018
1 parent 7576ae1 commit e15f7cc
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,9 @@ int QgsCoordinateReferenceSystem::syncDatabase()
if ( name.isEmpty() )
name = QObject::tr( "Imported from GDAL" );

sql = QStringLiteral( "SELECT parameters,description,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
bool deprecated = name.contains( QLatin1Literal( "(deprecated)" ) );

sql = QStringLiteral( "SELECT parameters,description,deprecated,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
statement = database.prepare( sql, result );
if ( result != SQLITE_OK )
{
Expand All @@ -1929,25 +1931,28 @@ int QgsCoordinateReferenceSystem::syncDatabase()

QString srsProj4;
QString srsDesc;
bool srsDeprecated;
if ( statement.step() == SQLITE_ROW )
{
srsProj4 = statement.columnAsText( 0 );
srsDesc = statement.columnAsText( 1 );
srsDeprecated = statement.columnAsText( 2 ).toInt() != 0;

if ( statement.columnAsText( 2 ).toInt() != 0 )
if ( statement.columnAsText( 3 ).toInt() != 0 )
{
continue;
}
}

if ( !srsProj4.isEmpty() || !srsDesc.isEmpty() )
{
if ( proj4 != srsProj4 || name != srsDesc )
if ( proj4 != srsProj4 || name != srsDesc || deprecated != srsDeprecated )
{
errMsg = nullptr;
sql = QStringLiteral( "UPDATE tbl_srs SET parameters=%1,description=%2 WHERE auth_name='EPSG' AND auth_id=%3" )
sql = QStringLiteral( "UPDATE tbl_srs SET parameters=%1,description=%2,deprecated=%3 WHERE auth_name='EPSG' AND auth_id=%4" )
.arg( quotedValue( proj4 ) )
.arg( quotedValue( name ) )
.arg( deprecated ? 1 : 0 )
.arg( it.key() );

if ( sqlite3_exec( database.get(), sql.toUtf8(), nullptr, nullptr, &errMsg ) != SQLITE_OK )
Expand Down Expand Up @@ -1982,13 +1987,14 @@ int QgsCoordinateReferenceSystem::syncDatabase()
ellps = ellipseRegExp.cap( 1 );
}

sql = QStringLiteral( "INSERT INTO tbl_srs(description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) VALUES (%1,%2,%3,%4,%5,'EPSG',%5,%6,0)" )
sql = QStringLiteral( "INSERT INTO tbl_srs(description,projection_acronym,ellipsoid_acronym,parameters,srid,auth_name,auth_id,is_geo,deprecated) VALUES (%1,%2,%3,%4,%5,'EPSG',%5,%6,%7)" )
.arg( quotedValue( name ),
quotedValue( projRegExp.cap( 1 ) ),
quotedValue( ellps ),
quotedValue( proj4 ) )
.arg( it.key() )
.arg( OSRIsGeographic( crs ) );
.arg( OSRIsGeographic( crs ) )
.arg( deprecated ? 1 : 0 );

errMsg = nullptr;
if ( sqlite3_exec( database.get(), sql.toUtf8(), nullptr, nullptr, &errMsg ) == SQLITE_OK )
Expand Down

1 comment on commit e15f7cc

@agiudiceandrea
Copy link
Contributor

@agiudiceandrea agiudiceandrea commented on e15f7cc May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jef-n!
Unfortunately, this
bool deprecated = name.contains( QLatin1Literal( "(deprecated)" ) );
for now works only for PROJCSs with GDAL 2.2 and 2.3.0, but however it solves the inconsistencies reported in #18905 (except for EPSG 102067 that has deprecated=1 but not " deprecated" in the description and was manually updated at 792ac5a setting noupdate=1).

Anyway this fix will work also for GEOGCSs in a future version of GDAL (see OSGeo/gdal#575) and hopefully for GEOCCSs (see https://lists.osgeo.org/pipermail/gdal-dev/2018-May/048495.html and OSGeo/gdal#646) solving the discrepancies between srs.db and the GDAL EPSG derived support csv files about deprecated GEOGCSs and GEOCCSs also reported in #18905.

Please sign in to comment.