Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport queued_ltr_backports] Fix bug with inverted polygon renderer vs OTF simplification #58480

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/PyQt6/core/auto_generated/qgsrendercontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ Sets whether the rendering optimization (geometry simplification) should be exec
.. seealso:: :py:func:`useRenderingOptimization`
%End

const QgsVectorSimplifyMethod &vectorSimplifyMethod() const;
QgsVectorSimplifyMethod &vectorSimplifyMethod();
%Docstring
Returns the simplification settings to use when rendering vector layers.

Expand All @@ -646,6 +646,7 @@ The default is to use no simplification.
.. versionadded:: 2.4
%End


void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod );
%Docstring
Sets the simplification setting to use when rendering vector layers.
Expand Down
3 changes: 2 additions & 1 deletion python/core/auto_generated/qgsrendercontext.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ Sets whether the rendering optimization (geometry simplification) should be exec
.. seealso:: :py:func:`useRenderingOptimization`
%End

const QgsVectorSimplifyMethod &vectorSimplifyMethod() const;
QgsVectorSimplifyMethod &vectorSimplifyMethod();
%Docstring
Returns the simplification settings to use when rendering vector layers.

Expand All @@ -646,6 +646,7 @@ The default is to use no simplification.
.. versionadded:: 2.4
%End


void setVectorSimplifyMethod( const QgsVectorSimplifyMethod &simplifyMethod );
%Docstring
Sets the simplification setting to use when rendering vector layers.
Expand Down
11 changes: 10 additions & 1 deletion src/core/qgsrendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,16 @@ class CORE_EXPORT QgsRenderContext : public QgsTemporalRangeObject
* \see setVectorSimplifyMethod()
* \since QGIS 2.4
*/
const QgsVectorSimplifyMethod &vectorSimplifyMethod() const { return mVectorSimplifyMethod; }
QgsVectorSimplifyMethod &vectorSimplifyMethod() { return mVectorSimplifyMethod; }

/**
* Returns the simplification settings to use when rendering vector layers.
*
* The default is to use no simplification.
*
* \see setVectorSimplifyMethod()
*/
const QgsVectorSimplifyMethod &vectorSimplifyMethod() const SIP_SKIP { return mVectorSimplifyMethod; }

/**
* Sets the simplification setting to use when rendering vector layers.
Expand Down
19 changes: 19 additions & 0 deletions src/core/symbology/qgsmergedfeaturerenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgspainteffect.h"
#include "qgspainteffectregistry.h"
#include "qgsstyleentityvisitor.h"
#include "qgsmaptopixelgeometrysimplifier.h"

#include <QDomDocument>
#include <QDomElement>
Expand Down Expand Up @@ -232,6 +233,20 @@ bool QgsMergedFeatureRenderer::renderFeature( const QgsFeature &feature, QgsRend
}
QgsGeometry geom = feature.geometry();

// Simplify the geometry, if needed.
if ( context.vectorSimplifyMethod().forceLocalOptimization() )
{
const int simplifyHints = context.vectorSimplifyMethod().simplifyHints();
const QgsMapToPixelSimplifier simplifier( simplifyHints, context.vectorSimplifyMethod().tolerance(),
context.vectorSimplifyMethod().simplifyAlgorithm() );

QgsGeometry simplified( simplifier.simplify( geom ) );
if ( !simplified.isEmpty() )
{
geom = simplified;
}
}

QgsCoordinateTransform xform = context.coordinateTransform();
if ( xform.isValid() )
{
Expand Down Expand Up @@ -366,7 +381,11 @@ void QgsMergedFeatureRenderer::stopRender( QgsRenderContext &context )
if ( feat.hasGeometry() )
{
mContext.expressionContext().setFeature( feat );
const bool prevSimplify = context.vectorSimplifyMethod().forceLocalOptimization();
// we've already simplified, no need to re-do simplification
mContext.vectorSimplifyMethod().setForceLocalOptimization( false );
mSubRenderer->renderFeature( feat, mContext );
mContext.vectorSimplifyMethod().setForceLocalOptimization( prevSimplify );
}
}

Expand Down
35 changes: 33 additions & 2 deletions tests/src/core/testqgsinvertedpolygonrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <qgsproviderregistry.h>
#include <qgsproject.h>
#include "qgsrenderer.h"

#include "qgsfillsymbol.h"
#include "qgsinvertedpolygonrenderer.h"
#include "qgssinglesymbolrenderer.h"
//qgis test includes
#include "qgsmultirenderchecker.h"

Expand All @@ -41,7 +43,7 @@ class TestQgsInvertedPolygon : public QgsTest
Q_OBJECT

public:
TestQgsInvertedPolygon() : QgsTest( QStringLiteral( "Inverted Polygon Renderer Tests" ) ) {}
TestQgsInvertedPolygon() : QgsTest( QStringLiteral( "Inverted Polygon Renderer Tests" ), QStringLiteral( "symbol_invertedpolygon" ) ) {}

private slots:
void initTestCase();// will be called before the first testfunction is executed.
Expand All @@ -52,6 +54,7 @@ class TestQgsInvertedPolygon : public QgsTest
void checkSymbolItem();
void preprocess();
void projectionTest();
void projectionWithSimplificationTest();
void curvedPolygons();
void rotationTest();

Expand Down Expand Up @@ -136,6 +139,34 @@ void TestQgsInvertedPolygon::projectionTest()
mMapSettings.setDestinationCrs( mpPolysLayer->crs() );
}

void TestQgsInvertedPolygon::projectionWithSimplificationTest()
{
std::unique_ptr< QgsVectorLayer > polyLayer = std::make_unique< QgsVectorLayer >( testDataPath( "polys.shp" ), QStringLiteral( "polys" ) );
QVERIFY( polyLayer->isValid() );
QgsMapSettings mapSettings;
mapSettings.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) ) );
mapSettings.setLayers( QList<QgsMapLayer *>() << polyLayer.get() );
mapSettings.setOutputDpi( 96 );

QgsFillSymbol *fill = QgsFillSymbol::createSimple( QVariantMap( {{"color", "#fdbf6f"}, {"outline_color", "black"},
{ "outline_width", "1"}} ) );
QgsInvertedPolygonRenderer *renderer = new QgsInvertedPolygonRenderer();
QgsSingleSymbolRenderer *singleSymbolRenderer = new QgsSingleSymbolRenderer( fill );
renderer->setEmbeddedRenderer( singleSymbolRenderer );
polyLayer->setRenderer( renderer );

mapSettings.setExtent( QgsRectangle( -119.552, 25.255, -109.393, 32.651 ) );

QgsVectorSimplifyMethod simplifyMethod;
simplifyMethod.setSimplifyHints( QgsVectorSimplifyMethod::GeometrySimplification );
simplifyMethod.setForceLocalOptimization( true );
simplifyMethod.setSimplifyAlgorithm( QgsVectorSimplifyMethod::SnappedToGridGlobal );
simplifyMethod.setThreshold( 0.1f );
mapSettings.setSimplifyMethod( simplifyMethod );

QGSVERIFYRENDERMAPSETTINGSCHECK( QStringLiteral( "inverted_polys_projection_simplification" ), QStringLiteral( "inverted_polys_projection_simplification" ), mapSettings );
}

void TestQgsInvertedPolygon::curvedPolygons()
{
const QString myCurvedPolysFileName = mTestDataDir + "curved_polys.gpkg";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading