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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* * * *
***************************************************************************/ ***************************************************************************/


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


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


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


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


void QgsRasterProjector::calc() void QgsRasterProjector::calc()
{ {
QgsDebugMsg( "Entered" ); QgsDebugMsg( "Entered" );
mCPMatrix.clear(); mCPMatrix.clear();
delete pHelperTop; delete[] pHelperTop;
pHelperTop = 0; pHelperTop = 0;
delete pHelperBottom; delete[] pHelperBottom;
pHelperBottom = 0; 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 ); mDestXRes = mDestExtent.width() / ( mDestCols );
mDestYRes = mDestExtent.height() / ( mDestRows ); mDestYRes = mDestExtent.height() / ( mDestRows );


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

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


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


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


void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent, int width, int height ) 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 ( !mInput ) return 0;


if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS ) if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
Expand Down
5 changes: 1 addition & 4 deletions src/core/qgsrasterprojector.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
/** get source extent */ /** get source extent */
QgsRectangle srcExtent() { return mSrcExtent; } QgsRectangle srcExtent() { return mSrcExtent; }


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

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


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


/** Destination extent */ /** Destination extent */
Expand Down
26 changes: 0 additions & 26 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -829,30 +829,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
// procedure to use : // 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(); QgsRasterProjector *projector = mPipe.projector();
// TODO: add in init? // TODO: add in init?
if ( !projector ) if ( !projector )
Expand All @@ -866,8 +842,6 @@ void QgsRasterLayer::draw( QPainter * theQPainter,
if ( projector ) if ( projector )
{ {
projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS ); projector->setCRS( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS );
projector->setMaxSrcRes( maxSrcXRes, maxSrcYRes );
projector->setSrcExtent( mDataProvider->extent() );
} }


// Drawer to pipe? // Drawer to pipe?
Expand Down
3 changes: 1 addition & 2 deletions src/core/raster/qgsrasterresamplefilter.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
{ {
QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() ); QgsRasterDataProvider *provider = dynamic_cast<QgsRasterDataProvider*>( mInput->srcInput() );
// Do not oversample if data source does not have fixed resolution (WMS) // 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 xRes = extent.width() / width;
double providerXRes = provider->extent().width() / provider->xSize(); 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 // TODO: we must also increase the extent to get correct result on borders of parts



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


Expand Down

0 comments on commit 4d68a69

Please sign in to comment.