Skip to content

Commit 4d68a69

Browse files
committed
raster projector fixes
1 parent e30cd19 commit 4d68a69

4 files changed

+25
-42
lines changed

src/core/qgsrasterprojector.cpp

+23-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* *
1616
***************************************************************************/
1717

18+
#include "qgsrasterdataprovider.h"
1819
#include "qgslogger.h"
1920
#include "qgsrasterprojector.h"
2021
#include "qgscoordinatetransform.h"
@@ -59,35 +60,46 @@ QgsRasterProjector::QgsRasterProjector(
5960
}
6061

6162
QgsRasterProjector::QgsRasterProjector()
62-
: QgsRasterInterface( 0)
63+
: QgsRasterInterface( 0 )
6364
, pHelperTop( 0 ), pHelperBottom( 0 )
6465
{
6566
QgsDebugMsg( "Entered" );
6667
}
6768

6869
QgsRasterProjector::~QgsRasterProjector()
6970
{
70-
delete pHelperTop;
71-
delete pHelperBottom;
71+
delete[] pHelperTop;
72+
delete[] pHelperBottom;
7273
}
7374

7475
void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
7576
{
7677
mSrcCRS = theSrcCRS;
7778
mDestCRS = theDestCRS;
78-
mCoordinateTransform.setSourceCrs( theSrcCRS );
79-
mCoordinateTransform.setDestCRS( theDestCRS );
79+
mCoordinateTransform.setSourceCrs( theDestCRS );
80+
mCoordinateTransform.setDestCRS( theSrcCRS );
8081
}
8182

8283
void QgsRasterProjector::calc()
8384
{
8485
QgsDebugMsg( "Entered" );
8586
mCPMatrix.clear();
86-
delete pHelperTop;
87+
delete[] pHelperTop;
8788
pHelperTop = 0;
88-
delete pHelperBottom;
89+
delete[] pHelperBottom;
8990
pHelperBottom = 0;
9091

92+
// Get max source resolution if possible
93+
if ( mInput )
94+
{
95+
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() );
96+
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::ExactResolution ) )
97+
{
98+
mMaxSrcXRes = provider->extent().width() / provider->xSize();
99+
mMaxSrcYRes = provider->extent().height() / provider->ySize();
100+
}
101+
}
102+
91103
mDestXRes = mDestExtent.width() / ( mDestCols );
92104
mDestYRes = mDestExtent.height() / ( mDestRows );
93105

@@ -139,13 +151,13 @@ void QgsRasterProjector::calc()
139151
mApproximate = false;
140152
break;
141153
}
142-
143154
}
144155
QgsDebugMsg( QString( "CPMatrix size: mCPRows = %1 mCPCols = %2" ).arg( mCPRows ).arg( mCPCols ) );
145156
mDestRowsPerMatrixRow = ( float )mDestRows / ( mCPRows - 1 );
146157
mDestColsPerMatrixCol = ( float )mDestCols / ( mCPCols - 1 );
147158

148-
//QgsDebugMsg( "CPMatrix:\n" + cpToString() );
159+
QgsDebugMsgLevel( "CPMatrix:", 5 );
160+
QgsDebugMsgLevel( cpToString(), 5 );
149161

150162
// Calculate source dimensions
151163
calcSrcExtent();
@@ -568,7 +580,8 @@ bool QgsRasterProjector::checkRows()
568580

569581
void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
570582
{
571-
QgsDebugMsg( "Entered" );
583+
QgsDebugMsg( QString( "extent:\n%1" ).arg( extent.toString() ) );
584+
QgsDebugMsg( QString( "width = %1 height = %1" ).arg( width ).arg( height ) );
572585
if ( !mInput ) return 0;
573586

574587
if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )

src/core/qgsrasterprojector.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
130130
/** get source extent */
131131
QgsRectangle srcExtent() { return mSrcExtent; }
132132

133-
/** set source extent */
134-
void setSrcExtent( const QgsRectangle theExtent ) { mSrcExtent = theExtent; }
135-
136133
/** get/set source width/height */
137134
int srcRows() { return mSrcRows; }
138135
int srcCols() { return mSrcCols; }
@@ -154,7 +151,7 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
154151
/** Destination CRS */
155152
QgsCoordinateReferenceSystem mDestCRS;
156153

157-
/** Coordinate transform */
154+
/** Reverse coordinate transform (from destination to source) */
158155
QgsCoordinateTransform mCoordinateTransform;
159156

160157
/** Destination extent */

src/core/raster/qgsrasterlayer.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -829,30 +829,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
829829
// procedure to use :
830830
//
831831

832-
double maxSrcXRes = 0;
833-
double maxSrcYRes = 0;
834-
835-
if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution )
836-
{
837-
maxSrcXRes = mDataProvider->extent().width() / mDataProvider->xSize();
838-
maxSrcYRes = mDataProvider->extent().height() / mDataProvider->ySize();
839-
}
840-
/*
841-
if ( mRenderer )
842-
{
843-
//QgsRasterDrawer drawer( mRenderer );
844-
//QgsRasterDrawer drawer( mResampleFilter );
845-
846-
847-
QgsRasterProjector projector( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS, maxSrcXRes, maxSrcYRes, mDataProvider->extent() );
848-
849-
projector.setInput( mResampleFilter );
850-
851-
QgsRasterDrawer drawer( &projector );
852-
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
853-
}
854-
*/
855-
856832
QgsRasterProjector *projector = mPipe.projector();
857833
// TODO: add in init?
858834
if ( !projector )
@@ -866,8 +842,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
866842
if ( projector )
867843
{
868844
projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS );
869-
projector->setMaxSrcRes( maxSrcXRes, maxSrcYRes );
870-
projector->setSrcExtent( mDataProvider->extent() );
871845
}
872846

873847
// Drawer to pipe?

src/core/raster/qgsrasterresamplefilter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
6868
{
6969
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() );
7070
// Do not oversample if data source does not have fixed resolution (WMS)
71-
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::Size ) )
71+
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::ExactResolution ) )
7272
{
7373
double xRes = extent.width() / width;
7474
double providerXRes = provider->extent().width() / provider->xSize();
@@ -92,7 +92,6 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
9292

9393
// TODO: we must also increase the extent to get correct result on borders of parts
9494

95-
9695
int resWidth = width * oversamplingX;
9796
int resHeight = height * oversamplingY;
9897

0 commit comments

Comments
 (0)