2424#include < QDomElement>
2525#include < QFileInfo>
2626#include < QRegExp>
27+ #include < QTextStream>
2728
2829#include " qgsapplication.h"
2930#include " qgslogger.h"
@@ -226,12 +227,8 @@ bool QgsSpatialRefSys::loadFromDb(QString db, QString field, long id)
226227 mEpsg = QString::fromUtf8 ((char *)sqlite3_column_text (myPreparedStatement,6 )).toLong ();
227228 int geo = QString::fromUtf8 ((char *)sqlite3_column_text (myPreparedStatement,7 )).toInt ();
228229 mGeoFlag = (geo == 0 ? false : true );
230+ setProj4String ( proj4String );
229231 setMapUnits ();
230- mIsValidFlag = true ;
231- const char *oldlocale = setlocale (LC_NUMERIC, NULL );
232- setlocale (LC_NUMERIC, " C" );
233- OSRImportFromProj4 ( mSRS , proj4String.toLatin1 ().constData () );
234- setlocale (LC_NUMERIC, oldlocale);
235232 }
236233 else
237234 {
@@ -278,7 +275,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
278275
279276 // now that we have the proj4string, delegate to createFromProj4String so
280277 // that we can try to fill in the remaining class members...
281- // create from Proj wil set the isValidFalg
278+ // create from Proj will set the isValidFlag
282279 createFromProj4 (QString (proj4src));
283280 CPLFree (proj4src);
284281
@@ -288,11 +285,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
288285
289286bool QgsSpatialRefSys::isValid () const
290287{
291- if (mIsValidFlag )
292- {
293- return true ;
294- }
295- return false ;
288+ return mIsValidFlag ;
296289}
297290
298291bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
@@ -410,10 +403,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
410403 if (!myRecord.empty ())
411404 {
412405 // Success! We have found the proj string by swapping the lat_1 and lat_2
413- const char *oldlocale = setlocale (LC_NUMERIC, NULL );
414- setlocale (LC_NUMERIC, " C" );
415- OSRImportFromProj4 (mSRS , theProj4StringModified.toLatin1 ().constData () );
416- setlocale (LC_NUMERIC, oldlocale);
406+ setProj4String ( theProj4StringModified );
417407 mySrsId=myRecord[" srs_id" ].toLong ();
418408 QgsDebugMsg (" QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " + QString::number (mySrsId));
419409 if (mySrsId > 0 )
@@ -664,8 +654,12 @@ void QgsSpatialRefSys::setDescription (QString theDescription)
664654void QgsSpatialRefSys::setProj4String (QString theProj4String)
665655{
666656 const char *oldlocale = setlocale (LC_NUMERIC, NULL );
657+
667658 setlocale (LC_NUMERIC, " C" );
659+ OSRDestroySpatialReference ( mSRS );
660+ mSRS = OSRNewSpatialReference (NULL );
668661 mIsValidFlag = OSRImportFromProj4 (mSRS , theProj4String.toLatin1 ().constData () )==OGRERR_NONE;
662+
669663 setlocale (LC_NUMERIC, oldlocale);
670664}
671665void QgsSpatialRefSys::setGeographicFlag (bool theGeoFlag)
@@ -691,7 +685,6 @@ void QgsSpatialRefSys::setMapUnits()
691685{
692686 if (!mIsValidFlag )
693687 {
694- QgsLogger::warning (" No valid projection. Unable to set map units." );
695688 mMapUnits = QGis::UNKNOWN;
696689 return ;
697690 }
@@ -944,6 +937,7 @@ bool QgsSpatialRefSys::readXML( QDomNode & theNode )
944937 {
945938 setGeographicFlag (false );
946939 }
940+
947941 // make sure the map units have been set
948942 setMapUnits ();
949943
0 commit comments