crs-borys.diff

small modifications - Borys Jurgiel, 2011-03-10 01:50 AM

Download (14 KB)

View differences:

src/app/qgsoptions.cpp (working copy)
188 188
  {
189 189
    radUseGlobalProjection->setChecked( true );
190 190
  }
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 );
193 193
  //display the crs as friendly text rather than in wkt
194 194
  leLayerGlobalCrs->setText( mLayerDefaultCrs.authid() + " - " + mLayerDefaultCrs.description() );
195 195

  
196 196
  //on the fly CRS transformation settings
197 197
  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 );
201 201
  //display the crs as friendly text rather than in wkt
202 202
  leProjectGlobalCrs->setText( mDefaultCrs.authid() + " - " + mDefaultCrs.description() );
203 203

  
......
639 639
    settings.setValue( "/Projections/defaultBehaviour", "useGlobal" );
640 640
  }
641 641

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

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

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

  
......
758 758

  
759 759
  if ( mySelector->exec() )
760 760
  {
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() );
765 764
    QgsDebugMsg( QString( "------ Global Layer Default Projection Selection set to ----------\n%1" ).arg( leLayerGlobalCrs->text() ) );
766 765
  }
767 766
  else
......
782 781

  
783 782
  if ( mySelector->exec() )
784 783
  {
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() );
789 787
    QgsDebugMsg( QString( "------ Global OTF Projection Selection set to ----------\n%1" ).arg( leProjectGlobalCrs->text() ) );
790 788
  }
791 789
  else
src/app/qgsnewvectorlayerdialog.cpp (working copy)
155 155
  if ( mySelector->exec() )
156 156
  {
157 157
    mCrsId = mySelector->selectedCrsId();
158
    leSpatialRefSys->setText( mySelector->selectedProj4String() );
158
    leSpatialRefSys->setText( mySelector->selectedAuthId() );
159 159
  }
160 160
  else
161 161
  {
src/app/qgswmssourceselect.cpp (working copy)
654 654
  mySelector->setMessage();
655 655
  mySelector->setOgcWmsCrsFilter( mCRSs );
656 656

  
657
  QString myDefaultProjString = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCRSProj4String", GEOPROJ4 );
657
  QString myDefaultCrs = QgsProject::instance()->readEntry( "SpatialRefSys", "/ProjectCrs", GEO_EPSG_CRS_AUTHID );
658 658
  QgsCoordinateReferenceSystem defaultCRS;
659
  if ( defaultCRS.createFromProj4( myDefaultProjString ) )
659
  if ( defaultCRS.createFromOgcWmsCrs( myDefaultCrs ) )
660 660
  {
661 661
    mySelector->setSelectedCrsId( defaultCRS.srsid() );
662 662
  }
src/app/qgisapp.cpp (working copy)
319 319
 */
320 320
static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )
321 321
{
322
  QString toProj4;
322
  QString authid;
323 323
  QSettings mySettings;
324 324
  QString myDefaultProjectionOption = mySettings.value( "/Projections/defaultBehaviour" ).toString();
325 325
  if ( myDefaultProjectionOption == "prompt" )
......
327 327
    //@note this class is not a descendent of QWidget so we cant pass
328 328
    //it in the ctor of the layer projection selector
329 329

  
330
    QgsGenericProjectionSelector * mySelector = new QgsGenericProjectionSelector();
330
    QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector();
331 331
    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 ) )
335 335
    {
336
      mySelector->setSelectedCrsId( defaultCRS.srsid() );
336
      mySelector->setSelectedCrsId( defaultCrs.srsid() );
337 337
    }
338 338

  
339 339
    QApplication::setOverrideCursor( Qt::ArrowCursor );
......
341 341
    if ( mySelector->exec() )
342 342
    {
343 343
      QgsDebugMsg( "Layer srs set from dialog: " + QString::number( mySelector->selectedCrsId() ) );
344
      srs->createFromProj4( mySelector->selectedProj4String() );
344
      srs->createFromOgcWmsCrs( mySelector->selectedAuthId() );
345 345
    }
346 346

  
347 347
    QApplication::restoreOverrideCursor();
......
351 351
  else if ( myDefaultProjectionOption == "useProject" )
352 352
  {
353 353
    // 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 );
356 356
    QgisApp::instance()->statusBar()->showMessage( QObject::tr( "CRS undefined - defaulting to project CRS" ) );
357
    srs->createFromProj4( toProj4 );
357
    srs->createFromOgcWmsCrs( authid );
358 358
  }
359 359
  else ///Projections/defaultBehaviour==useGlobal
360 360
  {
361
    srs->createFromProj4( mySettings.value( "/Projections/defaultProjectionString", GEOPROJ4 ).toString() );
361
    srs->createFromOgcWmsCrs( mySettings.value( "/Projections/layerDefaultCrs", GEO_EPSG_CRS_AUTHID ).toString() );
362 362
    QgisApp::instance()->statusBar()->showMessage( QObject::tr( "CRS undefined - defaulting to default CRS" ) );
363 363
  }
364 364
}
......
2489 2489

  
2490 2490
  // set project CRS
2491 2491
  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();
2493 2493
  QgsCoordinateReferenceSystem srs;
2494
  srs.createFromProj4( projString );
