@@ -491,7 +491,9 @@ void QgsRasterLayer::setupDestSrs()
491
491
{
492
492
QgsDebugMsg (" Layer registry has " + QString::number (QgsMapLayerRegistry::instance ()->count ()) + " layers" );
493
493
494
- if (QgsMapLayerRegistry::instance ()->count () ==0 )
494
+ // No reason to set project SRS
495
+ // if (QgsMapLayerRegistry::instance()->count() ==0)
496
+ if (NULL )
495
497
{
496
498
mCoordinateTransform ->destSRS ().createFromProj4 (
497
499
mCoordinateTransform ->sourceSRS ().proj4String ());
@@ -551,22 +553,32 @@ QgsRasterLayer::readFile( QString const & fileName )
551
553
QPixmap myPyramidPixmap (myThemePath + " /mIconPyramid.png" );
552
554
QPixmap myNoPyramidPixmap (myThemePath + " /mIconNoPyramid.png" );
553
555
554
- // Get the layer's projection info and set up the
555
- // QgsCoordinateTransform for this layer
556
- // NOTE: we must do this before getMetadata is called
557
- mCoordinateTransform = new QgsCoordinateTransform ();
558
- QString mySourceWKT = getProjectionWKT ();
559
556
560
- QgsDebugMsg (" --------------------------------------------------------------------------------------" );
561
- QgsDebugMsg (" QgsRasterLayer::readFile --- using wkt\n " + mySourceWKT);
562
- QgsDebugMsg (" --------------------------------------------------------------------------------------" );
563
-
564
- mCoordinateTransform ->sourceSRS ().createFromWkt (mySourceWKT);
565
- // get the project projection, defaulting to this layer's projection
566
- // if none exists....
567
- if (!mCoordinateTransform ->sourceSRS ().isValid ())
557
+ if (mCoordinateTransform && mCoordinateTransform ->sourceSRS ().isValid ())
558
+ {
559
+ // Layer source SRS is already set, probably by reading XML from project file
560
+ // This setting should override any GDAL info.
561
+ QgsDebugMsg (" Source SRS is alerady set. Ignoring GDAL projection info" );
562
+ }
563
+ else
568
564
{
569
- mCoordinateTransform ->sourceSRS ().validate ();
565
+ // Get the layer's projection info and set up the
566
+ // QgsCoordinateTransform for this layer
567
+ // NOTE: we must do this before getMetadata is called
568
+ mCoordinateTransform = new QgsCoordinateTransform ();
569
+ QString mySourceWKT = getProjectionWKT ();
570
+
571
+ QgsDebugMsg (" --------------------------------------------------------------------------------------" );
572
+ QgsDebugMsg (" QgsRasterLayer::readFile --- using wkt\n " + mySourceWKT);
573
+ QgsDebugMsg (" --------------------------------------------------------------------------------------" );
574
+
575
+ mCoordinateTransform ->sourceSRS ().createFromWkt (mySourceWKT);
576
+ // get the project projection, defaulting to this layer's projection
577
+ // if none exists....
578
+ if (!mCoordinateTransform ->sourceSRS ().isValid ())
579
+ {
580
+ mCoordinateTransform ->sourceSRS ().validate ();
581
+ }
570
582
}
571
583
572
584
setupDestSrs ();
@@ -4527,6 +4539,8 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
4527
4539
QgsDebugMsg (" ReadXml: red band name " + redBandNameQString);
4528
4540
QgsDebugMsg (" ReadXml: green band name " + greenBandNameQString);
4529
4541
QgsDebugMsg (" Drawing style " + getDrawingStyleAsQString ());
4542
+ QgsDebugMsg (" Source SRS: " + mCoordinateTransform ->sourceSRS ().description ());
4543
+ QgsDebugMsg (" Dest SRS: " + mCoordinateTransform ->destSRS ().description ());
4530
4544
4531
4545
return true ;
4532
4546
0 commit comments