Skip to content

Commit bf45d0b

Browse files
Gustrytimlinux
authored andcommittedDec 20, 2017
Crs (#5908)
* fix display of CRS if invalid CRS * fix #17455 set an empty CRS if the read CRS from XML is wrong * add warning about empty CRS node when reading XML
1 parent 9a5435f commit bf45d0b

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed
 

‎python/core/qgscoordinatereferencesystem.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ Returns opposite bool value to operator ==
515515
bool readXml( const QDomNode &node );
516516
%Docstring
517517
Restores state from the given DOM node.
518+
If it fails or if the node is empty, a default not empty CRS will be returned.
518519

519520
:param node: The node from which state will be restored
520521

‎src/core/metadata/qgslayermetadata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ bool QgsLayerMetadata::readMetadataXml( const QDomElement &metadataElement )
366366

367367
// crs
368368
mnl = metadataElement.namedItem( QStringLiteral( "crs" ) );
369-
mCrs.readXml( mnl );
369+
if ( !mCrs.readXml( mnl ) )
370+
mCrs = QgsCoordinateReferenceSystem();
370371

371372
// extent
372373
mnl = metadataElement.namedItem( QStringLiteral( "extent" ) );

‎src/core/qgscoordinatereferencesystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem
466466

467467
/**
468468
* Restores state from the given DOM node.
469+
* If it fails or if the node is empty, a default not empty CRS will be returned.
469470
* \param node The node from which state will be restored
470471
* \returns bool True on success, False on failure
471472
*/

‎src/core/qgsvectorlayer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4032,12 +4032,16 @@ QString QgsVectorLayer::htmlMetadata() const
40324032
}
40334033

40344034
// EPSG
4035-
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" ) + crs().authid() + QStringLiteral( " - " );
4036-
myMetadata += crs().description() + QStringLiteral( " - " );
4037-
if ( crs().isGeographic() )
4038-
myMetadata += tr( "Geographic" );
4039-
else
4040-
myMetadata += tr( "Projected" );
4035+
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
4036+
if ( crs().isValid() )
4037+
{
4038+
myMetadata += crs().authid() + QStringLiteral( " - " );
4039+
myMetadata += crs().description() + QStringLiteral( " - " );
4040+
if ( crs().isGeographic() )
4041+
myMetadata += tr( "Geographic" );
4042+
else
4043+
myMetadata += tr( "Projected" );
4044+
}
40414045
myMetadata += QLatin1String( "</td></tr>\n" );
40424046

40434047
// Extent

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,16 @@ QString QgsRasterLayer::htmlMetadata() const
324324
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>" ) + providerType() + QStringLiteral( "</td></tr>\n" );
325325

326326
// EPSG
327-
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" ) + crs().authid() + QStringLiteral( " - " );
328-
myMetadata += crs().description() + QStringLiteral( " - " );
329-
if ( crs().isGeographic() )
330-
myMetadata += tr( "Geographic" );
331-
else
332-
myMetadata += tr( "Projected" );
327+
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
328+
if ( crs().isValid() )
329+
{
330+
myMetadata += crs().authid() + QStringLiteral( " - " );
331+
myMetadata += crs().description() + QStringLiteral( " - " );
332+
if ( crs().isGeographic() )
333+
myMetadata += tr( "Geographic" );
334+
else
335+
myMetadata += tr( "Projected" );
336+
}
333337
myMetadata += QLatin1String( "</td></tr>\n" );
334338

335339
// Extent

0 commit comments

Comments
 (0)
Please sign in to comment.