Skip to content
Permalink
Browse files

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@5627 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au
morb_au committed Jul 24, 2006
1 parent eb4fc90 commit e57f22e05ffb1f84f906ef86d5ff8e26a0c5b10d
Showing with 52 additions and 48 deletions.
  1. +42 −48 src/raster/qgsrasterlayer.cpp
  2. +10 −0 src/raster/qgsrasterlayer.h
@@ -482,6 +482,33 @@ QgsRasterLayer::~QgsRasterLayer()
}


void QgsRasterLayer::setupDestSrs()
{
QgsDebugMsg("Layer registry has " + QString::number(QgsMapLayerRegistry::instance()->count()) + "layers");

if (QgsMapLayerRegistry::instance()->count() ==0)
{
mCoordinateTransform->destSRS().createFromProj4(
mCoordinateTransform->sourceSRS().proj4String());
//first layer added will set the default project level projection
//TODO remove cast if poss!
int mySrsId = static_cast<int>(mCoordinateTransform->sourceSRS().srsid());
if (mySrsId)
{
QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectSRSID",mySrsId);
}
}
else
{
mCoordinateTransform->destSRS().createFromSrsId(
QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",0));
}
if (!mCoordinateTransform->destSRS().isValid())
{
mCoordinateTransform->destSRS().validate();
}
}


bool
QgsRasterLayer::readFile( QString const & fileName )
@@ -536,43 +563,12 @@ QgsRasterLayer::readFile( QString const & fileName )
{
mCoordinateTransform->sourceSRS().validate();
}
QString myDestWKT = QgsProject::instance()->readEntry("SpatialRefSys","/WKT",mySourceWKT);
//set up the coordinat transform - in the case of raster this is mainly used to convert
//the inverese projection of the map extents of the canvas when zzooming in etc. so
//that they match the coordinate system of this layer
// if no other layers exist, set the output projection to be
// the same as the input projection, otherwise set the output to the
// project srs
QgsDebugMsg("Layer registry has " + QString::number(QgsMapLayerRegistry::instance()->count()) + "layers");

if (QgsMapLayerRegistry::instance()->count() ==0)
{
mCoordinateTransform->destSRS().createFromProj4(
mCoordinateTransform->sourceSRS().proj4String());
//first layer added will set the default project level projection
//TODO remove cast if poss!
int mySrsId = static_cast<int>(mCoordinateTransform->sourceSRS().srsid());
if (mySrsId)
{
QgsProject::instance()->writeEntry("SpatialRefSys","/ProjectSRSID",mySrsId);
}
}
else
{
mCoordinateTransform->destSRS().createFromSrsId(
QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",0));
}
if (!mCoordinateTransform->destSRS().isValid())
{
mCoordinateTransform->destSRS().validate();
}


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

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


getMetadata();

// Use the affine transform to get geo coordinates for
@@ -5057,21 +5053,19 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
//
// Get the layers project info and set up the QgsCoordinateTransform for this layer
//

// get the project projection
// TODO: defaulting to this layer's projection if none exists....
QString myDestWKT = QgsProject::instance()->readEntry("SpatialRefSys","/WKT","");

// set up the coordinate transform - in the case of raster this is mainly used to convert
// the inverese projection of the map extents of the canvas when zooming in etc. so
// that they match the coordinate system of this layer
QgsDebugMsg("QgsRasterLayer::setDataProvider: myDestWKT: " + myDestWKT);
// Hard-code the source coordinate reference for now
// TODO: Make WMS projection-aware.
mCoordinateTransform = new QgsCoordinateTransform(4326,
myDestWKT,
QgsSpatialRefSys::EPSG);


mCoordinateTransform = new QgsCoordinateTransform();

// Setup source SRS in the QgsCoordinateTransform
QgsSpatialRefSys sourceSrs = QgsSpatialRefSys();
sourceSrs.createFromOgcWmsCrs(crs);
mCoordinateTransform->setSourceSRS(sourceSrs);

// Setup destination SRS in the QgsCoordinateTransform
setupDestSrs();

// initialise the transform - you should do this any time one of the SRS's changes
mCoordinateTransform->initialise();
}
}
else
@@ -968,6 +968,16 @@ public slots:
/** \brief Update the layer if it is outdated */
bool update ();

/**
set up the coordinate transform - in the case of raster this is mainly used to convert
the inverese projection of the map extents of the canvas when zooming in etc. so
that they match the coordinate system of this layer
if no other layers exist, set the output projection to be
the same as the input projection, otherwise set the output to the
project srs
*/
void setupDestSrs();

//
// Private member vars
//

0 comments on commit e57f22e

Please sign in to comment.
You can’t perform that action at this time.