Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix incorrect WCS request bbox when layer limited to an extent (#52900)
* Fix incorrect WCS request bbox when layer limited to an extent

- The passed extent was in WGS84 and not necessarily in the selected CRS
- The delimiting extent was not intersected with the current view extent, resulting in an incorrect request bbox

---------

Co-authored-by: Nyall Dawson <nyall.dawson@gmail.com>
  • Loading branch information
manisandro and nyalldawson committed Apr 27, 2023
1 parent 97f41ce commit 9d5af2a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/gui/qgsowssourceselect.cpp
Expand Up @@ -424,6 +424,7 @@ void QgsOWSSourceSelect::mChangeCRSButton_clicked()
return;

mSelectedCRS = mySelector->crs().authid();
mSpatialExtentBox->setOutputCrs( mySelector->crs() );
delete mySelector;

mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
Expand Down Expand Up @@ -480,6 +481,7 @@ void QgsOWSSourceSelect::populateCrs()
mSelectedCRS = defaultCRS;
}
}
mSpatialExtentBox->setOutputCrs( QgsCoordinateReferenceSystem( mSelectedCRS ) );
mSelectedCRSLabel->setText( descriptionForAuthId( mSelectedCRS ) );
mChangeCRSButton->setEnabled( true );
}
Expand Down
20 changes: 16 additions & 4 deletions src/providers/wcs/qgswcsprovider.cpp
Expand Up @@ -438,7 +438,11 @@ bool QgsWcsProvider::parseUri( const QString &uriString )

mTime = uri.param( QStringLiteral( "time" ) );

mBBOX = uri.param( QStringLiteral( "bbox" ) );
const QStringList bboxParts = uri.param( QStringLiteral( "bbox" ) ).split( "," );
if ( bboxParts.length() == 4 )
{
mBBOX = QgsRectangle( bboxParts[0].toDouble(), bboxParts[1].toDouble(), bboxParts[2].toDouble(), bboxParts[3].toDouble() );
}

setFormat( uri.param( QStringLiteral( "format" ) ) );

Expand Down Expand Up @@ -699,8 +703,16 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const &viewExtent, int
extent = QgsRectangle( viewExtent.xMinimum() + xRes / 2., viewExtent.yMinimum() + yRes / 2., viewExtent.xMaximum() - xRes / 2., viewExtent.yMaximum() - yRes / 2. );
}

if ( changeXY )
{
extent = QgsRectangle( extent.yMinimum(), extent.xMinimum(), extent.yMaximum(), extent.xMaximum() );
}
if ( !mBBOX.isEmpty() )
{
extent = extent.intersect( mBBOX );
}
// Bounding box in WCS format (Warning: does not work with scientific notation)
QString bbox = QString( changeXY ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
QString bbox = QString( "%1,%2,%3,%4" )
.arg( qgsDoubleToString( extent.xMinimum() ),
qgsDoubleToString( extent.yMinimum() ),
qgsDoubleToString( extent.xMaximum() ),
Expand Down Expand Up @@ -729,7 +741,7 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const &viewExtent, int
setQueryItem( url, QStringLiteral( "TIME" ), mTime );
}

setQueryItem( url, QStringLiteral( "BBOX" ), !mBBOX.isEmpty() ? mBBOX : bbox );
setQueryItem( url, QStringLiteral( "BBOX" ), bbox );

setQueryItem( url, QStringLiteral( "CRS" ), crs ); // request BBOX CRS
setQueryItem( url, QStringLiteral( "RESPONSE_CRS" ), crs ); // response CRS
Expand All @@ -749,7 +761,7 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const &viewExtent, int
setQueryItem( url, QStringLiteral( "TIMESEQUENCE" ), mTime );
}

setQueryItem( url, QStringLiteral( "BOUNDINGBOX" ), !mBBOX.isEmpty() ? mBBOX : bbox );
setQueryItem( url, QStringLiteral( "BOUNDINGBOX" ), bbox );


// Example:
Expand Down
4 changes: 2 additions & 2 deletions src/providers/wcs/qgswcsprovider.h
Expand Up @@ -261,8 +261,8 @@ class QgsWcsProvider final: public QgsRasterDataProvider, QgsGdalProviderBase
//! Time (temporalDomain), optional
QString mTime;

//! Specified bounding box
QString mBBOX;
//! Specified bounding box. Note: X/Y may be inverted if WCS uri contains InvertAxisOrientation.
QgsRectangle mBBOX;

//! Format of coverage to be used in request
QString mFormat;
Expand Down
7 changes: 6 additions & 1 deletion src/providers/wcs/qgswcssourceselect.cpp
Expand Up @@ -143,7 +143,12 @@ void QgsWCSSourceSelect::addButtonClicked()

if ( mSpatialExtentBox->isChecked() )
{
const QgsRectangle spatialExtent = mSpatialExtentBox->outputExtent();
QgsRectangle spatialExtent = mSpatialExtentBox->outputExtent();
QgsCoordinateTransform extentCrsToSSelectedCrs( mSpatialExtentBox->outputCrs(),
QgsCoordinateReferenceSystem( selectedCrs() ),
QgsProject::instance()->transformContext() );
extentCrsToSSelectedCrs.setBallparkTransformsAreAppropriate( true );
spatialExtent = extentCrsToSSelectedCrs.transformBoundingBox( spatialExtent );
bool inverted = uri.hasParam( QStringLiteral( "InvertAxisOrientation" ) );
QString bbox = QString( inverted ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
.arg( qgsDoubleToString( spatialExtent.xMinimum() ),
Expand Down

0 comments on commit 9d5af2a

Please sign in to comment.