Skip to content
Permalink
Browse files

Revert QgsMapSettings change, fix root cause in QgsCoordinateTransform

  • Loading branch information
nirvn committed Oct 15, 2020
1 parent 52416dd commit 2653afc12debf43bf765c42bdfdf55efa6c3990f
Showing with 37 additions and 4 deletions.
  1. +16 −0 src/core/qgscoordinatetransform.cpp
  2. +4 −4 src/core/qgsmapsettings.cpp
  3. +17 −0 tests/src/core/testqgscoordinatetransform.cpp
@@ -646,6 +646,16 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
return;
}

std::vector< int > zNanPositions;
for ( int i = 0; i < numPoints; i++ )
{
if ( std::isnan( z[i] ) )
{
zNanPositions.push_back( i );
z[i] = 0.0;
}
}

#if PROJ_VERSION_MAJOR>=6
std::vector< double > xprev( numPoints );
memcpy( xprev.data(), x, sizeof( double ) * numPoints );
@@ -795,6 +805,12 @@ void QgsCoordinateTransform::transformCoords( int numPoints, double *x, double *
}
}
#endif

for ( const int &pos : zNanPositions )
{
z[pos] = std::numeric_limits<double>::quiet_NaN();
}

if ( projResult != 0 )
{
//something bad happened....
@@ -500,7 +500,7 @@ QgsPoint QgsMapSettings::layerToMapCoordinates( const QgsMapLayer *layer, const
{
double x = point.x();
double y = point.y();
double z = !std::isnan( point.z() ) ? point.z() : 0.0;
double z = point.z();

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

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


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

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

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


@@ -43,6 +43,7 @@ class TestQgsCoordinateTransform: public QObject
void transform();
void transformLKS();
void transformContextNormalize();
void transform2DPoint();
void transformErrorMultiplePoints();
void transformErrorOnePoint();
void testDeprecated4240to4326();
@@ -486,6 +487,22 @@ void TestQgsCoordinateTransform::transformContextNormalize()
#endif
}

void TestQgsCoordinateTransform::transform2DPoint()
{
// Check that we properly handle 2D point transform
QgsCoordinateTransformContext context;
QgsCoordinateTransform ct( QgsCoordinateReferenceSystem::fromEpsgId( 4326 ), QgsCoordinateReferenceSystem::fromEpsgId( 3857 ), context );
QVERIFY( ct.isValid() );
QgsPoint pt( 0.0, 0.0 );
double x = pt.x();
double y = pt.y();
double z = pt.z();
ct.transformInPlace( x, y, z );

QGSCOMPARENEAR( x, 0.0, 0.01 );
QGSCOMPARENEAR( y, 0.0, 0.01 );
QGSCOMPARENEAR( z, pt.z(), 0.01 );
}

void TestQgsCoordinateTransform::transformErrorMultiplePoints()
{

0 comments on commit 2653afc

Please sign in to comment.
You can’t perform that action at this time.