Skip to content

Commit 65f92cc

Browse files
committed
Demote crs to 2d only crs before calling proj_trans_bounds
1 parent 450d080 commit 65f92cc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/core/proj/qgscoordinatetransform.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,23 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
637637
ProjData projData = d->threadLocalProjData();
638638
PJ_CONTEXT *projContext = QgsProjContext::get();
639639

640+
QgsProjUtils::proj_pj_unique_ptr srcCrs( proj_get_source_crs( projContext, projData ) );
641+
QgsProjUtils::proj_pj_unique_ptr destCrs( proj_get_target_crs( projContext, projData ) );
642+
643+
QgsProjUtils::proj_pj_unique_ptr srcCrsHorizontal;
644+
QgsProjUtils::proj_pj_unique_ptr destCrsHorizontal;
645+
QgsProjUtils::proj_pj_unique_ptr transform2D;
646+
if ( QgsProjUtils::hasVerticalAxis( srcCrs.get() ) ||
647+
QgsProjUtils::hasVerticalAxis( destCrs.get() ) )
648+
{
649+
// if source or destination crs include vertical components, we need to demote them to
650+
// 2d crs first, otherwise proj_trans_bounds fails
651+
srcCrsHorizontal = QgsProjUtils::crsToHorizontalCrs( srcCrs.get() );
652+
destCrsHorizontal = QgsProjUtils::crsToHorizontalCrs( destCrs.get() );
653+
transform2D.reset( proj_create_crs_to_crs_from_pj( projContext, srcCrsHorizontal.get(), destCrsHorizontal.get(), nullptr, nullptr ) );
654+
projData = transform2D.get();
655+
}
656+
640657
double transXMin = 0;
641658
double transYMin = 0;
642659
double transXMax = 0;
@@ -739,7 +756,7 @@ QgsRectangle QgsCoordinateTransform::transformBoundingBox( const QgsRectangle &r
739756
{
740757

741758
// Start at right edge
742-
double pointX = rect.xMinimum();
759+
double pointX = xMin;
743760

744761
for ( int j = 0; j < nXPoints; j++ )
745762
{

0 commit comments

Comments
 (0)