Skip to content

Commit

Permalink
Force wmts resolution to 90 dpi if paint device dpi is < 225
Browse files Browse the repository at this point in the history
Ref: a169ad1a1e34406d72fe9dd860d8d3ede4adb855
  • Loading branch information
mhugent committed Dec 22, 2016
1 parent 7c0259c commit 09bb1c8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
52 changes: 48 additions & 4 deletions src/core/raster/qgsrasterdrawer.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgslogger.h"
#include "qgsrasterdataprovider.h"
#include "qgsrasterdrawer.h"
#include "qgsrasteriterator.h"
#include "qgsrasterviewport.h"
Expand All @@ -41,9 +42,29 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
return;
}

int width = viewPort->mWidth;
int height = viewPort->mHeight;
QgsMapToPixel mapToPixel( *theQgsMapToPixel );
double scaleFactor = 1.0;

if ( ctx && isWMTSLayer( mIterator->input() ) ) //wmts case, comply with standard pixel size of 0.28mm from specification
{
scaleFactor = ( 1.0 / 0.28 * 25.4 ) / p->device()->logicalDpiX();
if ( scaleFactor < 0.4 )
{
width = width * scaleFactor;
height = height * scaleFactor;
mapToPixel.setParameters( ctx->extent().width() / width, ctx->extent().xMinimum(), ctx->extent().yMinimum(), height );
}
else
{
scaleFactor = 1.0;
}
}

// last pipe filter has only 1 band
int bandNumber = 1;
mIterator->startRasterRead( bandNumber, viewPort->mWidth, viewPort->mHeight, viewPort->mDrawnExtent );
mIterator->startRasterRead( bandNumber, width, height, viewPort->mDrawnExtent );

//number of cols/rows in output pixels
int nCols = 0;
Expand Down Expand Up @@ -90,15 +111,15 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
}
}

drawImage( p, viewPort, img, topLeftCol, topLeftRow, theQgsMapToPixel );
drawImage( p, viewPort, img, topLeftCol, topLeftRow, scaleFactor, &mapToPixel );
QgsDebugMsg( "Block drawn" );

delete block;
if ( ctx && ctx->renderingStopped() ) { break; }
}
}

void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow, const QgsMapToPixel* theQgsMapToPixel ) const
void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow, double scaleFactor, const QgsMapToPixel* theQgsMapToPixel ) const
{
if ( !p || !viewPort )
{
Expand Down Expand Up @@ -132,7 +153,16 @@ void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const
}
}

p->drawImage( tlPoint, img );
if ( qgsDoubleNear( scaleFactor, 1.0 ) )
{
p->drawImage( tlPoint, img );
}
else
{
QRect source( 0, 0, img.width(), img.height() );
QRect target( tlPoint.x(), tlPoint.y(), img.width() / scaleFactor, img.height() / scaleFactor );
p->drawImage( target, img, source );
}

#if 0
// For debugging:
Expand All @@ -155,3 +185,17 @@ void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const
p->restore();
}

bool QgsRasterDrawer::isWMTSLayer( const QgsRasterInterface* iface )
{
if ( iface && iface->srcInput() )
{
const QgsRasterDataProvider* provider = dynamic_cast<const QgsRasterDataProvider*>( iface->srcInput() );
QVariant resolutions = provider->property( "resolutions" );
if ( provider->name() == "wms" && !resolutions.isNull() )
{
return true;
}
}
return false;
}

4 changes: 3 additions & 1 deletion src/core/raster/qgsrasterdrawer.h
Expand Up @@ -48,10 +48,12 @@ class CORE_EXPORT QgsRasterDrawer
@param topLeftRow Top position relative to top border of viewport
@param mapToPixel map to device coordinate transformation info
(not available in python bindings) */
void drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow, const QgsMapToPixel* mapToPixel = 0 ) const;
void drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow, double scaleFactor, const QgsMapToPixel* mapToPixel = 0 ) const;

private:
QgsRasterIterator* mIterator;

static bool isWMTSLayer( const QgsRasterInterface* iface );
};

#endif // QGSRASTERDRAWER_H

0 comments on commit 09bb1c8

Please sign in to comment.