Skip to content

Commit 14e1c86

Browse files
author
morb_au
committed
Fix for trac ticket #11.
When a new WMS layer is opened and it is the first layer on the canvas, the project projection is now copied from that used when selecting that WMS layer. Previously this was hard coded to EPSG:4326 / WGS 84. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5627 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 6e6c1cb commit 14e1c86

File tree

2 files changed

+52
-48
lines changed

2 files changed

+52
-48
lines changed

src/raster/qgsrasterlayer.cpp

+42-48
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,33 @@ QgsRasterLayer::~QgsRasterLayer()
482482
}
483483

484484

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+
485512

486513
bool
487514
QgsRasterLayer::readFile( QString const & fileName )
@@ -536,43 +563,12 @@ QgsRasterLayer::readFile( QString const & fileName )
536563
{
537564
mCoordinateTransform->sourceSRS().validate();
538565
}
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-
}
569566

570-
571-
//initialise the transform - you should do this any time one of the SRS's changes
567+
setupDestSrs();
572568

569+
// initialise the transform - you should do this any time one of the SRS's changes
573570
mCoordinateTransform->initialise();
574571

575-
576572
getMetadata();
577573

578574
// Use the affine transform to get geo coordinates for
@@ -5057,21 +5053,19 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
50575053
//
50585054
// Get the layers project info and set up the QgsCoordinateTransform for this layer
50595055
//
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();
50755069
}
50765070
}
50775071
else

src/raster/qgsrasterlayer.h

+10
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,16 @@ public slots:
968968
/** \brief Update the layer if it is outdated */
969969
bool update ();
970970

971+
/**
972+
set up the coordinate transform - in the case of raster this is mainly used to convert
973+
the inverese projection of the map extents of the canvas when zooming in etc. so
974+
that they match the coordinate system of this layer
975+
if no other layers exist, set the output projection to be
976+
the same as the input projection, otherwise set the output to the
977+
project srs
978+
*/
979+
void setupDestSrs();
980+
971981
//
972982
// Private member vars
973983
//

0 commit comments

Comments
 (0)