Skip to content

Commit

Permalink
Fix incorrect WCS request bbox when layer limited to an extent
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
manisandro authored and nyalldawson committed Apr 27, 2023
1 parent 2330b11 commit ef91cad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,11 @@ bool QgsWcsProvider::parseUri( const QString &uriString )

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

mBBOX = uri.param( QStringLiteral( "bbox" ) );
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
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class QgsWcsProvider final: public QgsRasterDataProvider, QgsGdalProviderBase
QString mTime;

//! Specified bounding box
QString mBBOX;
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
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ void QgsWCSSourceSelect::addButtonClicked()

if ( mSpatialExtentBox->isChecked() )
{
const QgsRectangle spatialExtent = mSpatialExtentBox->outputExtent();
QgsRectangle spatialExtent = mSpatialExtentBox->outputExtent();
spatialExtent = QgsCoordinateTransform(
mSpatialExtentBox->outputCrs(),
QgsCoordinateReferenceSystem( selectedCrs() ),
QgsProject::instance()->transformContext()
).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 ef91cad

Please sign in to comment.