Skip to content
Permalink
Browse files

Fixed SRS validation. The settings in options on how to get projectio…

…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
homann committed Jan 13, 2007
1 parent d30f4dc commit 0e30d3ff025b3c1d89308934d56f0e06f1d136ba
@@ -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
{
@@ -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();
}

}
@@ -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);
@@ -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 ))
{
@@ -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;
@@ -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;
@@ -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;
}
}
@@ -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: "\
@@ -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);
}
@@ -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
@@ -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("--------------------------------------------------------------------------------------");
@@ -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
@@ -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;

0 comments on commit 0e30d3f

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