Skip to content

Commit 4c7b539

Browse files
author
jef
committed
apply #3586
git-svn-id: http://svn.osgeo.org/qgis/trunk@15419 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e59fb6b commit 4c7b539

11 files changed

+60
-56
lines changed

python/core/qgscoordinatereferencesystem.sip

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ class QgsCoordinateReferenceSystem
4646
*
4747
* Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.
4848
*
49-
* \note This function only deals with Epsg Id labels only at this time.
50-
*
51-
* \retval FALSE if not given an Epsg Id label
49+
* \retval false if not given an valid label
5250
*/
5351
bool createFromOgcWmsCrs(QString theCrs);
5452

src/app/qgisapp.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -319,29 +319,29 @@ static QgsMessageOutput *messageOutputViewer_()
319319
*/
320320
static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
321321
{
322-
QString toProj4;
322+
QString authid;
323323
QSettings mySettings;
324324
QString myDefaultProjectionOption = mySettings.value( "/Projections/defaultBehaviour" ).toString();
325325
if ( myDefaultProjectionOption == "prompt" )
326326
{
327327
//@note this class is not a descendent of QWidget so we cant pass
328328
//it in the ctor of the layer projection selector
329329

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

339339
QApplication::setOverrideCursor( Qt::ArrowCursor );
340340

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

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

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

48104810
// set project CRS
48114811
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
4812-
QString projString = mySettings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
4812+
QString defCrs = mySettings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
48134813
QgsCoordinateReferenceSystem srs;
4814-
srs.createFromProj4( projString );
4814+
srs.createFromOgcWmsCrs( defCrs );
48154815
myRenderer->setDestinationSrs( srs );
48164816
// write the projections _proj string_ to project settings
4817-
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
4817+
QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
48184818
if ( srs.mapUnits() != QGis::UnknownUnit )
48194819
{
48204820
myRenderer->setMapUnits( srs.mapUnits() );

src/app/qgsnewvectorlayerdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void QgsNewVectorLayerDialog::on_pbnChangeSpatialRefSys_clicked()
155155
if ( mySelector->exec() )
156156
{
157157
mCrsId = mySelector->selectedCrsId();
158-
leSpatialRefSys->setText( mySelector->selectedProj4String() );
158+
leSpatialRefSys->setText( mySelector->selectedAuthId() );
159159
}
160160
else
161161
{

src/app/qgsoptions.cpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
188188
{
189189
radUseGlobalProjection->setChecked( true );
190190
}
191-
QString myLayerDefaultCrsString = settings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString();
192-
mLayerDefaultCrs.createFromProj4( myLayerDefaultCrsString );
191+
QString myLayerDefaultCrs = settings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
192+
mLayerDefaultCrs.createFromOgcWmsCrs( myLayerDefaultCrs );
193193
//display the crs as friendly text rather than in wkt
194194
leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );
195195

196196
//on the fly CRS transformation settings
197197
chkOtfTransform->setChecked( settings.value( "/Projections/otfTransformEnabled", 0 ).toBool() );
198-
199-
QString myDefaultCrsString = settings.value( "/Projections/projectDefaultProjectionString", GEOPROJ4 ).toString();
200-
mDefaultCrs.createFromProj4( myDefaultCrsString );
198+
199+
QString myDefaultCrs = settings.value( "/Projections/projectDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString();
200+
mDefaultCrs.createFromOgcWmsCrs( myDefaultCrs );
201201
//display the crs as friendly text rather than in wkt
202202
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
203203

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

642-
settings.setValue( "/Projections/defaultProjectionString", mLayerDefaultCrs.toProj4() );
642+
settings.setValue( "/Projections/layerDefaultCrs", mLayerDefaultCrs.authid() );
643643

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

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

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

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

783782
if ( mySelector->exec() )
784783
{
785-
mDefaultCrs.createFromProj4( mySelector->selectedProj4String() );
786-
QgsDebugMsg( QString( "Setting default project CRS to : %1").arg( mySelector->selectedProj4String() ) );
787-
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " +
788-
mDefaultCrs.description() );
784+
mDefaultCrs.createFromOgcWmsCrs( mySelector->selectedAuthId() );
785+
QgsDebugMsg( QString( "Setting default project CRS to : %1" ).arg( mySelector->selectedAuthId() ) );
786+
leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
789787
QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leProjectGlobalCrs->text() ) );
790788
}
791789
else

src/app/qgswmssourceselect.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,9 @@ void QgsWMSSourceSelect::on_btnChangeSpatialRefSys_clicked()
654654
mySelector->setMessage();
655655
mySelector->setOgcWmsCrsFilter( mCRSs );
656656

657-
QString myDefaultProjString = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCRSProj4String", GEOPROJ4 );
657+
QString myDefaultCrs = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
658658
QgsCoordinateReferenceSystem defaultCRS;
659-
if ( defaultCRS.createFromProj4( myDefaultProjString ) )
659+
if ( defaultCRS.createFromOgcWmsCrs( myDefaultCrs ) )
660660
{
661661
mySelector->setSelectedCrsId( defaultCRS.srsid() );
662662
}

src/core/qgscoordinatereferencesystem.cpp

+17-9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ bool QgsCoordinateReferenceSystem::createFromString( const QString theDefinition
128128

129129
bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
130130
{
131+
QRegExp re( "(user|custom|qgis):(\\d+)", Qt::CaseInsensitive );
132+
if ( re.exactMatch( theCrs ) && createFromSrsId( re.cap( 2 ).toInt() ) )
133+
{
134+
return true;
135+
}
136+
131137
if ( loadFromDb( QgsApplication::srsDbFilePath(), "lower(auth_name||':'||auth_id)", theCrs.toLower() ) )
132138
return true;
133139

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

185191
if ( !mIsValidFlag )
186192
// set the default
187-
createFromProj4( GEOPROJ4 );
193+
createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
188194
}
189195

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

200206
bool QgsCoordinateReferenceSystem::createFromSrsId( long id )
201207
{
202-
return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() :
203-
QgsApplication::qgisUserDbFilePath(), "srs_id", QString::number( id ) );
208+
return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() : QgsApplication::qgisUserDbFilePath(),
209+
"srs_id", QString::number( id ) );
204210
}
205211

