@@ -302,7 +302,18 @@ bool QgsCoordinateReferenceSystem::createFromWkt( QString theWkt )
302302 // now that we have the proj4string, delegate to createFromProj4 so
303303 // that we can try to fill in the remaining class members...
304304 // 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+
306317 CPLFree ( proj4src );
307318
308319 return mIsValidFlag ;
@@ -324,42 +335,36 @@ bool QgsCoordinateReferenceSystem::createFromProj4( const QString theProj4String
324335 // +proj=lcc +lat_1=46.8 +lat_0=46.8 +lon_0=2.337229166666664 +k_0=0.99987742
325336 // +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356515.000000472 +units=m +no_defs
326337 //
338+ QgsDebugMsg ( " proj4: " + theProj4String );
327339 mIsValidFlag = false ;
328340
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 );
333343 if ( myStart == -1 )
334344 {
335- QgsDebugMsg ( " error proj string supplied has no +proj argument" );
345+ QgsDebugMsg ( " proj string supplied has no +proj argument" );
336346 return mIsValidFlag ;
337347 }
338- else
339- {
340- myLength = myProjRegExp.matchedLength ();
341- }
342348
343- mProjectionAcronym = theProj4String. mid ( myStart + PROJ_PREFIX_LEN, myLength - PROJ_PREFIX_LEN );
349+ mProjectionAcronym = myProjRegExp. cap ( 1 );
344350
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 )
350354 {
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 );
353361 }
354362
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 )
360366 {
361- QgsDebugMsg ( " proj string supplied has no +ellps or +a argument" );
362- return mIsValidFlag ;
367+ QgsDebugMsg ( " proj string supplied has no +a argument" );
363368 }
364369
365370 /*
0 commit comments