|
14 | 14 | * (at your option) any later version. *
|
15 | 15 | * *
|
16 | 16 | ***************************************************************************/
|
| 17 | +#include <algorithm> |
17 | 18 |
|
18 | 19 | #include "qgsrasterdataprovider.h"
|
19 | 20 | #include "qgscrscache.h"
|
@@ -941,3 +942,27 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
|
941 | 942 |
|
942 | 943 | return outputBlock;
|
943 | 944 | }
|
| 945 | + |
| 946 | +bool QgsRasterProjector::destExtentSize( const QgsRectangle& theSrcExtent, int theSrcXSize, int theSrcYSize, |
| 947 | + QgsRectangle& theDestExtent, int& theDestXSize, int& theDesYSize ) |
| 948 | +{ |
| 949 | + if ( theSrcExtent.isEmpty() || theSrcXSize <= 0 || theSrcYSize <= 0 ) |
| 950 | + { |
| 951 | + return false; |
| 952 | + } |
| 953 | + QgsCoordinateTransform ct( mSrcCRS, mDestCRS ); |
| 954 | + theDestExtent = ct.transformBoundingBox( theSrcExtent ); |
| 955 | + |
| 956 | + // We reproject pixel rectangle from center of source, of course, it gives |
| 957 | + // bigger xRes,yRes than reprojected edges (envelope), it may also be that |
| 958 | + // close to margins are higher resolutions (even very, too high) |
| 959 | + // TODO: consider more precise resolution calculation |
| 960 | + double xRes = theSrcExtent.width() / theSrcXSize; |
| 961 | + double yRes = theSrcExtent.height() / theSrcYSize; |
| 962 | + QgsPoint srcCenter = theSrcExtent.center(); |
| 963 | + QgsRectangle srcCenterRectangle( srcCenter.x() - xRes / 2, srcCenter.y() - yRes / 2, srcCenter.x() + xRes / 2, srcCenter.y() + yRes / 2 ); |
| 964 | + QgsRectangle destCenterRectangle = ct.transformBoundingBox( srcCenterRectangle ); |
| 965 | + theDestXSize = std::max( 1, ( int )( theDestExtent.width() / destCenterRectangle.width() ) ); |
| 966 | + theDesYSize = std::max( 1, ( int )( theDestExtent.height() / destCenterRectangle.height() ) ); |
| 967 | + return true; |
| 968 | +} |
0 commit comments