Skip to content

Commit

Permalink
call saveAsUserCRS after each call to createFromProj4
Browse files Browse the repository at this point in the history
  • Loading branch information
leyan committed Apr 16, 2013
1 parent cc6b010 commit 9895141
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -134,6 +134,17 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition
if ( reCrsStr.cap( 1 ).toLower() == "proj4" )
{
result = createFromProj4( reCrsStr.cap( 2 ) );
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( toProj4() );
saveAsUserCRS(myName);
}
}
else
{
Expand Down Expand Up @@ -460,6 +471,17 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )

createFromProj4( proj4src );
}
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( mSrsId == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( toProj4() );
saveAsUserCRS(myName);
}

CPLFree( proj4src );

Expand Down Expand Up @@ -1190,6 +1212,18 @@ bool QgsCoordinateReferenceSystem::readXML( QDomNode & theNode )
//@TODO this srs needs to be validated!!!
mIsValidFlag = true; //shamelessly hard coded for now
}
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( mSrsId == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( toProj4() );
saveAsUserCRS(myName);
}

}
}
else
Expand Down
12 changes: 12 additions & 0 deletions src/core/qgsdistancearea.cpp
Expand Up @@ -212,6 +212,18 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
QgsCoordinateReferenceSystem destCRS;
destCRS.createFromProj4( proj4 );
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( destCRS.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( destCRS.toProj4() );
destCRS.saveAsUserCRS(myName);
}
//

// set transformation from project CRS to ellipsoid coordinates
mCoordTransform->setDestCRS( destCRS );
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgsprojectionselector.cpp
Expand Up @@ -81,6 +81,20 @@ QgsProjectionSelector::QgsProjectionSelector( QWidget* parent, const char *name,
// No? Skip this entry
continue;
}
else
{
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( crs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( crs.toProj4() );
crs.saveAsUserCRS(myName);
}
}
}
mRecentProjections << QString::number( crs.srsid() );
}
Expand Down
12 changes: 12 additions & 0 deletions src/mapserver/qgssldparser.cpp
Expand Up @@ -1524,6 +1524,18 @@ void QgsSLDParser::setCrsForLayer( const QDomElement& layerElem, QgsMapLayer* ml
{
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( srs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( srs.toProj4() );
srs.saveAsUserCRS(myName);
}

ml->setCrs( srs );
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/providers/grass/qgsgrassgislib.cpp
Expand Up @@ -221,6 +221,17 @@ int GRASS_LIB_EXPORT QgsGrassGisLib::G__gisinit( const char * version, const cha
{
fatal( "Cannot create CRS from QGIS_GRASS_CRS: " + crsStr );
}
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( mCrs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( mCrs.toProj4() );
mCrs.saveAsUserCRS(myName);
}
}
mDistanceArea.setSourceCrs( mCrs.srsid() );

Expand Down
12 changes: 12 additions & 0 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3200,6 +3200,18 @@ QgsCoordinateReferenceSystem QgsSpatiaLiteProvider::crs()
if ( !srs.isValid() )
{
srs.createFromProj4( mProj4text );
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( srs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( srs.toProj4() );
srs.saveAsUserCRS(myName);
}

}
return srs;
}
Expand Down
11 changes: 11 additions & 0 deletions src/providers/sqlanywhere/qgssqlanywhereprovider.cpp
Expand Up @@ -1886,6 +1886,17 @@ QgsSqlAnywhereProvider::checkSrs()
SaDebugMsg( "Failed to create CRS from Proj4 description. Trying WKT." );
mCrs.createFromWkt( srsWkt );
}
//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if( mCrs.srsid() == 0 )
{
QString myName = QString( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) )
.arg( mCrs.toProj4() );
mCrs.saveAsUserCRS(myName);
}

return true;
} // QgsSqlAnywhereProvider::checkSrs()
Expand Down

0 comments on commit 9895141

Please sign in to comment.