Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix detection of 2.x project crs (followup f2b5a59)
  • Loading branch information
jef-n committed Jan 24, 2018
1 parent cf35aff commit 8c96eec
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/core/qgsproject.cpp
Expand Up @@ -905,21 +905,25 @@ bool QgsProject::readProjectFile( const QString &filename )

if ( !projectCrs.isValid() )
{
// else we try using the stored proj4 string - it's consistent across different QGIS installs,
// whereas the srsid can vary (e.g. for custom projections)
QString projCrsString = readEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSProj4String" ) );
if ( !projCrsString.isEmpty() )
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );

// try the CRS
if ( currentCRS >= 0 )
{
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}

// if that didn't produce a match, try the proj.4 string
if ( !projCrsString.isEmpty() && ( !projectCrs.isValid() || projectCrs.toProj4() != projCrsString ) )
{
projectCrs = QgsCoordinateReferenceSystem::fromProj4( projCrsString );
}
// last try using crs id - most fragile

// last just take the given id
if ( !projectCrs.isValid() )
{
long currentCRS = readNumEntry( QStringLiteral( "SpatialRefSys" ), QStringLiteral( "/ProjectCRSID" ), -1 );
if ( currentCRS != -1 && currentCRS < USER_CRS_START_ID )
{
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}
projectCrs = QgsCoordinateReferenceSystem::fromSrsId( currentCRS );
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/src/core/testqgscoordinatereferencesystem.cpp
Expand Up @@ -79,6 +79,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
void bounds();
void saveAsUserCrs();
void projectWithCustomCrs();
void projectEPSG25833();

private:
void debugPrint( QgsCoordinateReferenceSystem &crs );
Expand Down Expand Up @@ -882,5 +883,15 @@ void TestQgsCoordinateReferenceSystem::projectWithCustomCrs()
QCOMPARE( spyCrsChanged.count(), 1 );
}

void TestQgsCoordinateReferenceSystem::projectEPSG25833()
{
// tests loading a 2.x project with a predefined EPSG that has non unique proj.4 string
QgsProject p;
QSignalSpy spyCrsChanged( &p, &QgsProject::crsChanged );
QVERIFY( p.read( TEST_DATA_DIR + QStringLiteral( "/projects/epsg25833.qgs" ) ) );
QVERIFY( p.crs().isValid() );
QVERIFY( p.crs().authid() == QStringLiteral( "EPSG:25833" ) );
QCOMPARE( spyCrsChanged.count(), 1 );
}
QGSTEST_MAIN( TestQgsCoordinateReferenceSystem )
#include "testqgscoordinatereferencesystem.moc"
43 changes: 43 additions & 0 deletions tests/testdata/projects/epsg25833.qgs
@@ -0,0 +1,43 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="2.18.16">
<title></title>
<autotransaction active="0"/>
<evaluateDefaultValues active="0"/>
<layer-tree-group expanded="1" checked="Qt::PartiallyChecked" name="">
<customproperties/>
</layer-tree-group>
<relations/>
<mapcanvas>
<units>meters</units>
<extent>
<xmin>423939.41302644077222794</xmin>
<ymin>5645532.31057187728583813</ymin>
<xmax>426709.05210548255126923</xmax>
<ymax>5647280.68408176116645336</ymax>
</extent>
<rotation>0</rotation>
<projections>1</projections>
<destinationsrs>
<spatialrefsys>
<proj4>+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs</proj4>
<srsid>2106</srsid>
<srid>25833</srid>
<authid>EPSG:25833</authid>
<description>ETRS89 / UTM zone 33N</description>
<projectionacronym>utm</projectionacronym>
<ellipsoidacronym>GRS80</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</destinationsrs>
<rendermaptile>0</rendermaptile>
<layer_coordinate_transform_info/>
</mapcanvas>
<layer-tree-canvas>
<custom-order enabled="0"/>
</layer-tree-canvas>
<legend updateDrawingOrder="true">
</legend>
<projectlayers/>
<properties/>
<visibility-presets/>
</qgis>

0 comments on commit 8c96eec

Please sign in to comment.