2494
  srs.createFromOgcWmsCrs( defCrs );
2495 2495
  myRenderer->setDestinationSrs( srs );
2496 2496
  // write the projections _proj string_ to project settings
2497
  prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
2497
  prj->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
2498 2498
  prj->dirty( false );
2499 2499
  if ( srs.mapUnits() != QGis::UnknownUnit )
2500 2500
  {
......
4809 4809

  
4810 4810
    // set project CRS
4811 4811
    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();
4813 4813
    QgsCoordinateReferenceSystem srs;
4814
    srs.createFromProj4( projString );
4814
    srs.createFromOgcWmsCrs( defCrs );
4815 4815
    myRenderer->setDestinationSrs( srs );
4816 4816
    // write the projections _proj string_ to project settings
4817
    QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projString );
4817
    QgsProject::instance()->writeEntry( "SpatialRefSys", "/ProjectCrs", defCrs );
4818 4818
    if ( srs.mapUnits() != QGis::UnknownUnit )
4819 4819
    {
4820 4820
      myRenderer->setMapUnits( srs.mapUnits() );
src/plugins/north_arrow/plugin.cpp (working copy)
308 308
    {
309 309
      // Use a geographic CRS to get lat/long to work out direction
310 310
      QgsCoordinateReferenceSystem ourCRS;
311
      ourCRS.createFromProj4( "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" );
311
      ourCRS.createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
312 312
      assert( ourCRS.isValid() );
313 313

  
314 314
      QgsCoordinateTransform transform( outputCRS, ourCRS );
src/gui/qgsgenericprojectionselector.h (working copy)
61 61
     * 'define the CRS for this layer'.
62 62
     */
63 63
    void setMessage( QString theMessage = "" );
64
    QString selectedProj4String();
65 64
    long selectedCrsId();
66 65
    QString selectedAuthId();
67 66

  
68 67
#ifndef Q_MOC_RUN
69 68
    QGISDEPRECATED
70 69
#endif
70
    QString selectedProj4String();
71

  
72
#ifndef Q_MOC_RUN
73
    QGISDEPRECATED
74
#endif
71 75
    long selectedEpsg();
72 76

  
73 77
    void setSelectedCrsName( QString theName );
src/core/qgsdistancearea.cpp (working copy)
162 162

  
163 163

  
164 164
  // 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";
168 166
  QgsCoordinateReferenceSystem destCRS;
169 167
  destCRS.createFromProj4( proj4 );
170 168

  
src/core/qgscoordinatereferencesystem.cpp (working copy)
37 37
#include <ogr_srs_api.h>
38 38
#include <cpl_error.h>
39 39
#include <cpl_conv.h>
40
#include "qgslogger.h"
41 40

  
42 41
CUSTOM_CRS_VALIDATION QgsCoordinateReferenceSystem::mCustomSrsValidation = NULL;
43 42

  
......
129 128

  
130 129
bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( QString theCrs )
131 130
{
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

  
132 137
  if ( loadFromDb( QgsApplication::srsDbFilePath(), "lower(auth_name||':'||auth_id)", theCrs.toLower() ) )
133 138
    return true;
134 139

  
......
185 190

  
186 191
  if ( !mIsValidFlag )
187 192
    // set the default
188
    createFromProj4( GEOPROJ4 );
193
    createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
189 194
}
190 195

  
191 196
bool QgsCoordinateReferenceSystem::createFromSrid( long id )
......
200 205

  
201 206
bool QgsCoordinateReferenceSystem::createFromSrsId( long id )
202 207
{
203
  return loadFromDb( id < USER_CRS_START_ID ? QgsApplication::srsDbFilePath() :
204
                     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 ) );
205 210
}
206 211

  
207 212
bool QgsCoordinateReferenceSystem::loadFromDb( QString db, QString expression, QString value )
......
252 257
    QString toProj4 = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 4 ) );
253 258
    mSRID = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 5 ) ).toLong();
254 259
    mAuthId = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 6 ) );
255
    int geo = QString::fromUtf8(( char * )sqlite3_column_text( myPreparedStatement, 7 ) ).toInt();
256
    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

  
257 267
    setProj4String( toProj4 );
258 268
    setMapUnits();
259 269
  }
......
275 285
    QgsDebugMsg( "theWkt is uninitialised, operation failed" );
276 286
    return mIsValidFlag;
277 287
  }
278
  QgsDebugMsg( "QgsCoordinateReferenceSystem::createFromWkt(QString theWkt) using: " + theWkt );
288
  QgsDebugMsg( "wkt: " + theWkt );
279 289
  QByteArray ba = theWkt.toLatin1();
280 290
  const char *pWkt = ba.data();
281 291

  
......
612 622
#endif
613 623

  
614 624
  return myMap;
615

  
616

  
617

  
618 625
}
619 626

  
620 627
// Accessors -----------------------------------
src/core/qgsvectorlayer.cpp (working copy)
4283 4283
    }
4284 4284
    else
4285 4285
    {
4286
      mCRS->createFromProj4( GEOPROJ4 );
4286
      mCRS->createFromOgcWmsCrs( GEO_EPSG_CRS_AUTHID );
4287 4287
    }
4288 4288
  }
4289 4289
}