Skip to content

Commit

Permalink
New parameter for WMS service: tile_buffer [needs-docs][FEATURE]
Browse files Browse the repository at this point in the history
  • Loading branch information
lbartoletti committed Jun 4, 2019
1 parent 8b83a46 commit 35c4209
Show file tree
Hide file tree
Showing 16 changed files with 817 additions and 30 deletions.
11 changes: 11 additions & 0 deletions python/server/auto_generated/qgsserverprojectutils.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ Returns the quality for WMS images defined in a QGIS project.
:param project: the QGIS project

:return: quality if defined in project, -1 otherwise.
%End

int wmsTileBuffer( const QgsProject &project );
%Docstring
Returns the tile buffer for WMS images defined in a QGIS project.

:param project: the QGIS project

:return: tile buffer if defined in project, 0 otherwise.

.. versionadded:: 3.10
%End

int wmsMaxAtlasFeatures( const QgsProject &project );
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsprojectproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSImageQualitySpinBox->setValue( imageQuality );
}

// WMS tileBuffer
mWMSTileBufferSpinBox->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMSTileBuffer" ), QStringLiteral( "/" ), 0 ) );

mWMSMaxAtlasFeaturesSpinBox->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 ) );

QString defaultValueToolTip = tr( "In case of no other information to evaluate the map unit sized symbols, it uses default scale (on projected CRS) or default map units per mm (on geographic CRS)." );
Expand Down Expand Up @@ -1323,6 +1326,9 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), imageQualityValue );
}

// WMS TileBuffer
QgsProject::instance()->writeEntry( QStringLiteral( "WMSTileBuffer" ), QStringLiteral( "/" ), mWMSTileBufferSpinBox->value() );

int maxAtlasFeatures = mWMSMaxAtlasFeaturesSpinBox->value();
QgsProject::instance()->writeEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), maxAtlasFeatures );

Expand Down
5 changes: 5 additions & 0 deletions src/server/qgsserverprojectutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ int QgsServerProjectUtils::wmsImageQuality( const QgsProject &project )
return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
}

int QgsServerProjectUtils::wmsTileBuffer( const QgsProject &project )
{
return project.readNumEntry( QStringLiteral( "WMSTileBuffer" ), QStringLiteral( "/" ), 0 );
}

