mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
fix detection of 2.x project crs (followup f2b5a595)
This commit is contained in:
parent
cf35affedc
commit
8c96eec25e
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ class TestQgsCoordinateReferenceSystem: public QObject
|
||||
void bounds();
|
||||
void saveAsUserCrs();
|
||||
void projectWithCustomCrs();
|
||||
void projectEPSG25833();
|
||||
|
||||
private:
|
||||
void debugPrint( QgsCoordinateReferenceSystem &crs );
|
||||
@ -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
tests/testdata/projects/epsg25833.qgs
vendored
Normal file
43
tests/testdata/projects/epsg25833.qgs
vendored
Normal file
@ -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>
|
Loading…
x
Reference in New Issue
Block a user