Skip to content

Commit 7576ae1

Browse files
committed
crssync:
* also update coordinate system descriptions * retrieve descriptions of geocentric CRSes (fixes #18968)
1 parent a4d016f commit 7576ae1

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/core/qgscoordinatereferencesystem.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ bool QgsCoordinateReferenceSystem::loadWkts( QHash<int, QString> &wkts, const ch
17331733
if ( line.isNull() )
17341734
break;
17351735

1736-
if ( line.startsWith( '#' ) )
1736+
if ( line.trimmed().isEmpty() || line.startsWith( '#' ) )
17371737
{
17381738
continue;
17391739
}
@@ -1785,14 +1785,23 @@ bool QgsCoordinateReferenceSystem::loadIds( QHash<int, QString> &wkts )
17851785
if ( line.isNull() )
17861786
break;
17871787

1788+
if ( line.trimmed().isEmpty() )
1789+
continue;
1790+
17881791
int pos = line.indexOf( ',' );
17891792
if ( pos < 0 )
1793+
{
1794+
qWarning( "No id found in: %s", qPrintable( line ) );
17901795
continue;
1796+
}
17911797

17921798
bool ok;
17931799
int epsg = line.leftRef( pos ).toInt( &ok );
17941800
if ( !ok )
1801+
{
1802+
qWarning( "No valid id found in: %s", qPrintable( line ) );
17951803
continue;
1804+
}
17961805

17971806
// some CRS are known to fail (see http://trac.osgeo.org/gdal/ticket/2900)
17981807
if ( epsg == 2218 || epsg == 2221 || epsg == 2296 || epsg == 2297 || epsg == 2298 || epsg == 2299 || epsg == 2300 || epsg == 2301 || epsg == 2302 ||
@@ -1904,7 +1913,13 @@ int QgsCoordinateReferenceSystem::syncDatabase()
19041913
if ( proj4.isEmpty() )
19051914
continue;
19061915

1907-
sql = QStringLiteral( "SELECT parameters,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
1916+
QString name( OSRIsGeographic( crs ) ? OSRGetAttrValue( crs, "GEOGCS", 0 ) :
1917+
OSRIsGeocentric( crs ) ? OSRGetAttrValue( crs, "GEOCCS", 0 ) :
1918+
OSRGetAttrValue( crs, "PROJCS", 0 ) );
1919+
if ( name.isEmpty() )
1920+
name = QObject::tr( "Imported from GDAL" );
1921+
1922+
sql = QStringLiteral( "SELECT parameters,description,noupdate FROM tbl_srs WHERE auth_name='EPSG' AND auth_id='%1'" ).arg( it.key() );
19081923
statement = database.prepare( sql, result );
19091924
if ( result != SQLITE_OK )
19101925
{
@@ -1913,22 +1928,27 @@ int QgsCoordinateReferenceSystem::syncDatabase()
19131928
}
19141929

19151930
QString srsProj4;
1931+
QString srsDesc;
19161932
if ( statement.step() == SQLITE_ROW )
19171933
{
19181934
srsProj4 = statement.columnAsText( 0 );
1935+
srsDesc = statement.columnAsText( 1 );
19191936

1920-
if ( statement.columnAsText( 1 ).toInt() != 0 )
1937+
if ( statement.columnAsText( 2 ).toInt() != 0 )
19211938
{
19221939
continue;
19231940
}
19241941
}
19251942

1926-
if ( !srsProj4.isEmpty() )
1943+
if ( !srsProj4.isEmpty() || !srsDesc.isEmpty() )
19271944
{
1928-
if ( proj4 != srsProj4 )
1945+
if ( proj4 != srsProj4 || name != srsDesc )
19291946
{
19301947
errMsg = nullptr;
1931-
sql = QStringLiteral( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name='EPSG' AND auth_id=%2" ).arg( quotedValue( proj4 ) ).arg( it.key() );
1948+
sql = QStringLiteral( "UPDATE tbl_srs SET parameters=%1,description=%2 WHERE auth_name='EPSG' AND auth_id=%3" )
1949+
.arg( quotedValue( proj4 ) )
1950+
.arg( quotedValue( name ) )
1951+
.arg( it.key() );
19321952

19331953
if ( sqlite3_exec( database.get(), sql.toUtf8(), nullptr, nullptr, &errMsg ) != SQLITE_OK )
19341954
{
@@ -1962,10 +1982,6 @@ int QgsCoordinateReferenceSystem::syncDatabase()
19621982
ellps = ellipseRegExp.cap( 1 );
19631983
}
19641984

1965-
QString name( OSRIsGeographic( crs ) ? OSRGetAttrValue( crs, "GEOGCS", 0 ) : OSRGetAttrValue( crs, "PROJCS", 0 ) );
1966-
if ( name.isEmpty() )
1967-
name = QObject::tr( "Imported from GDAL" );
1968-
19691985
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)" )
19701986
.arg( quotedValue( name ),
19711987
quotedValue( projRegExp.cap( 1 ) ),

0 commit comments

Comments
 (0)