@@ -302,7 +302,18 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
302
302
// now that we have the proj4string, delegate to createFromProj4 so
303
303
// that we can try to fill in the remaining class members...
304
304
// create from Proj will set the isValidFlag
305
- createFromProj4 ( QString ( proj4src ) );
305
+ if ( !createFromProj4 ( proj4src ) )
306
+ {
307
+ CPLFree ( proj4src );
308
+
309
+ // try fixed up version
310
+ OSRFixup ( mCRS );
311
+
312
+ OSRExportToProj4 ( mCRS , &proj4src );
313
+
314
+ createFromProj4 ( proj4src );
315
+ }
316
+
306
317
CPLFree ( proj4src );
307
318
308
319
return mIsValidFlag ;
@@ -324,42 +335,36 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
324
335
// +proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=2.337229166666664 +k_0=0.99987742
325
336
// +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356515.000000472 +units=m +no_defs
326
337
//
338
+ QgsDebugMsg ( " proj4: " + theProj4String );
327
339
mIsValidFlag = false ;
328
340
329
- QRegExp myProjRegExp ( " \\ +proj=\\ S+" );
330
- int myStart = 0 ;
331
- int myLength = 0 ;
332
- myStart = myProjRegExp.indexIn ( theProj4String, myStart );
341
+ QRegExp myProjRegExp ( " \\ +proj=(\\ S+)" );
342
+ int myStart = myProjRegExp.indexIn ( theProj4String );
333
343
if ( myStart == -1 )
334
344
{
335
- QgsDebugMsg ( " error proj string supplied has no +proj argument" );
345
+ QgsDebugMsg ( " proj string supplied has no +proj argument" );
336
346
return mIsValidFlag ;
337
347
}
338
- else
339
- {
340
- myLength = myProjRegExp.matchedLength ();
341
- }
342
348
343
- mProjectionAcronym = theProj4String. mid ( myStart + PROJ_PREFIX_LEN, myLength - PROJ_PREFIX_LEN );
349
+ mProjectionAcronym = myProjRegExp. cap ( 1 );
344
350
345
- QRegExp myEllipseRegExp ( " \\ +ellps=\\ S+" );
346
- myStart = 0 ;
347
- myLength = 0 ;
348
- myStart = myEllipseRegExp.indexIn ( theProj4String, myStart );
349
- if ( myStart != -1 )
351
+ QRegExp myEllipseRegExp ( " \\ +ellps=(\\ S+)" );
352
+ myStart = myEllipseRegExp.indexIn ( theProj4String );
353
+ if ( myStart == -1 )
350
354
{
351
- myLength = myEllipseRegExp.matchedLength ();
352
- mEllipsoidAcronym = theProj4String.mid ( myStart + ELLPS_PREFIX_LEN, myLength - ELLPS_PREFIX_LEN );
355
+ QgsDebugMsg ( " proj string supplied has no +ellps argument" );
356
+ mEllipsoidAcronym = " " ;
357
+ }
358
+ else
359
+ {
360
+ mEllipsoidAcronym = myEllipseRegExp.cap ( 1 );
353
361
}
354
362
355
- QRegExp myAxisRegExp ( " \\ +a=\\ S+" );
356
- myStart = 0 ;
357
- myLength = 0 ;
358
- myStart = myAxisRegExp.indexIn ( theProj4String, myStart );
359
- if ( myStart == -1 && mEllipsoidAcronym .isNull () )
363
+ QRegExp myAxisRegExp ( " \\ +a=(\\ S+)" );
364
+ myStart = myAxisRegExp.indexIn ( theProj4String );
365
+ if ( myStart == -1 )
360
366
{
361
- QgsDebugMsg ( " proj string supplied has no +ellps or +a argument" );
362
- return mIsValidFlag ;
367
+ QgsDebugMsg ( " proj string supplied has no +a argument" );
363
368
}
364
369
365
370
/*
0 commit comments