Skip to content
Permalink
Browse files

Fix matching of CRS by WKT to user CRSes defined by WKT, including

parameter-order independant matches

(cherry picked from commit 0a9cb0e)
  • Loading branch information
nyalldawson committed Dec 17, 2019
1 parent 5f21f13 commit 35b2352ccf24ba55b4c7bd02c72e1b5413b7ef1d
Showing with 22 additions and 2 deletions.
  1. +12 −1 src/core/qgscoordinatereferencesystem.cpp
  2. +10 −1 tests/src/core/testqgscoordinatereferencesystem.cpp
@@ -736,7 +736,7 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
}

// try to match against user crs
QgsCoordinateReferenceSystem::RecordMap record = getRecord( "select * from tbl_srs where parameters=" + QgsSqliteUtils::quotedString( wkt ) + " order by deprecated" );
QgsCoordinateReferenceSystem::RecordMap record = getRecord( "select * from tbl_srs where wkt=" + QgsSqliteUtils::quotedString( wkt ) + " order by deprecated" );
if ( !record.empty() )
{
long srsId = record[QStringLiteral( "srs_id" )].toLong();
@@ -748,6 +748,17 @@ bool QgsCoordinateReferenceSystem::createFromWkt( const QString &wkt )
else
{
setWktString( wkt );
if ( d->mSrsId == 0 )
{
#if PROJ_VERSION_MAJOR>=6
// lastly, try a tolerant match of the created proj object against all user CRSes (allowing differences in parameter order during the comparison)
long id = matchToUserCrs();
if ( id >= USER_CRS_START_ID )
{
createFromSrsId( id );
}
#endif
}
}

locker.changeMode( QgsReadWriteLocker::Write );
@@ -413,7 +413,7 @@ void TestQgsCoordinateReferenceSystem::createFromWktWithIdentify()
crs.createFromWkt( QStringLiteral( "BOUNDCRS[SOURCECRS[PROJCRS[\"unnamed\",BASEGEOGCRS[\"unnamed\",DATUM[\"Geocentric Datum of Australia 2020\",ELLIPSOID[\"GRS 80\",6378137,298.257222101,LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433,ID[\"EPSG\",9122]]]],CONVERSION[\"UTM zone 55S\",METHOD[\"Transverse Mercator\",ID[\"EPSG\",9807]],PARAMETER[\"Latitude of natural origin\",0,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8801]],PARAMETER[\"Longitude of natural origin\",147,ANGLEUNIT[\"degree\",0.0174532925199433],ID[\"EPSG\",8802]],PARAMETER[\"Scale factor at natural origin\",0.9996,SCALEUNIT[\"unity\",1],ID[\"EPSG\",8805]],PARAMETER[\"False easting\",500000,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8806]],PARAMETER[\"False northing\",10000000,LENGTHUNIT[\"metre\",1],ID[\"EPSG\",8807]],ID[\"EPSG\",17055]],CS[Cartesian,2],AXIS[\"easting\",east,ORDER[1],LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]],AXIS[\"northing\",north,ORDER[2],LENGTHUNIT[\"metre\",1,ID[\"EPSG\",9001]]]]],TARGETCRS[GEOGCRS[\"WGS 84\",DATUM[\"World Geodetic System 1984\",ELLIPSOID[\"WGS 84\",6378137,298.257223563,LENGTHUNIT[\"metre\",1]]],PRIMEM[\"Greenwich\",0,ANGLEUNIT[\"degree\",0.0174532925199433]],CS[ellipsoidal,2],AXIS[\"geodetic latitude (Lat)\",north,ORDER[1],ANGLEUNIT[\"degree\",0.0174532925199433]],AXIS[\"geodetic longitude (Lon)\",east,ORDER[2],ANGLEUNIT[\"degree\",0.0174532925199433]],USAGE[SCOPE[\"unknown\"],AREA[\"World\"],BBOX[-90,-180,90,180]],ID[\"EPSG\",4326]]],ABRIDGEDTRANSFORMATION[\"Transformation to WGS84\",METHOD[\"Position Vector transformation (geog2D domain)\",ID[\"EPSG\",9606]],PARAMETER[\"X-axis translation\",-0.06155,ID[\"EPSG\",8605]],PARAMETER[\"Y-axis translation\",0.01087,ID[\"EPSG\",8606]],PARAMETER[\"Z-axis translation\",0.04019,ID[\"EPSG\",8607]],PARAMETER[\"X-axis rotation\",-0.0394924,ID[\"EPSG\",8608]],PARAMETER[\"Y-axis rotation\",-0.0327221,ID[\"EPSG\",8609]],PARAMETER[\"Z-axis rotation\",-0.0328979,ID[\"EPSG\",8610]],PARAMETER[\"Scale difference\",1.000000009994,ID[\"EPSG\",8611]]]]" ) );
QVERIFY( crs.isValid() );
// this must be a user CRS -- it's a boundcrs of EPSG:7855, not EPSG:7855 itself
QCOMPARE( crs.authid(), QStringLiteral( "USER:100011" ) );
QCOMPARE( crs.authid(), QStringLiteral( "USER:100006" ) );
QCOMPARE( crs.ellipsoidAcronym(), QStringLiteral( "PARAMETER:6378137:6356752.31414035614579916" ) );

// here's the correct (desirable) WKT we should get from GDAL
@@ -497,6 +497,15 @@ void TestQgsCoordinateReferenceSystem::createFromWktUnknown()
QVERIFY( crs5.isValid() );
QCOMPARE( crs5.toWkt(), expectedWkt );
QCOMPARE( crs5.mapUnits(), QgsUnitTypes::DistanceMeters );
QCOMPARE( crs5.authid(), QStringLiteral( "USER:100001" ) );

// try creating with a different parameter order, should still be matched to existing user crs
QgsCoordinateReferenceSystem crs6;
crs6.createFromWkt( QStringLiteral( R"""(PROJCS["Belge 1972 / Belgian Lambert 72",GEOGCS["Belge 1972",DATUM["Reseau_National_Belge_1972",AUTHORITY["EPSG","6313"],SPHEROID["International 1924",6378388,297]],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]])""" ) );
QVERIFY( crs6.isValid() );
QCOMPARE( crs6.toWkt(), expectedWkt );
QCOMPARE( crs6.mapUnits(), QgsUnitTypes::DistanceMeters );
QCOMPARE( crs6.authid(), QStringLiteral( "USER:100001" ) );
}

void TestQgsCoordinateReferenceSystem::fromWkt()

0 comments on commit 35b2352

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