206212
bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, QString value )
@@ -251,8 +257,13 @@ bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, Q
251257
QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
252258
mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
253259
mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
254-
int geo = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt();
255-
mGeoFlag = ( geo == 0 ? false : true );
260+
mGeoFlag = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt() != 0;
261+
262+
if ( mSrsId >= USER_CRS_START_ID && mAuthId.isEmpty() )
263+
{
264+
mAuthId = QString( "USER:%1" ).arg( mSrsId );
265+
}
266+
256267
setProj4String( toProj4 );
257268
setMapUnits();
258269
}
@@ -274,7 +285,7 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
274285
QgsDebugMsg( "theWkt is uninitialised, operation failed" );
275286
return mIsValidFlag;
276287
}
277-
QgsDebugMsg( "QgsCoordinateReferenceSystem::createFromWkt(QString theWkt) using: " + theWkt );
288+
QgsDebugMsg( "wkt: " + theWkt );
278289
QByteArray ba = theWkt.toLatin1();
279290
const char *pWkt = ba.data();
280291

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

613624
return myMap;
614-
615-
616-
617625
}
618626

619627
// Accessors -----------------------------------

src/core/qgscoordinatereferencesystem.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
8787
*
8888
* Sets this CRS to the given OGC WMS-format Coordinate Reference Systems.
8989
*
90-
* \note This function only deals with EpsgCrsId labels only at this time.
91-
*
92-
* \retval false if not given an EpsgCrsId label
90+
* \retval false if not given an valid label
9391
*/
9492
bool createFromOgcWmsCrs( QString theCrs );
9593

src/core/qgsdistancearea.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid )
162162

163163

164164
// get spatial ref system for ellipsoid
165-
QString proj4 = "+proj=longlat +ellps=";
166-
proj4 += ellipsoid;
167-
proj4 += " +no_defs";
165+
QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs";
168166
QgsCoordinateReferenceSystem destCRS;
169167
destCRS.createFromProj4( proj4 );
170168

src/core/qgsvectorlayer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,7 @@ void QgsVectorLayer::setCoordinateSystem()
42824282
}
42834283
else
42844284
{
4285-
mCRS->createFromProj4( GEOPROJ4 );
4285+
mCRS->createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
42864286
}
42874287
}
42884288
}

src/gui/qgsgenericprojectionselector.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ class GUI_EXPORT QgsGenericProjectionSelector : public QDialog, private Ui::QgsG
6161
* 'define the CRS for this layer'.
6262
*/
6363
void setMessage( QString theMessage = "" );
64-
QString selectedProj4String();
6564
long selectedCrsId();
6665
QString selectedAuthId();
6766

67+
#ifndef Q_MOC_RUN
68+
QGISDEPRECATED
69+
#endif
70+
QString selectedProj4String();
71+
6872
#ifndef Q_MOC_RUN
6973
QGISDEPRECATED
7074
#endif

src/plugins/north_arrow/plugin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ bool QgsNorthArrowPlugin::calculateNorthDirection()
308308
{
309309
// Use a geographic CRS to get lat/long to work out direction
310310
QgsCoordinateReferenceSystem ourCRS;
311-
ourCRS.createFromProj4( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" );
311+
ourCRS.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
312312
assert( ourCRS.isValid() );
313313

314314
QgsCoordinateTransform transform( outputCRS, ourCRS );

0 commit comments

Comments
 (0)