Skip to content
Permalink
Browse files
Fix GetMap tile_buffer when labels are rotated
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 1, 2021
1 parent 7dddf19 commit df5806792388726f08206fc16edebaa5f04eae91
@@ -486,6 +486,16 @@ Returns the visible area as a polygon (may be rotated)

.. versionadded:: 2.8
%End

QPolygonF visiblePolygonWithBuffer() const;
%Docstring
Returns the visible area as a polygon (may be rotated) with extent buffer included

.. seealso:: :py:func:`extentBuffer`

.. versionadded:: 3.20
%End

double mapUnitsPerPixel() const;
%Docstring
Returns the distance in geographical coordinates that equals to one pixel in the map
@@ -297,8 +297,11 @@ void QgsLabelingEngine::solve( QgsRenderContext &context )

QPainter *painter = context.painter();

QgsGeometry extentGeom = QgsGeometry::fromRect( mMapSettings.visibleExtent() );
QPolygonF visiblePoly = mMapSettings.visiblePolygon();
QgsRectangle r1 = mMapSettings.visibleExtent();
r1.grow( mMapSettings.extentBuffer() );
QgsGeometry extentGeom = QgsGeometry::fromRect( r1 );

QPolygonF visiblePoly = mMapSettings.visiblePolygonWithBuffer();
visiblePoly.append( visiblePoly.at( 0 ) ); //close polygon

// get map label boundary geometry - if one hasn't been explicitly set, we use the whole of the map's visible polygon
@@ -773,4 +776,3 @@ QgsLabeling::LinePlacementFlags QgsLabelingUtils::decodeLinePlacementFlags( cons
flags |= QgsLabeling::LinePlacementFlag::MapOrientation;
return flags;
}

@@ -619,7 +619,7 @@ LabelRenderJob QgsMapRendererJob::prepareLabelingJob( QPainter *painter, QgsLabe

QgsRectangle r1 = mSettings.visibleExtent();
r1.grow( mSettings.extentBuffer() );
job.context.setExtent( mSettings.visibleExtent() );
job.context.setExtent( r1 );

job.context.setFeatureFilterProvider( mFeatureFilterProvider );

@@ -388,6 +388,28 @@ QPolygonF QgsMapSettings::visiblePolygon() const
return poly;
}

QPolygonF QgsMapSettings::visiblePolygonWithBuffer() const
{
QPolygonF poly;

const QSize &sz = outputSize();
const QgsMapToPixel &m2p = mapToPixel();

// Transform tilebuffer in pixel.
// Original tilebuffer is in pixel and transformed only according
// extent width (see QgsWmsRenderContext::mapTileBuffer)

const double mapUnitsPerPixel = mExtent.width() / sz.width();
const double buffer = mExtentBuffer / mapUnitsPerPixel;

poly << m2p.toMapCoordinates( -buffer, -buffer ).toQPointF();
poly << m2p.toMapCoordinates( static_cast<double>( sz.width() + buffer ), -buffer ).toQPointF();
poly << m2p.toMapCoordinates( static_cast<double>( sz.width() + buffer ), static_cast<double>( sz.height() + buffer ) ).toQPointF();
poly << m2p.toMapCoordinates( -buffer, static_cast<double>( sz.height() + buffer ) ).toQPointF();

return poly;
}

double QgsMapSettings::mapUnitsPerPixel() const
{
return mMapUnitsPerPixel;
@@ -449,6 +449,14 @@ class CORE_EXPORT QgsMapSettings : public QgsTemporalRangeObject
* \since QGIS 2.8
*/
QPolygonF visiblePolygon() const;

/**
* Returns the visible area as a polygon (may be rotated) with extent buffer included
* \see extentBuffer()
* \since QGIS 3.20
*/
QPolygonF visiblePolygonWithBuffer() const;

//! Returns the distance in geographical coordinates that equals to one pixel in the map
double mapUnitsPerPixel() const;

@@ -1806,6 +1806,25 @@ def test_wms_getmap_tile_buffer(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Tiled_Labels_True")

# Check with rotated labels and tiled=true
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(
os.path.join(self.testdata_path, 'wms_tile_buffer.qgs')),
"SERVICE": "WMS",
"VERSION": "1.3.0",
"REQUEST": "GetMap",
"BBOX": "317654,6163276,327603,6173244",
"CRS": "EPSG:3857",
"WIDTH": "512",
"HEIGHT": "512",
"LAYERS": "wms_tile_buffer_labels_rotated",
"FORMAT": "image/png",
"TILED": "true"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Tiled_Rotated_Labels_True")

@unittest.skipIf(os.getenv('QGIS_CONTINUOUS_INTEGRATION_RUN'), "This tests fails on GH workflow")
def test_mode8bit_with_transparency(self):
# 8 bits
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

0 comments on commit df58067

Please sign in to comment.