Skip to content

Commit

Permalink
When creating a CRS from WKT and the WKT has an embedded CRS name, co…
Browse files Browse the repository at this point in the history
…rrectly use this to set the QgsCoordinateReferenceSystem description
  • Loading branch information
nyalldawson committed Oct 13, 2020
1 parent 8298d68 commit 9a35b27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -692,7 +692,12 @@ bool QgsCoordinateReferenceSystem::loadFromDatabase( const QString &db, const QS
if ( !d->mIsValid )
{
if ( !wkt.isEmpty() )
{
setWktString( wkt, false );
// set WKT string resets the description to that description embedded in the WKT, so manually overwrite this back to the
// value from the user DB
d->mDescription = statement.columnAsText( 1 );
}
else
setProjString( d->mProj4 );
}
Expand Down Expand Up @@ -1656,6 +1661,7 @@ bool QgsCoordinateReferenceSystem::setWktString( const QString &wkt, bool allowP
{
// Still a valid CRS, just not a known one
d->mIsValid = true;
d->mDescription = QString( proj_get_name( d->threadLocalProjObject() ) );
}
setMapUnits();
}
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -522,6 +522,13 @@ void TestQgsCoordinateReferenceSystem::fromWkt()
QCOMPARE( myCrs.srsid(), GEOCRS_ID );
myCrs = QgsCoordinateReferenceSystem::fromWkt( QStringLiteral( "not wkt" ) );
QVERIFY( !myCrs.isValid() );

#if PROJ_VERSION_MAJOR>=6
// wkt with embedded name
myCrs = QgsCoordinateReferenceSystem::fromWkt( R"""(PROJCRS["some locally made crs",BASEGEOGCRS["unknown",DATUM["Unknown based on WGS84 ellipsoid",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1],ID["EPSG",7030]]],PRIMEM["Greenwich",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8901]]],CONVERSION["unknown",METHOD["Hotine Oblique Mercator (variant B)",ID["EPSG",9815]],PARAMETER["Latitude of projection centre",47.2,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8811]],PARAMETER["Longitude of projection centre",9,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8812]],PARAMETER["Azimuth of initial line",39.4,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8813]],PARAMETER["Angle from Rectified to Skew Grid",0,ANGLEUNIT["degree",0.0174532925199433],ID["EPSG",8814]],PARAMETER["Scale factor on initial line",1,SCALEUNIT["unity",1],ID["EPSG",8815]],PARAMETER["Easting at projection centre",750,LENGTHUNIT["metre",1],ID["EPSG",8816]],PARAMETER["Northing at projection centre",250,LENGTHUNIT["metre",1],ID["EPSG",8817]]],CS[Cartesian,2],AXIS["(E)",east,ORDER[1],LENGTHUNIT["metre",1,ID["EPSG",9001]]],AXIS["(N)",north,ORDER[2],LENGTHUNIT["metre",1,ID["EPSG",9001]]]]])""" );
QVERIFY( myCrs.isValid() );
QCOMPARE( myCrs.description(), QStringLiteral( "some locally made crs" ) );
#endif
}

void TestQgsCoordinateReferenceSystem::wktCache()
Expand Down

0 comments on commit 9a35b27

Please sign in to comment.