Skip to content

Commit

Permalink
raster projector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent e30cd19 commit 4d68a69
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 42 deletions.
33 changes: 23 additions & 10 deletions src/core/qgsrasterprojector.cpp
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/

#include "qgsrasterdataprovider.h"
#include "qgslogger.h"
#include "qgsrasterprojector.h"
#include "qgscoordinatetransform.h"
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 1 addition & 4 deletions src/core/qgsrasterprojector.h
Expand Up @@ -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; }
Expand All @@ -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 */
Expand Down
26 changes: 0 additions & 26 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -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 )
Expand All @@ -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?
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -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();
Expand All @@ -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;

Expand Down

0 comments on commit 4d68a69

Please sign in to comment.