24
24
#include < QDomElement>
25
25
#include < QFileInfo>
26
26
#include < QRegExp>
27
+ #include < QTextStream>
27
28
28
29
#include " qgsapplication.h"
29
30
#include " qgslogger.h"
@@ -226,12 +227,8 @@ bool QgsSpatialRefSys::loadFromDb(QString db, QString field, long id)
226
227
mEpsg = QString::fromUtf8 ((char *)sqlite3_column_text (myPreparedStatement,6 )).toLong ();
227
228
int geo = QString::fromUtf8 ((char *)sqlite3_column_text (myPreparedStatement,7 )).toInt ();
228
229
mGeoFlag = (geo == 0 ? false : true );
230
+ setProj4String ( proj4String );
229
231
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);
235
232
}
236
233
else
237
234
{
@@ -278,7 +275,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
278
275
279
276
// now that we have the proj4string, delegate to createFromProj4String so
280
277
// 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
282
279
createFromProj4 (QString (proj4src));
283
280
CPLFree (proj4src);
284
281
@@ -288,11 +285,7 @@ bool QgsSpatialRefSys::createFromWkt(QString theWkt)
288
285
289
286
bool QgsSpatialRefSys::isValid () const
290
287
{
291
- if (mIsValidFlag )
292
- {
293
- return true ;
294
- }
295
- return false ;
288
+ return mIsValidFlag ;
296
289
}
297
290
298
291
bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
@@ -410,10 +403,7 @@ bool QgsSpatialRefSys::createFromProj4 (const QString theProj4String)
410
403
if (!myRecord.empty ())
411
404
{
412
405
// 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 );
417
407
mySrsId=myRecord[" srs_id" ].toLong ();
418
408
QgsDebugMsg (" QgsSpatialRefSys::createFromProj4 proj4string match search for srsid returned srsid: " + QString::number (mySrsId));
419
409
if (mySrsId > 0 )
@@ -664,8 +654,12 @@ void QgsSpatialRefSys::setDescription (QString theDescription)
664
654
void QgsSpatialRefSys::setProj4String (QString theProj4String)
665
655
{
666
656
const char *oldlocale = setlocale (LC_NUMERIC, NULL );
657
+
667
658
setlocale (LC_NUMERIC, " C" );
659
+ OSRDestroySpatialReference ( mSRS );
660
+ mSRS = OSRNewSpatialReference (NULL );
668
661
mIsValidFlag = OSRImportFromProj4 (mSRS , theProj4String.toLatin1 ().constData () )==OGRERR_NONE;
662
+
669
663
setlocale (LC_NUMERIC, oldlocale);
670
664
}
671
665
void QgsSpatialRefSys::setGeographicFlag (bool theGeoFlag)
@@ -691,7 +685,6 @@ void QgsSpatialRefSys::setMapUnits()
691
685
{
692
686
if (!mIsValidFlag )
693
687
{
694
- QgsLogger::warning (" No valid projection. Unable to set map units." );
695
688
mMapUnits = QGis::UNKNOWN;
696
689
return ;
697
690
}
@@ -944,6 +937,7 @@ bool QgsSpatialRefSys::readXML( QDomNode & theNode )
944
937
{
945
938
setGeographicFlag (false );
946
939
}
940
+
947
941
// make sure the map units have been set
948
942
setMapUnits ();
949
943
0 commit comments