Skip to content

Commit

Permalink
Crs (#5908)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Gustry authored and timlinux committed Dec 20, 2017
1 parent 9a5435f commit bf45d0b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions python/core/qgscoordinatereferencesystem.sip
Expand Up @@ -515,6 +515,7 @@ Returns opposite bool value to operator ==
bool readXml( const QDomNode &node );
%Docstring
Restores state from the given DOM node.
If it fails or if the node is empty, a default not empty CRS will be returned.

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

Expand Down
3 changes: 2 additions & 1 deletion src/core/metadata/qgslayermetadata.cpp
Expand Up @@ -366,7 +366,8 @@ bool QgsLayerMetadata::readMetadataXml( const QDomElement &metadataElement )

// crs
mnl = metadataElement.namedItem( QStringLiteral( "crs" ) );
mCrs.readXml( mnl );
if ( !mCrs.readXml( mnl ) )
mCrs = QgsCoordinateReferenceSystem();

// extent
mnl = metadataElement.namedItem( QStringLiteral( "extent" ) );
Expand Down
1 change: 1 addition & 0 deletions src/core/qgscoordinatereferencesystem.h
Expand Up @@ -466,6 +466,7 @@ class CORE_EXPORT QgsCoordinateReferenceSystem

/**
* Restores state from the given DOM node.
* If it fails or if the node is empty, a default not empty CRS will be returned.
* \param node The node from which state will be restored
* \returns bool True on success, False on failure
*/
Expand Down
16 changes: 10 additions & 6 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -4032,12 +4032,16 @@ QString QgsVectorLayer::htmlMetadata() const
}

// EPSG
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" ) + crs().authid() + QStringLiteral( " - " );
myMetadata += crs().description() + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
myMetadata += tr( "Projected" );
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( crs().isValid() )
{
myMetadata += crs().authid() + QStringLiteral( " - " );
myMetadata += crs().description() + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
myMetadata += tr( "Projected" );
}
myMetadata += QLatin1String( "</td></tr>\n" );

// Extent
Expand Down
16 changes: 10 additions & 6 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -324,12 +324,16 @@ QString QgsRasterLayer::htmlMetadata() const
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Provider" ) + QStringLiteral( "</td><td>" ) + providerType() + QStringLiteral( "</td></tr>\n" );

// EPSG
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" ) + crs().authid() + QStringLiteral( " - " );
myMetadata += crs().description() + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
myMetadata += tr( "Projected" );
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "CRS" ) + QStringLiteral( "</td><td>" );
if ( crs().isValid() )
{
myMetadata += crs().authid() + QStringLiteral( " - " );
myMetadata += crs().description() + QStringLiteral( " - " );
if ( crs().isGeographic() )
myMetadata += tr( "Geographic" );
else
myMetadata += tr( "Projected" );
}
myMetadata += QLatin1String( "</td></tr>\n" );

// Extent
Expand Down

0 comments on commit bf45d0b

Please sign in to comment.