Skip to content
Permalink
Browse files

QgsRasterProjector::destExtentSize - calc destination extent and size…

… from source
  • Loading branch information
blazek committed May 15, 2015
1 parent 3b00dc1 commit ece9a92d4cab3bed1b35c784e8675acb1619d185
Showing with 30 additions and 0 deletions.
  1. +25 −0 src/core/raster/qgsrasterprojector.cpp
  2. +5 −0 src/core/raster/qgsrasterprojector.h
@@ -14,6 +14,7 @@
* (at your option) any later version. *
* *
***************************************************************************/
#include <algorithm>

#include "qgsrasterdataprovider.h"
#include "qgscrscache.h"
@@ -941,3 +942,27 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex

return outputBlock;
}

bool QgsRasterProjector::destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize )
{
if ( theSrcExtent.isEmpty() || theSrcXSize <= 0 || theSrcYSize <= 0 )
{
return false;
}
QgsCoordinateTransform ct( mSrcCRS, mDestCRS );
theDestExtent = ct.transformBoundingBox( theSrcExtent );

// We reproject pixel rectangle from center of source, of course, it gives
// bigger xRes,yRes than reprojected edges (envelope), it may also be that
// close to margins are higher resolutions (even very, too high)
// TODO: consider more precise resolution calculation
double xRes = theSrcExtent.width() / theSrcXSize;
double yRes = theSrcExtent.height() / theSrcYSize;
QgsPoint srcCenter = theSrcExtent.center();
QgsRectangle srcCenterRectangle( srcCenter.x() - xRes / 2, srcCenter.y() - yRes / 2, srcCenter.x() + xRes / 2, srcCenter.y() + yRes / 2 );
QgsRectangle destCenterRectangle = ct.transformBoundingBox( srcCenterRectangle );
theDestXSize = std::max( 1, ( int )( theDestExtent.width() / destCenterRectangle.width() ) );
theDesYSize = std::max( 1, ( int )( theDestExtent.height() / destCenterRectangle.height() ) );
return true;
}
@@ -103,6 +103,11 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface

QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) override;

/** Calculate destination extent and size from source extent and size
*/
bool destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize,
QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize );

private:
/** get source extent */
QgsRectangle srcExtent() { return mSrcExtent; }

0 comments on commit ece9a92

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