Skip to content

Commit

Permalink
Fix QgsMapSettings {mapToLayer,layerToMap}Coordinates failing with po…
Browse files Browse the repository at this point in the history
…ints having a nan z value
  • Loading branch information
nirvn committed Oct 15, 2020
1 parent ab6e615 commit e951aea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgsmapsettings.sip.in
Expand Up @@ -526,7 +526,7 @@ transform point coordinates from layer's CRS to output CRS
:return: the transformed point
%End

QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
%Docstring
transform point coordinates from layer's CRS to output CRS

Expand All @@ -551,7 +551,7 @@ transform point coordinates from output CRS to layer's CRS
:return: the transformed point
%End

QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;
%Docstring
transform point coordinates from output CRS to layer's CRS

Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsmapsettings.cpp
Expand Up @@ -496,11 +496,11 @@ QgsPointXY QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, QgsP
return point;
}

QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, QgsPoint point ) const
QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const
{
double x = point.x();
double y = point.y();
double z = point.z();
double z = !std::isnan( point.z() ) ? point.z() : 0.0;

try
{
Expand All @@ -513,7 +513,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, QgsPoi
QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
}

return QgsPoint( x, y, z );
return QgsPoint( x, y, !std::isnan( point.z() ) ? z : point.z() );
}


Expand Down Expand Up @@ -550,11 +550,11 @@ QgsPointXY QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, QgsP
return point;
}

QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, QgsPoint point ) const
QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const
{
double x = point.x();
double y = point.y();
double z = point.z();
double z = !std::isnan( point.z() ) ? point.z() : 0.0;

try
{
Expand All @@ -567,7 +567,7 @@ QgsPoint QgsMapSettings::mapToLayerCoordinates( const QgsMapLayer *layer, QgsPoi
QgsMessageLog::logMessage( QObject::tr( "Transform error caught: %1" ).arg( cse.what() ), QObject::tr( "CRS" ) );
}

return QgsPoint( x, y, z );
return QgsPoint( x, y, !std::isnan( point.z() ) ? z : point.z() );
}


Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmapsettings.h
Expand Up @@ -468,7 +468,7 @@ class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
* \returns the transformed point
* \since QGIS 3.16
*/
QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
QgsPoint layerToMapCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;

/**
* \brief transform rectangle from layer's CRS to output CRS
Expand All @@ -488,7 +488,7 @@ class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
* \returns the transformed point
* \since QGIS 3.16
*/
QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, QgsPoint point ) const;
QgsPoint mapToLayerCoordinates( const QgsMapLayer *layer, const QgsPoint &point ) const;

/**
* \brief transform rectangle from output CRS to layer's CRS
Expand Down

0 comments on commit e951aea

Please sign in to comment.