Skip to content

Commit

Permalink
Fixed SRS validation. The settings in options on how to get projectio…
Browse files Browse the repository at this point in the history
…ns for layers without info in the file, is now functioning.

Added a debugPrint() function to QgsSpatialRefSys, and some more debug ouputs.
Removed som dead code(?)


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6430 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
homann committed Jan 13, 2007
1 parent d30f4dc commit 0e30d3f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -259,7 +259,9 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
mySelector->setSelectedSRSID(myDefaultSRS);
if(mySelector->exec())
{
QgsDebugMsg("Layer srs set from dialog: " + QString::number(mySelector->getCurrentSRSID()));
srs->createFromSrsId(mySelector->getCurrentSRSID());
srs->debugPrint();
}
else
{
Expand All @@ -271,13 +273,17 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
{
// XXX TODO: Change project to store selected CS as 'projectSRS' not 'selectedWKT'
proj4String = QgsProject::instance()->readEntry("SpatialRefSys","//ProjectSRSProj4String",GEOPROJ4);
QgsDebugMsg("Layer srs set from project: " + proj4String);
srs->createFromProj4(proj4String);
srs->debugPrint();
}
else ///Projections/defaultBehaviour==useGlobal
{
// XXX TODO: Change global settings to store default CS as 'defaultSRS' not 'defaultProjectionWKT'
int srs_id = mySettings.readNumEntry("/Projections/defaultProjectionSRSID",GEOSRS_ID);
srs->createFromSrsId(srs_id);
QgsDebugMsg("Layer srs set from global: " + proj4String);
srs->createFromSrsId(srs_id);
srs->debugPrint();
}

}
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -44,7 +44,7 @@ QgsMapLayer::QgsMapLayer(int type,
{
QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname);

mSRS = new QgsSpatialRefSys(GEOSRS_ID, QgsSpatialRefSys::QGIS_SRSID); // WGS 84
mSRS = new QgsSpatialRefSys();

// Set the display name = internal name
mLayerName = capitaliseLayerName(lyrname);
Expand Down Expand Up @@ -151,6 +151,11 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
QDomElement mne = mnl.toElement();
mDataSource = mne.text();

// Set a SRS (any will do) so that we don't ask the user.
// We will overwrite whatever GDAL etc picks up anway
// further down this function.
mSRS->createFromSrsId(GEOSRS_ID);

// now let the children grab what they need from the DOM node.
if (!readXML_( layer_node ))
{
Expand Down
18 changes: 16 additions & 2 deletions src/core/qgsspatialrefsys.cpp
Expand Up @@ -128,7 +128,7 @@ void QgsSpatialRefSys::validate()
//if not we will prompt the user for and srs
//then retest using gdal
//if the retest fails we will then set this srs to the GEOCS/WGS84 default

QgsDebugMsg("Use GDAL to vaildate");

/* Here are the possible OGR error codes :
typedef int OGRErr;
Expand Down Expand Up @@ -243,6 +243,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
{
if (theWkt.isEmpty())
{
QgsDebugMsg("QgsSpatialRefSys::createFromWkt -- theWkt is uninitialised, operation failed")
QgsLogger::critical("QgsSpatialRefSys::createFromWkt -- theWkt is uninitialised, operation failed");
mIsValidFlag = false;
return false;
Expand Down Expand Up @@ -442,11 +443,13 @@ bool QgsSpatialRefSys::isValid() const
OGRErr myResult = myOgrSpatialRef.importFromProj4( mySourceCharArrayPointer );
if (myResult==OGRERR_NONE)
{
QgsDebugMsg("The OGRe says it's a valid SRS with proj4 string: " + mProj4String);
//srs is valid so nothing more to do...
return true;
}
else
{
QgsDebugMsg("The OGRe says it's an invalid SRS with proj4 string: " + mProj4String);
return false;
}
}
Expand Down Expand Up @@ -510,7 +513,9 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
{
myRecord = getRecord("select * from tbl_srs where description='" + mDescription.stripWhiteSpace () + "'");
}
if (!myRecord.empty())
// if (!myRecord.empty())
// What if descriptions aren't unique?
if (NULL)
{
mySrsId=myRecord["srs_id"].toLong();
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 Projection Description match search for srsid returned srsid: "\
Expand Down Expand Up @@ -1267,3 +1272,12 @@ void QgsSpatialRefSys::setCustomSrsValidation(CUSTOM_SRS_VALIDATION f)
{
mCustomSrsValidation = f;
}

void QgsSpatialRefSys::debugPrint()
{
QgsDebugMsg("***SpatialRefSystem***");
QgsDebugMsg("* Valid : " + (mIsValidFlag?QString("true"):QString("false")));
QgsDebugMsg("* SrsId : " + QString::number(mSrsId));
QgsDebugMsg("* Proj4 : " + mProj4String);
QgsDebugMsg("* Desc. : " + mDescription);
}
4 changes: 4 additions & 0 deletions src/core/qgsspatialrefsys.h
Expand Up @@ -310,6 +310,10 @@ class CORE_EXPORT QgsSpatialRefSys
* @param QString the acronym (must be a valid proj4 ellipsoid acronym)
*/
void setEllipsoidAcronym(QString theEllipsoidAcronym);

/*! Print the description if debugging
*/
void debugPrint();
private:
// Open SQLite db and show message if ccannot be opened
// returns the same code as sqlite3_open
Expand Down
20 changes: 14 additions & 6 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -519,6 +519,9 @@ QgsRasterLayer::readFile( QString const & fileName )
// QgsCoordinateTransform for this layer
// NOTE: we must do this before getMetadata is called

QgsDebugMsg("Raster initial SRS");
mSRS->debugPrint();

QString mySourceWKT = getProjectionWKT();

QgsDebugMsg("--------------------------------------------------------------------------------------");
Expand All @@ -532,6 +535,8 @@ QgsRasterLayer::readFile( QString const & fileName )
{
mSRS->validate();
}
QgsDebugMsg("Raster determined to have the following SRS");
mSRS->debugPrint();

//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
Expand Down Expand Up @@ -662,12 +667,15 @@ QString QgsRasterLayer::getProjectionWKT()
//try to get the gcp srs from the raster layer if available
myWKTString=QString(gdalDataset->GetGCPProjection());

mySRS.createFromWkt(myWKTString);
if (!mySRS.isValid())
{
// use force and make SRS valid!
mySRS.validate();
}
// What is the purpose of this piece of code?
// Sideeffects from validate()?
// mySRS.createFromWkt(myWKTString);
// if (!mySRS.isValid())
// {
// // use force and make SRS valid!
// mySRS.validate();
// }

}

return myWKTString;
Expand Down

0 comments on commit 0e30d3f

Please sign in to comment.