Skip to content
Permalink
Browse files

Fixing reading projections when opening project file.

1) Default project projections is now set from XML only, and does not get
   reset from any layers added.
2) Raster layers get the source SRS from XML only, and does not read the
   GDAL view of projection.
Also added som debug outputs


git-svn-id: http://svn.osgeo.org/qgis/branches/Release-0_8_0@6363 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann
homann committed Jan 1, 2007
1 parent 3e8d436 commit f3107f0b39b3839de2e67aadce71139e4dc415f4
@@ -119,6 +119,7 @@ void QgsCoordinateTransform::initialise()
// Pass through with no projection since we have no idea what the layer
// coordinates are and projecting them may not be appropriate
mShortCircuit = true;
QgsDebugMsg("SourceSRS deemed invalid!");
return;
}

@@ -130,22 +131,6 @@ void QgsCoordinateTransform::initialise()
mDestSRS.createFromProj4(mSourceSRS.proj4String());
}

//XXX todo overload == operator for QgsSpatialRefSys
//at the moment srs.parameters contains the whole proj def...soon it wont...
//if (mSourceSRS->proj4String() == mDestSRS->proj4String())
if (mSourceSRS == mDestSRS)
{
// If the source and destination projection are the same, set the short
// circuit flag (no transform takes place)
mShortCircuit=true;
return;
}
else
{
// Transform must take place
mShortCircuit=false;
}

// init the projections (destination and source)
mDestinationProjection = pj_init_plus(mDestSRS.proj4String());
mSourceProjection = pj_init_plus(mSourceSRS.proj4String());
@@ -176,6 +161,23 @@ void QgsCoordinateTransform::initialise()
QgsDebugMsg("------------------------------------------------------------");
}
#endif

//XXX todo overload == operator for QgsSpatialRefSys
//at the moment srs.parameters contains the whole proj def...soon it wont...
//if (mSourceSRS->proj4String() == mDestSRS->proj4String())
if (mSourceSRS == mDestSRS)
{
// If the source and destination projection are the same, set the short
// circuit flag (no transform takes place)
mShortCircuit=true;
QgsDebugMsg("Source/Dest SRS equal, shortcircuit is set.");
}
else
{
// Transform must take place
mShortCircuit=false;
}

}

//
@@ -260,6 +260,7 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
QDomNode srsNode = layer_node.namedItem("coordinatetransform");
if( ! srsNode.isNull() )
{
qDebug("Reading coordinatetransform from project file");
mCoordinateTransform=new QgsCoordinateTransform();
mCoordinateTransform->readXML(srsNode);
}
@@ -268,7 +269,7 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
QDomNode transparencyNode = layer_node.namedItem("transparencyLevelInt");
if ( ! transparencyNode.isNull() )
{
// set transparency level only if it's in project
// set transparency level only if it's in project
// (otherwise it sets the layer transparent)
QDomElement myElement = transparencyNode.toElement();
setTransparency(myElement.text().toInt());
@@ -25,6 +25,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrenderer.h"
#include "qgslogger.h"

//qt includes
#include <QColorDialog>
@@ -61,6 +62,7 @@
}
// set the default wkt to WGS 84
long mySRSID = QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectSRSID",GEOSRS_ID);
QgsDebugMsg("Read project SRSID: " + QString::number(mySRSID));
projectionSelector->setSelectedSRSID(mySRSID);


@@ -3506,7 +3506,9 @@ void QgsVectorLayer::setCoordinateSystem()
// project srs

QgsDebugMsg("Layer registry has " + QString::number(QgsMapLayerRegistry::instance()->count()) + " layers ");
if (QgsMapLayerRegistry::instance()->count() ==0)
// No reason to set project SRS
// if (QgsMapLayerRegistry::instance()->count() ==0)
if (NULL)
{
mCoordinateTransform->destSRS().createFromProj4(
mCoordinateTransform->sourceSRS().proj4String());
@@ -491,7 +491,9 @@ void QgsRasterLayer::setupDestSrs()
{
QgsDebugMsg("Layer registry has " + QString::number(QgsMapLayerRegistry::instance()->count()) + "layers");

if (QgsMapLayerRegistry::instance()->count() ==0)
// No reason to set project SRS
// if (QgsMapLayerRegistry::instance()->count() ==0)
if (NULL)
{
mCoordinateTransform->destSRS().createFromProj4(
mCoordinateTransform->sourceSRS().proj4String());
@@ -551,22 +553,32 @@ QgsRasterLayer::readFile( QString const & fileName )
QPixmap myPyramidPixmap(myThemePath + "/mIconPyramid.png");
QPixmap myNoPyramidPixmap(myThemePath + "/mIconNoPyramid.png");

// Get the layer's projection info and set up the
// QgsCoordinateTransform for this layer
// NOTE: we must do this before getMetadata is called
mCoordinateTransform = new QgsCoordinateTransform();
QString mySourceWKT = getProjectionWKT();

QgsDebugMsg("--------------------------------------------------------------------------------------");
QgsDebugMsg("QgsRasterLayer::readFile --- using wkt\n" + mySourceWKT);
QgsDebugMsg("--------------------------------------------------------------------------------------");

mCoordinateTransform->sourceSRS().createFromWkt(mySourceWKT);
//get the project projection, defaulting to this layer's projection
//if none exists....
if (!mCoordinateTransform->sourceSRS().isValid())
if (mCoordinateTransform && mCoordinateTransform->sourceSRS().isValid())
{
// Layer source SRS is already set, probably by reading XML from project file
// This setting should override any GDAL info.
QgsDebugMsg("Source SRS is alerady set. Ignoring GDAL projection info");
}
else
{
mCoordinateTransform->sourceSRS().validate();
// Get the layer's projection info and set up the
// QgsCoordinateTransform for this layer
// NOTE: we must do this before getMetadata is called
mCoordinateTransform = new QgsCoordinateTransform();
QString mySourceWKT = getProjectionWKT();

QgsDebugMsg("--------------------------------------------------------------------------------------");
QgsDebugMsg("QgsRasterLayer::readFile --- using wkt\n" + mySourceWKT);
QgsDebugMsg("--------------------------------------------------------------------------------------");

mCoordinateTransform->sourceSRS().createFromWkt(mySourceWKT);
//get the project projection, defaulting to this layer's projection
//if none exists....
if (!mCoordinateTransform->sourceSRS().isValid())
{
mCoordinateTransform->sourceSRS().validate();
}
}

setupDestSrs();
@@ -4527,6 +4539,8 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
QgsDebugMsg("ReadXml: red band name " + redBandNameQString);
QgsDebugMsg("ReadXml: green band name " + greenBandNameQString);
QgsDebugMsg("Drawing style " + getDrawingStyleAsQString());
QgsDebugMsg("Source SRS: " + mCoordinateTransform->sourceSRS().description());
QgsDebugMsg("Dest SRS: " + mCoordinateTransform->destSRS().description());

return true;

0 comments on commit f3107f0

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