Skip to content

Commit

Permalink
Fixing reading projections when opening project file.
Browse files Browse the repository at this point in the history
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 committed Jan 1, 2007
1 parent 3e8d436 commit f3107f0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 33 deletions.
34 changes: 18 additions & 16 deletions src/gui/qgscoordinatetransform.cpp
Expand Up @@ -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;
}

Expand All @@ -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());
Expand Down Expand Up @@ -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;
}

}

//
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsmaplayer.cpp
Expand Up @@ -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);
}
Expand All @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsprojectproperties.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgsmaplayerregistry.h"
#include "qgsproject.h"
#include "qgsrenderer.h"
#include "qgslogger.h"

//qt includes
#include <QColorDialog>
Expand Down Expand Up @@ -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);


Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgsvectorlayer.cpp
Expand Up @@ -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());
Expand Down
44 changes: 29 additions & 15 deletions src/raster/qgsrasterlayer.cpp
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit f3107f0

Please sign in to comment.