Skip to content

Commit d3b240e

Browse files
author
homann
committedJan 13, 2007
Fixed SRS validation. The settings in options on how to get projections 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@6430 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 13ff2d0 commit d3b240e

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed
 

‎src/app/qgisapp.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
259259
mySelector->setSelectedSRSID(myDefaultSRS);
260260
if(mySelector->exec())
261261
{
262+
QgsDebugMsg("Layer srs set from dialog: " + QString::number(mySelector->getCurrentSRSID()));
262263
srs->createFromSrsId(mySelector->getCurrentSRSID());
264+
srs->debugPrint();
263265
}
264266
else
265267
{
@@ -271,13 +273,17 @@ static void customSrsValidation_(QgsSpatialRefSys* srs)
271273
{
272274
// XXX TODO: Change project to store selected CS as 'projectSRS' not 'selectedWKT'
273275
proj4String = QgsProject::instance()->readEntry("SpatialRefSys","//ProjectSRSProj4String",GEOPROJ4);
276+
QgsDebugMsg("Layer srs set from project: " + proj4String);
274277
srs->createFromProj4(proj4String);
278+
srs->debugPrint();
275279
}
276280
else ///Projections/defaultBehaviour==useGlobal
277281
{
278282
// XXX TODO: Change global settings to store default CS as 'defaultSRS' not 'defaultProjectionWKT'
279283
int srs_id = mySettings.readNumEntry("/Projections/defaultProjectionSRSID",GEOSRS_ID);
280-
srs->createFromSrsId(srs_id);
284+
QgsDebugMsg("Layer srs set from global: " + proj4String);
285+
srs->createFromSrsId(srs_id);
286+
srs->debugPrint();
281287
}
282288

283289
}

‎src/core/qgsmaplayer.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ QgsMapLayer::QgsMapLayer(int type,
4444
{
4545
QgsDebugMsg("QgsMapLayer::QgsMapLayer - lyrname is '" + lyrname);
4646

47-
mSRS = new QgsSpatialRefSys(GEOSRS_ID, QgsSpatialRefSys::QGIS_SRSID); // WGS 84
47+
mSRS = new QgsSpatialRefSys();
4848

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

154+
// Set a SRS (any will do) so that we don't ask the user.
155+
// We will overwrite whatever GDAL etc picks up anway
156+
// further down this function.
157+
mSRS->createFromSrsId(GEOSRS_ID);
158+
154159
// now let the children grab what they need from the DOM node.
155160
if (!readXML_( layer_node ))
156161
{

‎src/core/qgsspatialrefsys.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void QgsSpatialRefSys::validate()
128128
//if not we will prompt the user for and srs
129129
//then retest using gdal
130130
//if the retest fails we will then set this srs to the GEOCS/WGS84 default
131-
131+
QgsDebugMsg("Use GDAL to vaildate");
132132

133133
/* Here are the possible OGR error codes :
134134
typedef int OGRErr;
@@ -243,6 +243,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
243243
{
244244
if (theWkt.isEmpty())
245245
{
246+
QgsDebugMsg("QgsSpatialRefSys::createFromWkt -- theWkt is uninitialised, operation failed")
246247
QgsLogger::critical("QgsSpatialRefSys::createFromWkt -- theWkt is uninitialised, operation failed");
247248
mIsValidFlag = false;
248249
return false;
@@ -442,11 +443,13 @@ bool QgsSpatialRefSys::isValid() const
442443
OGRErr myResult = myOgrSpatialRef.importFromProj4( mySourceCharArrayPointer );
443444
if (myResult==OGRERR_NONE)
444445
{
446+
QgsDebugMsg("The OGRe says it's a valid SRS with proj4 string: " + mProj4String);
445447
//srs is valid so nothing more to do...
446448
return true;
447449
}
448450
else
449451
{
452+
QgsDebugMsg("The OGRe says it's an invalid SRS with proj4 string: " + mProj4String);
450453
return false;
451454
}
452455
}
@@ -510,7 +513,9 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
510513
{
511514
myRecord = getRecord("select * from tbl_srs where description='" + mDescription.stripWhiteSpace () + "'");
512515
}
513-
if (!myRecord.empty())
516+
// if (!myRecord.empty())
517+
// What if descriptions aren't unique?
518+
if (NULL)
514519
{
515520
mySrsId=myRecord["srs_id"].toLong();
516521
QgsDebugMsg("QgsSpatialRefSys::createFromProj4 Projection Description match search for srsid returned srsid: "\
@@ -1267,3 +1272,12 @@ void QgsSpatialRefSys::setCustomSrsValidation(CUSTOM_SRS_VALIDATION f)
12671272
{
12681273
mCustomSrsValidation = f;
12691274
}
1275+
1276+
void QgsSpatialRefSys::debugPrint()
1277+
{
1278+
QgsDebugMsg("***SpatialRefSystem***");
1279+
QgsDebugMsg("* Valid : " + (mIsValidFlag?QString("true"):QString("false")));
1280+
QgsDebugMsg("* SrsId : " + QString::number(mSrsId));
1281+
QgsDebugMsg("* Proj4 : " + mProj4String);
1282+
QgsDebugMsg("* Desc. : " + mDescription);
1283+
}

‎src/core/qgsspatialrefsys.h

+4
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ class CORE_EXPORT QgsSpatialRefSys
310310
* @param QString the acronym (must be a valid proj4 ellipsoid acronym)
311311
*/
312312
void setEllipsoidAcronym(QString theEllipsoidAcronym);
313+
314+
/*! Print the description if debugging
315+
*/
316+
void debugPrint();
313317
private:
314318
// Open SQLite db and show message if ccannot be opened
315319
// returns the same code as sqlite3_open

‎src/core/raster/qgsrasterlayer.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ QgsRasterLayer::readFile( QString const & fileName )
519519
// QgsCoordinateTransform for this layer
520520
// NOTE: we must do this before getMetadata is called
521521

522+
QgsDebugMsg("Raster initial SRS");
523+
mSRS->debugPrint();
524+
522525
QString mySourceWKT = getProjectionWKT();
523526

524527
QgsDebugMsg("--------------------------------------------------------------------------------------");
@@ -532,6 +535,8 @@ QgsRasterLayer::readFile( QString const & fileName )
532535
{
533536
mSRS->validate();
534537
}
538+
QgsDebugMsg("Raster determined to have the following SRS");
539+
mSRS->debugPrint();
535540

536541
//set up the coordinat transform - in the case of raster this is mainly used to convert
537542
//the inverese projection of the map extents of the canvas when zzooming in etc. so
@@ -662,12 +667,15 @@ QString QgsRasterLayer::getProjectionWKT()
662667
//try to get the gcp srs from the raster layer if available
663668
myWKTString=QString(gdalDataset->GetGCPProjection());
664669

665-
mySRS.createFromWkt(myWKTString);
666-
if (!mySRS.isValid())
667-
{
668-
// use force and make SRS valid!
669-
mySRS.validate();
670-
}
670+
// What is the purpose of this piece of code?
671+
// Sideeffects from validate()?
672+
// mySRS.createFromWkt(myWKTString);
673+
// if (!mySRS.isValid())
674+
// {
675+
// // use force and make SRS valid!
676+
// mySRS.validate();
677+
// }
678+
671679
}
672680

673681
return myWKTString;

0 commit comments

Comments
 (0)
Please sign in to comment.