Skip to content
Permalink
Browse files

Fix features right on the edges of geographic layers can disappear when

reprojected

Eg +/- 180 degree grid lines

Fixes #27571
  • Loading branch information
nyalldawson committed Dec 18, 2019
1 parent b566eac commit 971552a782d7a965c24ee404e607895970da74c7
@@ -154,8 +154,12 @@ bool QgsMapRendererJob::reprojectToLayerExtent( const QgsMapLayer *ml, const Qgs
.arg( std::fabs( 1.0 - extent2.height() / extent.height() ) )
, 3 );

if ( std::fabs( 1.0 - extent2.width() / extent.width() ) < 0.5 &&
std::fabs( 1.0 - extent2.height() / extent.height() ) < 0.5 )
// can differ by a maximum of up to 20% of height/width
if ( qgsDoubleNear( extent2.xMinimum(), extent.xMinimum(), extent.width() * 0.2 )
&& qgsDoubleNear( extent2.xMaximum(), extent.xMaximum(), extent.width() * 0.2 )
&& qgsDoubleNear( extent2.yMinimum(), extent.yMinimum(), extent.height() * 0.2 )
&& qgsDoubleNear( extent2.yMaximum(), extent.yMaximum(), extent.height() * 0.2 )
)
{
extent = extent1;
}
@@ -42,6 +42,7 @@
#include "qgsvectorlayerlabeling.h"
#include "qgsfontutils.h"
#include "qgsrasterlayer.h"
#include "qgssinglesymbolrenderer.h"

//qgs unit test utility class
#include "qgsrenderchecker.h"
@@ -84,6 +85,8 @@ class TestQgsMapRendererJob : public QObject
void stagedRenderer();
void stagedRendererWithStagedLabeling();

void vectorLayerBoundsWithReprojection();

private:
bool imageCheck( const QString &type, const QImage &image, int mismatchCount = 0 );

@@ -857,6 +860,34 @@ void TestQgsMapRendererJob::stagedRendererWithStagedLabeling()
QVERIFY( !job->renderCurrentPart( &painter ) );
}

void TestQgsMapRendererJob::vectorLayerBoundsWithReprojection()
{
std::unique_ptr< QgsVectorLayer > gridLayer = qgis::make_unique< QgsVectorLayer >( TEST_DATA_DIR + QStringLiteral( "/grid_4326.geojson" ),
QStringLiteral( "grid" ), QStringLiteral( "ogr" ) );
QVERIFY( gridLayer->isValid() );

std::unique_ptr< QgsLineSymbol > symbol = qgis::make_unique< QgsLineSymbol >();
symbol->setColor( QColor( 255, 0, 255 ) );
symbol->setWidth( 2 );
std::unique_ptr< QgsSingleSymbolRenderer > renderer = qgis::make_unique< QgsSingleSymbolRenderer >( symbol.release() );
gridLayer->setRenderer( renderer.release() );

QgsMapSettings mapSettings;

mapSettings.setDestinationCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:3857" ) ) );
mapSettings.setExtent( QgsRectangle( -37000835.1, -20182273.7, 37000835.1, 20182273.7 ) );
mapSettings.setOutputSize( QSize( 512, 512 ) );
mapSettings.setFlag( QgsMapSettings::DrawLabeling, false );
mapSettings.setOutputDpi( 96 );
mapSettings.setLayers( QList< QgsMapLayer * >() << gridLayer.get() );

QgsMapRendererSequentialJob renderJob( mapSettings );
renderJob.start();
renderJob.waitForFinished();
QImage img = renderJob.renderedImage();
QVERIFY( imageCheck( QStringLiteral( "vector_layer_bounds_with_reprojection" ), img ) );
}

bool TestQgsMapRendererJob::imageCheck( const QString &testName, const QImage &image, int mismatchCount )
{
mReport += "<h2>" + testName + "</h2>\n";
Binary file not shown.

Large diffs are not rendered by default.

0 comments on commit 971552a

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