Skip to content
Permalink
Browse files

raster projector fixes

  • Loading branch information
blazek committed Jul 1, 2012
1 parent e30cd19 commit 4d68a69fed4e6184baad84f0ed50e0e2e670d2f6
@@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgsrasterdataprovider.h"
#include "qgslogger.h"
#include "qgsrasterprojector.h"
#include "qgscoordinatetransform.h"
@@ -59,35 +60,46 @@ QgsRasterProjector::QgsRasterProjector(
}

QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( 0)
: QgsRasterInterface( 0 )
, pHelperTop( 0 ), pHelperBottom( 0 )
{
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::~QgsRasterProjector()
{
delete pHelperTop;
delete pHelperBottom;
delete[] pHelperTop;
delete[] pHelperBottom;
}

void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
{
mSrcCRS = theSrcCRS;
mDestCRS = theDestCRS;
mCoordinateTransform.setSourceCrs( theSrcCRS );
mCoordinateTransform.setDestCRS( theDestCRS );
mCoordinateTransform.setSourceCrs( theDestCRS );
mCoordinateTransform.setDestCRS( theSrcCRS );
}

void QgsRasterProjector::calc()
{
QgsDebugMsg( "Entered" );
mCPMatrix.clear();
delete pHelperTop;
delete[] pHelperTop;
pHelperTop = 0;
delete pHelperBottom;
delete[] pHelperBottom;
pHelperBottom = 0;

// Get max source resolution if possible
if ( mInput )
{
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() );
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::ExactResolution ) )
{
mMaxSrcXRes = provider->extent().width() / provider->xSize();
mMaxSrcYRes = provider->extent().height() / provider->ySize();
}
}

mDestXRes = mDestExtent.width() / ( mDestCols );
mDestYRes = mDestExtent.height() / ( mDestRows );

@@ -139,13 +151,13 @@ void QgsRasterProjector::calc()
mApproximate = false;
break;
}

}
QgsDebugMsg( QString( "CPMatrix size: mCPRows = %1 mCPCols = %2" ).arg( mCPRows ).arg( mCPCols ) );
mDestRowsPerMatrixRow = ( float )mDestRows / ( mCPRows - 1 );
mDestColsPerMatrixCol = ( float )mDestCols / ( mCPCols - 1 );

//QgsDebugMsg( "CPMatrix:\n" + cpToString() );
QgsDebugMsgLevel( "CPMatrix:", 5 );
QgsDebugMsgLevel( cpToString(), 5 );

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

void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
QgsDebugMsg( "Entered" );
QgsDebugMsg( QString( "extent:\n%1" ).arg( extent.toString() ) );
QgsDebugMsg( QString( "width = %1 height = %1" ).arg( width ).arg( height ) );
if ( !mInput ) return 0;

if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
@@ -130,9 +130,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
/** get source extent */
QgsRectangle srcExtent() { return mSrcExtent; }

/** set source extent */
void setSrcExtent( const QgsRectangle theExtent ) { mSrcExtent = theExtent; }

/** get/set source width/height */
int srcRows() { return mSrcRows; }
int srcCols() { return mSrcCols; }
@@ -154,7 +151,7 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
/** Destination CRS */
QgsCoordinateReferenceSystem mDestCRS;

/** Coordinate transform */
/** Reverse coordinate transform (from destination to source) */
QgsCoordinateTransform mCoordinateTransform;

/** Destination extent */
@@ -829,30 +829,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
// procedure to use :
//

double maxSrcXRes = 0;
double maxSrcYRes = 0;

if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution )
{
maxSrcXRes = mDataProvider->extent().width() / mDataProvider->xSize();
maxSrcYRes = mDataProvider->extent().height() / mDataProvider->ySize();
}
/*
if ( mRenderer )
{
//QgsRasterDrawer drawer( mRenderer );
//QgsRasterDrawer drawer( mResampleFilter );
QgsRasterProjector projector( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS, maxSrcXRes, maxSrcYRes, mDataProvider->extent() );
projector.setInput( mResampleFilter );
QgsRasterDrawer drawer( &projector );
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
}
*/

QgsRasterProjector *projector = mPipe.projector();
// TODO: add in init?
if ( !projector )
@@ -866,8 +842,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
if ( projector )
{
projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS );
projector->setMaxSrcRes( maxSrcXRes, maxSrcYRes );
projector->setSrcExtent( mDataProvider->extent() );
}

// Drawer to pipe?
@@ -68,7 +68,7 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
{
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() );
// Do not oversample if data source does not have fixed resolution (WMS)
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::Size ) )
if ( provider && ( provider->capabilities() & QgsRasterDataProvider::ExactResolution ) )
{
double xRes = extent.width() / width;
double providerXRes = provider->extent().width() / provider->xSize();
@@ -92,7 +92,6 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext

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


int resWidth = width * oversamplingX;
int resHeight = height * oversamplingY;

0 comments on commit 4d68a69

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