Skip to content
Permalink
Browse files

Don't flag CRSes created from a WKT which doesn't correspond to any

known authorities as invalid

If proj is happy to accept the WKT string, then it's valid

(cherry picked from commit 3d4b5fb)
  • Loading branch information
nyalldawson committed Dec 11, 2019
1 parent fda35a1 commit 54df3bb9cd7b6bec2f16a567473f271c13abca61
Showing with 24 additions and 5 deletions.
  1. +6 −4 src/core/qgscoordinatereferencesystem.cpp
  2. +18 −1 tests/src/core/testqgscoordinatereferencesystem.cpp
@@ -801,6 +801,11 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
return true;
}
}
else
{
// Still a valid CRS, just not a known one
d->mIsValid = true;
}
}
#else
if ( OSRAutoIdentifyEPSG( d->mCRS ) == OGRERR_NONE )
@@ -843,12 +848,9 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
}
#endif

//TODO: createFromProj4 used to save to the user database any new CRS
// this behavior was changed in order to separate creation and saving.
// Not sure if it necessary to save it here, should be checked by someone
// familiar with the code (should also give a more descriptive name to the generated CRS)
if ( d->mSrsId == 0 )
{
// TODO -- we should allow WKT based storage of custom CRS
QString myName = QStringLiteral( " * %1 (%2)" )
.arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ),
toProj4() );
@@ -42,6 +42,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void idCtor();
void copyCtor();
void assignmentCtor();
void saveAsUserCrs();
void createFromId();
void fromEpsgId();
void createFromOgcWmsCrs();
@@ -51,6 +52,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void sridCache();
void createFromWkt();
void createFromWktWithIdentify();
void createFromWktUnknown();
void fromWkt();
void wktCache();
void createFromESRIWkt();
@@ -82,7 +84,6 @@ class TestQgsCoordinateReferenceSystem: public QObject
void validSrsIds();
void asVariant();
void bounds();
void saveAsUserCrs();
void projectWithCustomCrs();
void projectEPSG25833();
void geoCcsDescription();
@@ -355,6 +356,22 @@ void TestQgsCoordinateReferenceSystem::createFromWktWithIdentify()
#endif
}

void TestQgsCoordinateReferenceSystem::createFromWktUnknown()
{
QgsCoordinateReferenceSystem crs;
// try creating a crs from a non-standard WKT string (in this case, the invalid WKT definition of EPSG:31370 used by
// some ArcGIS versions: see https://github.com/OSGeo/PROJ/issues/1781
const QString wkt = QStringLiteral( R"""(PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["Reseau_National_Belge_1972",SPHEROID["International 1924",6378388,297],AUTHORITY["EPSG","6313"]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["latitude_of_origin",90],PARAMETER["central_meridian",4.36748666666667],PARAMETER["standard_parallel_1",49.8333339],PARAMETER["standard_parallel_2",51.1666672333333],PARAMETER["false_easting",150000.01256],PARAMETER["false_northing",5400088.4378],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH]])""" );
crs.createFromWkt( wkt );
QVERIFY( crs.isValid() );
QgsDebugMsg( crs.toWkt() );
#if PROJ_VERSION_MAJOR>=6
// When used with proj < 6, a lossy conversion to proj string is used
QCOMPARE( crs.toWkt(), wkt );
#endif
QVERIFY( crs.authid().startsWith( QStringLiteral( "USER" ) ) || crs.authid().isEmpty() );
}

void TestQgsCoordinateReferenceSystem::fromWkt()
{
QgsCoordinateReferenceSystem myCrs = QgsCoordinateReferenceSystem::fromWkt( GEOWKT );

0 comments on commit 54df3bb

Please sign in to comment.
You can’t perform that action at this time.