int QgsServerProjectUtils::wmsMaxAtlasFeatures( const QgsProject &project )
{
return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
Expand Down
8 changes: 8 additions & 0 deletions src/server/qgsserverprojectutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT int wmsImageQuality( const QgsProject &project );

/**
* Returns the tile buffer for WMS images defined in a QGIS project.
* \param project the QGIS project
* \returns tile buffer if defined in project, 0 otherwise.
* \since QGIS 3.10
*/
SERVER_EXPORT int wmsTileBuffer( const QgsProject &project );

/**
* Returns the maximum number of atlas features which can be printed in a request
* \param project the QGIS project
Expand Down
1 change: 1 addition & 0 deletions src/server/services/wms/qgswmsgetmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace QgsWms
context.setFlag( QgsWmsRenderContext::AddHighlightLayers );
context.setFlag( QgsWmsRenderContext::AddExternalLayers );
context.setFlag( QgsWmsRenderContext::SetAccessControl );
context.setFlag( QgsWmsRenderContext::UseTileBuffer );
context.setParameters( parameters );

// rendering
Expand Down
15 changes: 15 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ namespace QgsWms
QVariant( 0 ) );
save( pQuality );

const QgsWmsParameter pTiled( QgsWmsParameter::TILED,
QVariant::Bool,
QVariant( false ) );
save( pTiled );

const QgsWmsParameter pBoxSpace( QgsWmsParameter::BOXSPACE,
QVariant::Double,
QVariant( 2.0 ) );
Expand Down Expand Up @@ -944,6 +949,16 @@ namespace QgsWms
return mWmsParameters[ QgsWmsParameter::IMAGE_QUALITY ].toInt();
}

QString QgsWmsParameters::tiled() const
{
return mWmsParameters[ QgsWmsParameter::TILED ].toString();
}

bool QgsWmsParameters::tiledAsBool() const
{
return mWmsParameters[ QgsWmsParameter::TILED ].toBool();
}

QString QgsWmsParameters::showFeatureCount() const
{
return mWmsParameters[ QgsWmsParameter::SHOWFEATURECOUNT ].toString();
Expand Down
17 changes: 16 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ namespace QgsWms
ATLAS_PK,
FORMAT_OPTIONS,
SRCWIDTH,
SRCHEIGHT
SRCHEIGHT,
TILED
};
Q_ENUM( Name )

Expand Down Expand Up @@ -628,6 +629,20 @@ namespace QgsWms
*/
int imageQualityAsInt() const;

/**
* Returns TILED parameter or an empty string if not
* defined.
* \since QGIS 3.10
*/
QString tiled() const;

/**
* Returns TILED parameter as a boolean.
* \throws QgsBadRequestException
* \since QGIS 3.10
*/
bool tiledAsBool() const;

/**
* Returns infoFormat. If the INFO_FORMAT parameter is not used, then the
* default value is text/plain.
Expand Down
46 changes: 37 additions & 9 deletions src/server/services/wms/qgswmsrendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using namespace QgsWms;

const double OGC_PX_M = 0.00028; // OGC reference pixel size in meter

QgsWmsRenderContext::QgsWmsRenderContext( const QgsProject *project, QgsServerInterface *interface )
: mProject( project )
, mInterface( interface )
Expand Down Expand Up @@ -132,6 +131,17 @@ int QgsWmsRenderContext::imageQuality() const
return imageQuality;
}

int QgsWmsRenderContext::tileBuffer() const
{
int tileBuffer = 0;

if ( mParameters.tiledAsBool() )
{
tileBuffer = QgsServerProjectUtils::wmsTileBuffer( *mProject );
}
return tileBuffer;
}

int QgsWmsRenderContext::precision() const
{
int precision = QgsServerProjectUtils::wmsFeatureInfoPrecision( *mProject );
Expand Down Expand Up @@ -638,22 +648,40 @@ bool QgsWmsRenderContext::isValidWidthHeight() const
return true;
}

QgsRectangle QgsWmsRenderContext::mapExtent() const
{
QgsRectangle extent = mParameters.bboxAsRectangle();
if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_InvalidParameterValue,
mParameters[QgsWmsParameter::BBOX] );
}
const double extentWidth = extent.width();
const double extentHeight = extent.height();
const int width = mapWidth();
const int height = mapHeight();
const double resolutionX = extentWidth / width;
const double resolutionY = extentHeight / height;
const int tBuffer = mFlags & UseTileBuffer ? tileBuffer() : 0;
const double xMin = extent.xMinimum() - tBuffer * resolutionX;
const double yMin = extent.yMinimum() - tBuffer * resolutionY;
const double xMax = extent.xMaximum() + tBuffer * resolutionX;
const double yMax = extent.yMaximum() + tBuffer * resolutionY;
return QgsRectangle( xMin, yMin, xMax, yMax );
}

QSize QgsWmsRenderContext::mapSize( const bool aspectRatio ) const
{
int width = mapWidth();
int height = mapHeight();
int tBuffer = mFlags & UseTileBuffer ? tileBuffer() : 0;
int width = mapWidth() + tBuffer * 2;
int height = mapHeight() + tBuffer * 2;

// Adapt width / height if the aspect ratio does not correspond with the BBOX.
// Required by WMS spec. 1.3.
if ( aspectRatio
&& mParameters.versionAsNumber() >= QgsProjectVersion( 1, 3, 0 ) )
{
QgsRectangle extent = mParameters.bboxAsRectangle();
if ( !mParameters.bbox().isEmpty() && extent.isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_InvalidParameterValue,
mParameters[QgsWmsParameter::BBOX] );
}
QgsRectangle extent = mapExtent();

QString crs = mParameters.crs();
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
Expand Down
16 changes: 15 additions & 1 deletion src/server/services/wms/qgswmsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace QgsWms
AddQueryLayers = 0x80,
UseWfsLayersOnly = 0x100,
AddExternalLayers = 0x200,
UseSrcWidthHeight = 0x400
UseSrcWidthHeight = 0x400,
UseTileBuffer = 0x800
};
Q_DECLARE_FLAGS( Flags, Flag )

Expand Down Expand Up @@ -148,6 +149,13 @@ namespace QgsWms
*/
int imageQuality() const;

/**
* Returns the tile buffer value to use for rendering according to the
* current configuration.
* \since QGIS 3.10
*/
int tileBuffer() const;

/**
* Returns the precision to use according to the current configuration.
*/
Expand Down Expand Up @@ -200,6 +208,12 @@ namespace QgsWms
*/
QMap<QString, QList<QgsMapLayer *> > layerGroups() const;

/**
* Returns the extent of the map to render.
* \since QGIS 3.10
*/
QgsRectangle mapExtent() const;

/**
* Returns the size (in pixels) of the map to render, according to width
* and height WMS parameters as well as the \a aspectRatio option.
Expand Down
14 changes: 7 additions & 7 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* *
***************************************************************************/


#include "qgswmsutils.h"
#include "qgsjsonutils.h"
#include "qgswmsrenderer.h"
Expand Down Expand Up @@ -771,6 +770,12 @@ namespace QgsWms
// painting is terminated
painter->end();

if ( mContext.testFlag( QgsWmsRenderContext::UseTileBuffer ) )
{
QRect rect( mContext.tileBuffer(), mContext.tileBuffer(), mContext.mapWidth(), mContext.mapHeight() );
image.reset( new QImage( image.get()->copy( rect ) ) );
}

// scale output image if necessary (required by WMS spec)
QImage *scaledImage = scaleImage( image.get() );
if ( scaledImage )
Expand Down Expand Up @@ -977,12 +982,7 @@ namespace QgsWms
mapSettings.setOutputDpi( paintDevice->logicalDpiX() );

//map extent
QgsRectangle mapExtent = mWmsParameters.bboxAsRectangle();
if ( !mWmsParameters.bbox().isEmpty() && mapExtent.isEmpty() )
{
throw QgsBadRequestException( QgsServiceException::QGIS_InvalidParameterValue,
mWmsParameters[QgsWmsParameter::BBOX] );
}
QgsRectangle mapExtent = mContext.mapExtent();

QString crs = mWmsParameters.crs();
if ( crs.compare( "CRS:84", Qt::CaseInsensitive ) == 0 )
Expand Down
38 changes: 26 additions & 12 deletions src/ui/qgsprojectpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>4</number>
<number>8</number>
</property>
<widget class="QWidget" name="mProjOptsGeneral">
<layout class="QVBoxLayout" name="verticalLayout_6">
Expand Down Expand Up @@ -265,8 +265,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>537</width>
<height>795</height>
<width>535</width>
<height>740</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
Expand Down Expand Up @@ -863,8 +863,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>546</width>
<height>164</height>
<width>544</width>
<height>155</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -938,8 +938,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>269</width>
<height>553</height>
<width>266</width>
<height>524</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1514,8 +1514,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>167</width>
<height>55</height>
<width>165</width>
<height>52</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
Expand Down Expand Up @@ -1575,9 +1575,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>598</width>
<height>2732</height>
<y>-793</y>
<width>671</width>
<height>2614</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
Expand Down Expand Up @@ -2437,6 +2437,20 @@
</item>
</layout>
</item>
<item row="11" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<widget class="QLabel" name="label_33">
<property name="text">
<string>Tile buffer</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mWMSTileBufferSpinBox"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
Expand Down
Loading

0 comments on commit 35c4209

Please sign in to comment.