Skip to content

Commit

Permalink
also sync non-EPSG crs
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jul 26, 2012
1 parent 5e39bf2 commit 47cc4f2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
38 changes: 37 additions & 1 deletion src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -1773,9 +1773,16 @@ int QgsCoordinateReferenceSystem::syncDb()
{
deleted = sqlite3_changes( database );
}
else
{
errors++;
qCritical( "Could not execute: %s [%s]\n",
sql.toLocal8Bit().constData(),
sqlite3_errmsg( database ) );
}

#if !defined(PJ_VERSION) || PJ_VERSION!=470
sql = QString( "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name<>'EPSG' WHERE NOT deprecated" );
sql = QString( "select auth_name,auth_id,parameters from tbl_srs WHERE auth_name<>'EPSG' AND NOT deprecated" );
if ( sqlite3_prepare( database, sql.toAscii(), sql.size(), &select, &tail ) == SQLITE_OK )
{
while ( sqlite3_step( select ) == SQLITE_ROW )
Expand Down Expand Up @@ -1806,6 +1813,28 @@ int QgsCoordinateReferenceSystem::syncDb()
proj4 = proj4.mid( input.size() );
proj4 = proj4.trimmed();
}

if ( proj4 != params )
{
sql = QString( "UPDATE tbl_srs SET parameters=%1 WHERE auth_name=%2 AND auth_id=%3" )
.arg( quotedValue( proj4 ) )
.arg( quotedValue( auth_name ) )
.arg( quotedValue( auth_id ) );

if ( sqlite3_exec( database, sql.toUtf8(), 0, 0, &errMsg ) == SQLITE_OK )
{
updated++;
QgsDebugMsgLevel( QString( "SQL: %1\n OLD:%2\n NEW:%3" ).arg( sql ).arg( params ).arg( proj4 ), 3 );
}
else
{
qCritical( "Could not execute: %s [%s/%s]\n",
sql.toLocal8Bit().constData(),
sqlite3_errmsg( database ),
errMsg ? errMsg : "(unknown error)" );
errors++;
}
}
}
else
{
Expand All @@ -1820,6 +1849,13 @@ int QgsCoordinateReferenceSystem::syncDb()
pj_free( pj );
}
}
else
{
errors++;
qCritical( "Could not execute: %s [%s]\n",
sql.toLocal8Bit().constData(),
sqlite3_errmsg( database ) );
}
#endif

OSRDestroySpatialReference( crs );
Expand Down
14 changes: 7 additions & 7 deletions src/crssync/main.cpp
@@ -1,10 +1,10 @@
/***************************************************************************
crssync.cpp
sync srs.db with proj
-------------------
begin : 2011
copyright : (C) 2011 by Juergen E. Fischer, norBIT GmbH
email : jef at norbit dot de
crssync.cpp
sync srs.db with proj
-------------------
begin : May 2011
copyright : (C) 2011 by Juergen E. Fischer, norBIT GmbH
email : jef at norbit dot de
***************************************************************************/

/***************************************************************************
Expand Down Expand Up @@ -46,7 +46,7 @@ int main( int argc, char ** argv )
QgsApplication::setPrefixPath( prefixPath ? prefixPath : CMAKE_INSTALL_PREFIX, TRUE );
}

std::cout << "Synchronizing CRS database with PROJ definitions." << std::endl;
std::cout << "Synchronizing CRS database with GDAL/PROJ definitions." << std::endl;

CPLPushErrorHandler( showError );

Expand Down

0 comments on commit 47cc4f2

Please sign in to comment.