Skip to content

Commit 8c96eec

Browse files
committedJan 24, 2018
fix detection of 2.x project crs (followup f2b5a59)
1 parent cf35aff commit 8c96eec

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed
 

‎src/core/qgsproject.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -905,21 +905,25 @@ bool QgsProject::readProjectFile( const QString &filename )
905905

906906
if ( !projectCrs.isValid() )
907907
{
908-
// else we try using the stored proj4 string - it's consistent across different QGIS installs,
909-
// whereas the srsid can vary (e.g. for custom projections)
910908
QString projCrsString = readEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSProj4String" ) );
911-
if ( !projCrsString.isEmpty() )
909+
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
910+
911+
// try the CRS
912+
if ( currentCRS >= 0 )
913+
{
914+
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
915+
}
916+
917+
// if that didn't produce a match, try the proj.4 string
918+
if ( !projCrsString.isEmpty() && ( !projectCrs.isValid() || projectCrs.toProj4() != projCrsString ) )
912919
{
913920
projectCrs = QgsCoordinateReferenceSystem::fromProj4( projCrsString );
914921
}
915-
// last try using crs id - most fragile
922+
923+
// last just take the given id
916924
if ( !projectCrs.isValid() )
917925
{
918-
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
919-
if ( currentCRS != -1 && currentCRS < USER_CRS_START_ID )
920-
{
921-
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
922-
}
926+
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
923927
}
924928
}
925929
}

‎tests/src/core/testqgscoordinatereferencesystem.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
7979
void bounds();
8080
void saveAsUserCrs();
8181
void projectWithCustomCrs();
82+
void projectEPSG25833();
8283

8384
private:
8485
void debugPrint( QgsCoordinateReferenceSystem &crs );
@@ -882,5 +883,15 @@ void TestQgsCoordinateReferenceSystem::projectWithCustomCrs()
882883
QCOMPARE( spyCrsChanged.count(), 1 );
883884
}
884885

886+
void TestQgsCoordinateReferenceSystem::projectEPSG25833()
887+
{
888+
// tests loading a 2.x project with a predefined EPSG that has non unique proj.4 string
889+
QgsProject p;
890+
QSignalSpy spyCrsChanged( &p, &QgsProject::crsChanged );
891+
QVERIFY( p.read( TEST_DATA_DIR + QStringLiteral( "/projects/epsg25833.qgs" ) ) );
892+
QVERIFY( p.crs().isValid() );
893+
QVERIFY( p.crs().authid() == QStringLiteral( "EPSG:25833" ) );
894+
QCOMPARE( spyCrsChanged.count(), 1 );
895+
}
885896
QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
886897
#include "testqgscoordinatereferencesystem.moc"

‎tests/testdata/projects/epsg25833.qgs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2+
<qgis projectname="" version="2.18.16">
3+
<title></title>
4+
<autotransaction active="0"/>
5+
<evaluateDefaultValues active="0"/>
6+
<layer-tree-group expanded="1" checked="Qt::PartiallyChecked" name="">
7+
<customproperties/>
8+
</layer-tree-group>
9+
<relations/>
10+
<mapcanvas>
11+
<units>meters</units>
12+
<extent>
13+
<xmin>423939.41302644077222794</xmin>
14+
<ymin>5645532.31057187728583813</ymin>
15+
<xmax>426709.05210548255126923</xmax>
16+
<ymax>5647280.68408176116645336</ymax>
17+
</extent>
18+
<rotation>0</rotation>
19+
<projections>1</projections>
20+
<destinationsrs>
21+
<spatialrefsys>
22+
<proj4>+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs</proj4>
23+
<srsid>2106</srsid>
24+
<srid>25833</srid>
25+
<authid>EPSG:25833</authid>
26+
<description>ETRS89 / UTM zone 33N</description>
27+
<projectionacronym>utm</projectionacronym>
28+
<ellipsoidacronym>GRS80</ellipsoidacronym>
29+
<geographicflag>false</geographicflag>
30+
</spatialrefsys>
31+
</destinationsrs>
32+
<rendermaptile>0</rendermaptile>
33+
<layer_coordinate_transform_info/>
34+
</mapcanvas>
35+
<layer-tree-canvas>
36+
<custom-order enabled="0"/>
37+
</layer-tree-canvas>
38+
<legend updateDrawingOrder="true">
39+
</legend>
40+
<projectlayers/>
41+
<properties/>
42+
<visibility-presets/>
43+
</qgis>

0 commit comments

Comments
 (0)
Please sign in to comment.