[QGIS Commit] r15533 - trunk/qgis/src/core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Mar 18 16:37:07 EDT 2011
Author: rblazek
Date: 2011-03-18 13:37:07 -0700 (Fri, 18 Mar 2011)
New Revision: 15533
Modified:
trunk/qgis/src/core/qgsrasterdataprovider.cpp
trunk/qgis/src/core/qgsrasterprojector.cpp
trunk/qgis/src/core/qgsrasterprojector.h
Log:
align extent according to src resolution/origin
Modified: trunk/qgis/src/core/qgsrasterdataprovider.cpp
===================================================================
--- trunk/qgis/src/core/qgsrasterdataprovider.cpp 2011-03-18 15:22:22 UTC (rev 15532)
+++ trunk/qgis/src/core/qgsrasterdataprovider.cpp 2011-03-18 20:37:07 UTC (rev 15533)
@@ -47,7 +47,7 @@
mMaxSrcYRes = extent().height() / ySize();
}
- QgsRasterProjector myProjector( theSrcCRS, theDestCRS, viewExtent, height, width, mMaxSrcXRes, mMaxSrcYRes );
+ QgsRasterProjector myProjector( theSrcCRS, theDestCRS, viewExtent, height, width, mMaxSrcXRes, mMaxSrcYRes, mExtent );
QgsDebugMsg( QString( "create projector time (ms): %1" ).arg( time.elapsed() ) );
@@ -182,10 +182,10 @@
QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
{
- int type = dataType(theBandNo);
- int size = dataTypeSize(theBandNo) / 8;
+ int type = dataType( theBandNo );
+ int size = dataTypeSize( theBandNo ) / 8;
QByteArray ba;
- ba.resize(size);
+ ba.resize( size );
char * data = ba.data();
double noval = mNoDataValue[theBandNo-1];
unsigned char uc;
@@ -195,35 +195,35 @@
int i;
float f;
double d;
- switch (type)
+ switch ( type )
{
case QgsRasterDataProvider::Byte:
- uc = (unsigned char)noval;
- memcpy ( data, &uc, size);
+ uc = ( unsigned char )noval;
+ memcpy( data, &uc, size );
break;
case QgsRasterDataProvider::UInt16:
- us = (unsigned short)noval;
- memcpy ( data, &us, size);
+ us = ( unsigned short )noval;
+ memcpy( data, &us, size );
break;
case QgsRasterDataProvider::Int16:
- s = (short)noval;
- memcpy ( data, &s, size);
+ s = ( short )noval;
+ memcpy( data, &s, size );
break;
case QgsRasterDataProvider::UInt32:
- ui = (unsigned int)noval;
- memcpy ( data, &ui, size);
+ ui = ( unsigned int )noval;
+ memcpy( data, &ui, size );
break;
case QgsRasterDataProvider::Int32:
- i = (int)noval;
- memcpy ( data, &i, size);
+ i = ( int )noval;
+ memcpy( data, &i, size );
break;
case QgsRasterDataProvider::Float32:
- f = (float)noval;
- memcpy ( data, &f, size);
+ f = ( float )noval;
+ memcpy( data, &f, size );
break;
case QgsRasterDataProvider::Float64:
- d = (double)noval;
- memcpy ( data, &d, size);
+ d = ( double )noval;
+ memcpy( data, &d, size );
break;
default:
QgsLogger::warning( "GDAL data type is not supported" );
Modified: trunk/qgis/src/core/qgsrasterprojector.cpp
===================================================================
--- trunk/qgis/src/core/qgsrasterprojector.cpp 2011-03-18 15:22:22 UTC (rev 15532)
+++ trunk/qgis/src/core/qgsrasterprojector.cpp 2011-03-18 20:37:07 UTC (rev 15533)
@@ -27,12 +27,14 @@
QgsCoordinateReferenceSystem theDestCRS,
QgsRectangle theDestExtent,
int theDestRows, int theDestCols,
- double theMaxSrcXRes, double theMaxSrcYRes )
+ double theMaxSrcXRes, double theMaxSrcYRes,
+ QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mDestExtent( theDestExtent )
, mDestRows( theDestRows ), mDestCols( theDestCols )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
+ , mExtent( theExtent )
{
QgsDebugMsg( "Entered" );
QgsDebugMsg( "theDestExtent = " + theDestExtent.toString() );
@@ -135,9 +137,39 @@
myPoint = mCPMatrix[mCPRows-1][i];
mSrcExtent.combineExtentWith( myPoint.x(), myPoint.y() );
}
- // Expand a bit to avoid possible approx coords falling out because of representation error
+ // Expand a bit to avoid possible approx coords falling out because of representation error?
+ // If mMaxSrcXRes, mMaxSrcYRes are defined (fixed src resolution)
+ // align extent to src resolution to avoid jumping reprojected pixels
+ // because of shifting resampled grid
+ // Important especially if we are over mMaxSrcXRes, mMaxSrcYRes limits
+
QgsDebugMsg( "mSrcExtent = " + mSrcExtent.toString() );
+
+ if ( mMaxSrcXRes > 0 )
+ {
+ // with floor/ceil it should work correctly also for mSrcExtent.xMinimum() < mExtent.xMinimum()
+ double col = floor(( mSrcExtent.xMinimum() - mExtent.xMinimum() ) / mMaxSrcXRes );
+ double x = mExtent.xMinimum() + col * mMaxSrcXRes;
+ mSrcExtent.setXMinimum( x );
+
+ col = ceil(( mSrcExtent.xMaximum() - mExtent.xMinimum() ) / mMaxSrcXRes );
+ x = mExtent.xMinimum() + col * mMaxSrcXRes;
+ mSrcExtent.setXMaximum( x );
+ }
+ if ( mMaxSrcYRes > 0 )
+ {
+ double row = floor(( mExtent.yMaximum() - mSrcExtent.yMaximum() ) / mMaxSrcYRes );
+ double y = mExtent.yMaximum() - row * mMaxSrcYRes;
+ mSrcExtent.setYMaximum( y );
+
+ row = ceil(( mExtent.yMaximum() - mSrcExtent.yMinimum() ) / mMaxSrcYRes );
+ y = mExtent.yMaximum() - row * mMaxSrcYRes;
+ mSrcExtent.setYMinimum( y );
+ }
+
+
+ QgsDebugMsg( "mSrcExtent = " + mSrcExtent.toString() );
}
QString QgsRasterProjector::cpToString()
@@ -197,9 +229,11 @@
double myMinYSize = mMaxSrcYRes > myMinSize ? mMaxSrcYRes : myMinSize;
QgsDebugMsg( QString( "myMinXSize = %1 myMinYSize = %2" ).arg( myMinXSize ).arg( myMinYSize ) );
QgsDebugMsg( QString( "mSrcExtent.width = %1 mSrcExtent.height = %2" ).arg( mSrcExtent.width() ).arg( mSrcExtent.height() ) );
- mSrcRows = ( int ) ceil( mSrcExtent.height() / myMinYSize );
- mSrcCols = ( int ) ceil( mSrcExtent.width() / myMinXSize );
+ // we have to round to keep alignment set in calcSrcExtent
+ mSrcRows = ( int ) qRound( mSrcExtent.height() / myMinYSize );
+ mSrcCols = ( int ) qRound( mSrcExtent.width() / myMinXSize );
+
QgsDebugMsg( QString( "mSrcRows = %1 mSrcCols = %2" ).arg( mSrcRows ).arg( mSrcCols ) );
}
Modified: trunk/qgis/src/core/qgsrasterprojector.h
===================================================================
--- trunk/qgis/src/core/qgsrasterprojector.h 2011-03-18 15:22:22 UTC (rev 15532)
+++ trunk/qgis/src/core/qgsrasterprojector.h 2011-03-18 20:37:07 UTC (rev 15533)
@@ -51,7 +51,8 @@
QgsCoordinateReferenceSystem theDestCRS,
QgsRectangle theDestExtent,
int theDestRows, int theDestCols,
- double theMaxSrcXRes, double theMaxSrcYRes
+ double theMaxSrcXRes, double theMaxSrcYRes,
+ QgsRectangle theExtent
);
/** \brief The destructor */
@@ -136,6 +137,9 @@
/** Source extent */
QgsRectangle mSrcExtent;
+ /** Source raster extent */
+ QgsRectangle mExtent;
+
/** Number of destination rows */
int mDestRows;
More information about the QGIS-commit
mailing list