Skip to content
Permalink
Browse files

Merge pull request #3229 from mhugo/fix_15113

Allow curved polygons to be inverted (fixes #15113)
  • Loading branch information
mhugo committed Jun 23, 2016
2 parents e6970ba + 8976c9d commit defd7388bc612f0dd7c0a69f92fa27af09422357
@@ -288,13 +288,13 @@ void QgsInvertedPolygonRenderer::stopRender( QgsRenderContext& context )
Q_FOREACH ( QgsGeometry* geom, cit.geometries )
{
QgsMultiPolygon multi;
if (( geom->wkbType() == QGis::WKBPolygon ) ||
( geom->wkbType() == QGis::WKBPolygon25D ) )
QgsWKBTypes::Type type = QgsWKBTypes::flatType( geom->geometry()->wkbType() );

if (( type == QgsWKBTypes::Polygon ) || ( type == QgsWKBTypes::CurvePolygon ) )
{
multi.append( geom->asPolygon() );
}
else if (( geom->wkbType() == QGis::WKBMultiPolygon ) ||
( geom->wkbType() == QGis::WKBMultiPolygon25D ) )
else if (( type == QgsWKBTypes::MultiPolygon ) || ( type == QgsWKBTypes::MultiSurface ) )
{
multi = geom->asMultiPolygon();
}
@@ -34,11 +34,10 @@ QgsInvertedPolygonRendererWidget::QgsInvertedPolygonRendererWidget( QgsVectorLay
return;
}

QgsWKBTypes::Type type = QgsWKBTypes::singleType( QgsWKBTypes::flatType( QGis::fromOldWkbType( layer->wkbType() ) ) );

// the renderer only applies to polygon vector layers
if ( layer->wkbType() != QGis::WKBPolygon &&
layer->wkbType() != QGis::WKBPolygon25D &&
layer->wkbType() != QGis::WKBMultiPolygon &&
layer->wkbType() != QGis::WKBMultiPolygon25D )
if ( type != QgsWKBTypes::Polygon && type != QgsWKBTypes::CurvePolygon )
{
//setup blank dialog
mRenderer.reset( nullptr );
@@ -51,10 +51,13 @@ class TestQgsInvertedPolygon : public QObject
void graduatedSubRenderer();
void preprocess();
void projectionTest();
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_MAJOR >= 2
void curvedPolygons();
#endif

private:
bool mTestHasError;
bool setQml( const QString& qmlFile );
bool setQml( QgsVectorLayer* vlayer, const QString& qmlFile );
bool imageCheck( const QString& theType, const QgsRectangle* = 0 );
QgsMapSettings mMapSettings;
QgsVectorLayer * mpPolysLayer;
@@ -93,8 +96,7 @@ void TestQgsInvertedPolygon::initTestCase()
mpPolysLayer->setSimplifyMethod( simplifyMethod );

// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPolysLayer );
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer *>() << mpPolysLayer );

mMapSettings.setLayers( QStringList() << mpPolysLayer->id() );
mReport += "<h1>Inverted Polygon Renderer Tests</h1>\n";
@@ -117,22 +119,22 @@ void TestQgsInvertedPolygon::cleanupTestCase()
void TestQgsInvertedPolygon::singleSubRenderer()
{
mReport += "<h2>Inverted polygon renderer, single sub renderer test</h2>\n";
QVERIFY( setQml( "inverted_polys_single.qml" ) );
QVERIFY( setQml( mpPolysLayer, "inverted_polys_single.qml" ) );
QVERIFY( imageCheck( "inverted_polys_single" ) );
}

void TestQgsInvertedPolygon::graduatedSubRenderer()
{
mReport += "<h2>Inverted polygon renderer, graduated sub renderer test</h2>\n";
QVERIFY( setQml( "inverted_polys_graduated.qml" ) );
QVERIFY( setQml( mpPolysLayer, "inverted_polys_graduated.qml" ) );
QVERIFY( imageCheck( "inverted_polys_graduated" ) );
}

void TestQgsInvertedPolygon::preprocess()
{
// FIXME will have to find some overlapping polygons
mReport += "<h2>Inverted polygon renderer, preprocessing test</h2>\n";
QVERIFY( setQml( "inverted_polys_preprocess.qml" ) );
QVERIFY( setQml( mpPolysLayer, "inverted_polys_preprocess.qml" ) );
QVERIFY( imageCheck( "inverted_polys_preprocess" ) );
}

@@ -142,25 +144,44 @@ void TestQgsInvertedPolygon::projectionTest()
mMapSettings.setDestinationCrs( QgsCoordinateReferenceSystem( "EPSG:2154" ) );
mMapSettings.setCrsTransformEnabled( true );
QgsRectangle extent( QgsPoint( -8639421, 8382691 ), QgsPoint( -3969110, 12570905 ) );
QVERIFY( setQml( "inverted_polys_single.qml" ) );
QVERIFY( setQml( mpPolysLayer, "inverted_polys_single.qml" ) );
QVERIFY( imageCheck( "inverted_polys_projection", &extent ) );
QVERIFY( setQml( "inverted_polys_preprocess.qml" ) );
QVERIFY( setQml( mpPolysLayer, "inverted_polys_preprocess.qml" ) );
QVERIFY( imageCheck( "inverted_polys_projection2", &extent ) );
mMapSettings.setCrsTransformEnabled( false );
}

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_MAJOR >= 2
// This test relies on GDAL support of curved polygons
void TestQgsInvertedPolygon::curvedPolygons()
{
QString myCurvedPolysFileName = mTestDataDir + "curved_polys.gpkg";
QFileInfo myCurvedPolyFileInfo( myCurvedPolysFileName );
QgsVectorLayer* curvedLayer = new QgsVectorLayer( myCurvedPolyFileInfo.filePath() + "|layername=polys",
myCurvedPolyFileInfo.completeBaseName(), "ogr" );
curvedLayer->setSimplifyMethod( simplifyMethod );
QgsMapLayerRegistry::instance()->addMapLayers( QList<QgsMapLayer *>() << curvedLayer );

mReport += "<h2>Inverted polygon renderer, curved polygons test</h2>\n";
mMapSettings.setLayers( QStringList() << curvedLayer->id() );
QVERIFY( setQml( mpCurvedPolysLayer, "inverted_polys_single.qml" ) );
QVERIFY( imageCheck( "inverted_polys_curved" ) );
mMapSettings.setLayers( QStringList() << curvedLayer->id() );
}
#endif

//
// Private helper functions not called directly by CTest
//

bool TestQgsInvertedPolygon::setQml( const QString& qmlFile )
bool TestQgsInvertedPolygon::setQml( QgsVectorLayer* vlayer, const QString& qmlFile )
{
//load a qml style and apply to our layer
//the style will correspond to the renderer
//type we are testing
bool myStyleFlag = false;
QString myFileName = mTestDataDir + qmlFile;
QString error = mpPolysLayer->loadNamedStyle( myFileName, myStyleFlag );
QString error = vlayer->loadNamedStyle( myFileName, myStyleFlag );
if ( !myStyleFlag )
{
qDebug( "%s", error.toLocal8Bit().constData() );
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit defd738

Please sign in to comment.
You can’t perform that action at this time.