Skip to content
Permalink
Browse files

apply #3586

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15419 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Mar 10, 2011
1 parent b83ae21 commit 86895ff9fee7725d738db5578737a2b4cc257119
@@ -46,9 +46,7 @@ class QgsCoordinateReferenceSystem
*
* Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.
*
* \note This function only deals with Epsg Id labels only at this time.
*
* \retval FALSE if not given an Epsg Id label
* \retval false if not given an valid label
*/
bool createFromOgcWmsCrs(QString theCrs);

@@ -319,29 +319,29 @@ static QgsMessageOutput *messageOutputViewer_()
*/
static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
{
QString toProj4;
QString authid;
QSettings mySettings;
QString myDefaultProjectionOption = mySettings.value( "/Projections/defaultBehaviour" ).toString();
if ( myDefaultProjectionOption == "prompt" )
{
//@note this class is not a descendent of QWidget so we cant pass
//it in the ctor of the layer projection selector

QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector();
mySelector->setMessage( srs->validationHint() ); //shows a generic message, if not specified
toProj4 = QgsProject::instance()->readEntry( "SpatialRefSys", "//ProjectCRSProj4String", GEOPROJ4 );
QgsCoordinateReferenceSystem defaultCRS;
if ( defaultCRS.createFromProj4( toProj4 ) )
authid = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
QgsCoordinateReferenceSystem defaultCrs;
if ( defaultCrs.createFromOgcWmsCrs( authid ) )
{
mySelector->setSelectedCrsId( defaultCRS.srsid() );
mySelector->setSelectedCrsId( defaultCrs.srsid() );
}

QApplication::setOverrideCursor( Qt::ArrowCursor );

if ( mySelector->exec() )
{
QgsDebugMsg( "Layer srs set from dialog: " + QString::number( mySelector->selectedCrsId() ) );
srs->createFromProj4( mySelector->selectedProj4String() );
srs->createFromOgcWmsCrs( mySelector->selectedAuthId() );
}

QApplication::restoreOverrideCursor();
@@ -351,14 +351,14 @@ static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
else if ( myDefaultProjectionOption == "useProject" )
{
// XXX TODO: Change project to store selected CS as 'projectCRS' not 'selectedWkt'
toProj4 = QgsProject::instance()->readEntry( "SpatialRefSys", "//ProjectCRSProj4String", GEOPROJ4 );
QgsDebugMsg( "Layer srs set from project: " + toProj4 );
authid = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
QgsDebugMsg( "Layer srs set from project: " + authid );
QgisApp::instance()->statusBar()->showMessage( QObject::tr( "CRS undefined - defaulting to project CRS" ) );
srs->createFromProj4( toProj4 );
srs->createFromOgcWmsCrs( authid );
}
else ///Projections/defaultBehaviour==useGlobal
{
srs->createFromProj4( mySettings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString() );
srs->createFromOgcWmsCrs( mySettings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
QgisApp::instance()->statusBar()->showMessage( QObject::tr( "CRS undefined - defaulting to default CRS" ) );
}
}
@@ -2489,12 +2489,12 @@ void QgisApp::fileNew( bool thePromptToSaveFlag )

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = settings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
QString defCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
srs.createFromOgcWmsCrs( defCrs );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
prj->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
prj->dirty( false );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
@@ -4809,12 +4809,12 @@ void QgisApp::options()

// set project CRS
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
QString projString = mySettings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
QString defCrs = mySettings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
QgsCoordinateReferenceSystem srs;
srs.createFromProj4( projString );
srs.createFromOgcWmsCrs( defCrs );
myRenderer->setDestinationSrs( srs );
// write the projections _proj string_ to project settings
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
if ( srs.mapUnits() != QGis::UnknownUnit )
{
myRenderer->setMapUnits( srs.mapUnits() );
@@ -155,7 +155,7 @@ void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
if ( mySelector->exec() )
{
mCrsId = mySelector->selectedCrsId();
leSpatialRefSys->setText( mySelector->selectedProj4String() );
leSpatialRefSys->setText( mySelector->selectedAuthId() );
}
else
{
@@ -188,16 +188,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
{
radUseGlobalProjection->setChecked( true );
}
QString myLayerDefaultCrsString = settings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString();
mLayerDefaultCrs.createFromProj4( myLayerDefaultCrsString );
QString myLayerDefaultCrs = settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
mLayerDefaultCrs.createFromOgcWmsCrs( myLayerDefaultCrs );
//display the crs as friendly text rather than in wkt
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );

//on the fly CRS transformation settings
chkOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
QString myDefaultCrsString = settings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
mDefaultCrs.createFromProj4( myDefaultCrsString );

QString myDefaultCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
mDefaultCrs.createFromOgcWmsCrs( myDefaultCrs );
//display the crs as friendly text rather than in wkt
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );

@@ -639,11 +639,11 @@ void QgsOptions::saveOptions()
settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
}

settings.setValue( "/Projections/defaultProjectionString", mLayerDefaultCrs.toProj4() );
settings.setValue( "/Projections/layerDefaultCrs", mLayerDefaultCrs.authid() );

// save 'on the fly' CRS transformation settings
settings.setValue( "/Projections/otfTransformEnabled", chkOtfTransform->isChecked() );
settings.setValue( "/Projections/projectDefaultProjectionString", mDefaultCrs.toProj4() );
settings.setValue( "/Projections/projectDefaultCrs", mDefaultCrs.authid() );

settings.setValue( "/qgis/measure/ellipsoid", getEllipsoidAcronym( cmbEllipsoid->currentText() ) );

@@ -758,10 +758,9 @@ void QgsOptions::on_pbnSelectProjection_clicked()

if ( mySelector->exec() )
{
mLayerDefaultCrs.createFromProj4( mySelector->selectedProj4String() );
QgsDebugMsg( QString( "Setting default project CRS to : %1").arg( mySelector->selectedProj4String() ) );
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " +
mLayerDefaultCrs.description() );
mLayerDefaultCrs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
QgsDebugMsg( QString( "Setting default project CRS to : %1" ).arg( mySelector->selectedAuthId() ) );
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );
QgsDebugMsg( QString( "------ Global Layer Default Projection Selection set to ----------\n%1" ).arg( leLayerGlobalCrs->text() ) );
}
else
@@ -782,10 +781,9 @@ void QgsOptions::on_pbnSelectOtfProjection_clicked()

if ( mySelector->exec() )
{
mDefaultCrs.createFromProj4( mySelector->selectedProj4String() );
QgsDebugMsg( QString( "Setting default project CRS to : %1").arg( mySelector->selectedProj4String() ) );
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " +
mDefaultCrs.description() );
mDefaultCrs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
QgsDebugMsg( QString( "Setting default project CRS to : %1" ).arg( mySelector->selectedAuthId() ) );
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leProjectGlobalCrs->text() ) );
}
else
@@ -654,9 +654,9 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked()
mySelector->setMessage();
mySelector->setOgcWmsCrsFilter( mCRSs );

QString myDefaultProjString = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCRSProj4String", GEOPROJ4 );
QString myDefaultCrs = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
QgsCoordinateReferenceSystem defaultCRS;
if ( defaultCRS.createFromProj4( myDefaultProjString ) )
if ( defaultCRS.createFromOgcWmsCrs( myDefaultCrs ) )
{
mySelector->setSelectedCrsId( defaultCRS.srsid() );
}
@@ -128,6 +128,12 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
{
QRegExp re( "(user|custom|qgis):(\\d+)", Qt::CaseInsensitive );
if ( re.exactMatch( theCrs ) && createFromSrsId( re.cap( 2 ).toInt() ) )
{
return true;
}

if ( loadFromDb( QgsApplication::srsDbFilePath(), "lower(auth_name||':'||auth_id)", theCrs.toLower() ) )
return true;

@@ -184,7 +190,7 @@ void QgsCoordinateReferenceSystem::validate()

if ( !mIsValidFlag )
// set the default
createFromProj4( GEOPROJ4 );
createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
}

bool QgsCoordinateReferenceSystem::createFromSrid( long id )
@@ -199,8 +205,8 @@ bool QgsCoordinateReferenceSystem::createFromEpsg( long id )

bool QgsCoordinateReferenceSystem::createFromSrsId( long id )
{
return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() :
QgsApplication::qgisUserDbFilePath(), "srs_id", QString::number( id ) );
return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() : QgsApplication::qgisUserDbFilePath(),
"srs_id", QString::number( id ) );
}

bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, QString value )
@@ -251,8 +257,13 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
int geo = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt();
mGeoFlag = ( geo == 0 ? false : true );
mGeoFlag = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;

if ( mSrsId >= USER_CRS_START_ID && mAuthId.isEmpty() )
{
mAuthId = QString( "USER:%1" ).arg( mSrsId );
}

setProj4String( toProj4 );
setMapUnits();
}
@@ -274,7 +285,7 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
QgsDebugMsg( "theWkt is uninitialised, operation failed" );
return mIsValidFlag;
}
QgsDebugMsg( "QgsCoordinateReferenceSystem::createFromWkt(QString theWkt) using: " + theWkt );
QgsDebugMsg( "wkt: " + theWkt );
QByteArray ba = theWkt.toLatin1();
const char *pWkt = ba.data();

@@ -611,9 +622,6 @@ QgsCoordinateReferenceSystem::RecordMap QgsCoordinateReferenceSystem::getRecord(
#endif

return myMap;



}

// Accessors -----------------------------------
@@ -87,9 +87,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
*
* Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.
*
* \note This function only deals with EpsgCrsId labels only at this time.
*
* \retval false if not given an EpsgCrsId label
* \retval false if not given an valid label
*/
bool createFromOgcWmsCrs( QString theCrs );

@@ -162,9 +162,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )


// get spatial ref system for ellipsoid
QString proj4 = "+proj=longlat +ellps=";
proj4 += ellipsoid;
proj4 += " +no_defs";
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
QgsCoordinateReferenceSystem destCRS;
destCRS.createFromProj4( proj4 );

@@ -4282,7 +4282,7 @@ void QgsVectorLayer::setCoordinateSystem()
}
else
{
mCRS->createFromProj4( GEOPROJ4 );
mCRS->createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
}
}
}
@@ -61,10 +61,14 @@ class GUI_EXPORT QgsGenericProjectionSelector : public QDialog, private Ui::QgsG
* 'define the CRS for this layer'.
*/
void setMessage( QString theMessage = "" );
QString selectedProj4String();
long selectedCrsId();
QString selectedAuthId();

#ifndef Q_MOC_RUN
QGISDEPRECATED
#endif
QString selectedProj4String();

#ifndef Q_MOC_RUN
QGISDEPRECATED
#endif
@@ -308,7 +308,7 @@ bool QgsNorthArrowPlugin::calculateNorthDirection()
{
// Use a geographic CRS to get lat/long to work out direction
QgsCoordinateReferenceSystem ourCRS;
ourCRS.createFromProj4( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" );
ourCRS.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
assert( ourCRS.isValid() );

QgsCoordinateTransform transform( outputCRS, ourCRS );

0 comments on commit 86895ff

Please sign in to comment.
You can’t perform that action at this time.