@@ -482,6 +482,33 @@ QgsRasterLayer::~QgsRasterLayer()
482
482
}
483
483
484
484
485
+ void QgsRasterLayer::setupDestSrs ()
486
+ {
487
+ QgsDebugMsg (" Layer registry has " + QString::number (QgsMapLayerRegistry::instance ()->count ()) + " layers" );
488
+
489
+ if (QgsMapLayerRegistry::instance ()->count () ==0 )
490
+ {
491
+ mCoordinateTransform ->destSRS ().createFromProj4 (
492
+ mCoordinateTransform ->sourceSRS ().proj4String ());
493
+ // first layer added will set the default project level projection
494
+ // TODO remove cast if poss!
495
+ int mySrsId = static_cast <int >(mCoordinateTransform ->sourceSRS ().srsid ());
496
+ if (mySrsId)
497
+ {
498
+ QgsProject::instance ()->writeEntry (" SpatialRefSys" ," /ProjectSRSID" ,mySrsId);
499
+ }
500
+ }
501
+ else
502
+ {
503
+ mCoordinateTransform ->destSRS ().createFromSrsId (
504
+ QgsProject::instance ()->readNumEntry (" SpatialRefSys" ," /ProjectSRSID" ,0 ));
505
+ }
506
+ if (!mCoordinateTransform ->destSRS ().isValid ())
507
+ {
508
+ mCoordinateTransform ->destSRS ().validate ();
509
+ }
510
+ }
511
+
485
512
486
513
bool
487
514
QgsRasterLayer::readFile ( QString const & fileName )
@@ -536,43 +563,12 @@ QgsRasterLayer::readFile( QString const & fileName )
536
563
{
537
564
mCoordinateTransform ->sourceSRS ().validate ();
538
565
}
539
- QString myDestWKT = QgsProject::instance ()->readEntry (" SpatialRefSys" ," /WKT" ,mySourceWKT);
540
- // set up the coordinat transform - in the case of raster this is mainly used to convert
541
- // the inverese projection of the map extents of the canvas when zzooming in etc. so
542
- // that they match the coordinate system of this layer
543
- // if no other layers exist, set the output projection to be
544
- // the same as the input projection, otherwise set the output to the
545
- // project srs
546
- QgsDebugMsg (" Layer registry has " + QString::number (QgsMapLayerRegistry::instance ()->count ()) + " layers" );
547
-
548
- if (QgsMapLayerRegistry::instance ()->count () ==0 )
549
- {
550
- mCoordinateTransform ->destSRS ().createFromProj4 (
551
- mCoordinateTransform ->sourceSRS ().proj4String ());
552
- // first layer added will set the default project level projection
553
- // TODO remove cast if poss!
554
- int mySrsId = static_cast <int >(mCoordinateTransform ->sourceSRS ().srsid ());
555
- if (mySrsId)
556
- {
557
- QgsProject::instance ()->writeEntry (" SpatialRefSys" ," /ProjectSRSID" ,mySrsId);
558
- }
559
- }
560
- else
561
- {
562
- mCoordinateTransform ->destSRS ().createFromSrsId (
563
- QgsProject::instance ()->readNumEntry (" SpatialRefSys" ," /ProjectSRSID" ,0 ));
564
- }
565
- if (!mCoordinateTransform ->destSRS ().isValid ())
566
- {
567
- mCoordinateTransform ->destSRS ().validate ();
568
- }
569
566
570
-
571
- // initialise the transform - you should do this any time one of the SRS's changes
567
+ setupDestSrs ();
572
568
569
+ // initialise the transform - you should do this any time one of the SRS's changes
573
570
mCoordinateTransform ->initialise ();
574
571
575
-
576
572
getMetadata ();
577
573
578
574
// Use the affine transform to get geo coordinates for
@@ -5057,21 +5053,19 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
5057
5053
//
5058
5054
// Get the layers project info and set up the QgsCoordinateTransform for this layer
5059
5055
//
5060
-
5061
- // get the project projection
5062
- // TODO: defaulting to this layer's projection if none exists....
5063
- QString myDestWKT = QgsProject::instance ()->readEntry (" SpatialRefSys" ," /WKT" ," " );
5064
-
5065
- // set up the coordinate transform - in the case of raster this is mainly used to convert
5066
- // the inverese projection of the map extents of the canvas when zooming in etc. so
5067
- // that they match the coordinate system of this layer
5068
- QgsDebugMsg (" QgsRasterLayer::setDataProvider: myDestWKT: " + myDestWKT);
5069
- // Hard-code the source coordinate reference for now
5070
- // TODO: Make WMS projection-aware.
5071
- mCoordinateTransform = new QgsCoordinateTransform (4326 ,
5072
- myDestWKT,
5073
- QgsSpatialRefSys::EPSG);
5074
-
5056
+
5057
+ mCoordinateTransform = new QgsCoordinateTransform ();
5058
+
5059
+ // Setup source SRS in the QgsCoordinateTransform
5060
+ QgsSpatialRefSys sourceSrs = QgsSpatialRefSys ();
5061
+ sourceSrs.createFromOgcWmsCrs (crs);
5062
+ mCoordinateTransform ->setSourceSRS (sourceSrs);
5063
+
5064
+ // Setup destination SRS in the QgsCoordinateTransform
5065
+ setupDestSrs ();
5066
+
5067
+ // initialise the transform - you should do this any time one of the SRS's changes
5068
+ mCoordinateTransform ->initialise ();
5075
5069
}
5076
5070
}
5077
5071
else
0 commit comments