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
This commit is contained in:
morb_au 2006-07-24 02:29:34 +00:00
parent 6e6c1cb3c0
commit 14e1c86540
2 changed files with 52 additions and 48 deletions

View File

@ -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 bool
QgsRasterLayer::readFile( QString const & fileName ) QgsRasterLayer::readFile( QString const & fileName )
@ -536,43 +563,12 @@ QgsRasterLayer::readFile( QString const & fileName )
{ {
mCoordinateTransform->sourceSRS().validate(); 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) setupDestSrs();
{
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
// initialise the transform - you should do this any time one of the SRS's changes
mCoordinateTransform->initialise(); mCoordinateTransform->initialise();
getMetadata(); getMetadata();
// Use the affine transform to get geo coordinates for // 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 layers project info and set up the QgsCoordinateTransform for this layer
// //
// get the project projection mCoordinateTransform = new QgsCoordinateTransform();
// TODO: defaulting to this layer's projection if none exists....
QString myDestWKT = QgsProject::instance()->readEntry("SpatialRefSys","/WKT",""); // Setup source SRS in the QgsCoordinateTransform
QgsSpatialRefSys sourceSrs = QgsSpatialRefSys();
// set up the coordinate transform - in the case of raster this is mainly used to convert sourceSrs.createFromOgcWmsCrs(crs);
// the inverese projection of the map extents of the canvas when zooming in etc. so mCoordinateTransform->setSourceSRS(sourceSrs);
// that they match the coordinate system of this layer
QgsDebugMsg("QgsRasterLayer::setDataProvider: myDestWKT: " + myDestWKT); // Setup destination SRS in the QgsCoordinateTransform
// Hard-code the source coordinate reference for now setupDestSrs();
// TODO: Make WMS projection-aware.
mCoordinateTransform = new QgsCoordinateTransform(4326, // initialise the transform - you should do this any time one of the SRS's changes
myDestWKT, mCoordinateTransform->initialise();
QgsSpatialRefSys::EPSG);
} }
} }
else else

View File

@ -968,6 +968,16 @@ private:
/** \brief Update the layer if it is outdated */ /** \brief Update the layer if it is outdated */
bool update (); 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 // Private member vars
// //