Skip to content
Permalink
Browse files

raster cleanup

  • Loading branch information
blazek committed Apr 29, 2013
1 parent e755815 commit 33d13ccca7a120a62a20a1e2b822d1541a638fc3
@@ -4,16 +4,6 @@ class QgsRasterIterator
#include <qgsrasteriterator.h>
%End
public:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterBlock *block;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterIterator( QgsRasterInterface* input );
~QgsRasterIterator();
@@ -21,10 +21,10 @@ class QgsRasterNuller : QgsRasterInterface

QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /;

void setNoData( QList<QgsRasterNuller::NoData> noData );
void setNoData( int bandNo, QgsRasterRangeList noData );

QList<QgsRasterNuller::NoData> noData() const;
QgsRasterRangeList noData( int bandNo ) const;

/** \brief Set output no data value. */
void setOutputNoData( double noData );
void setOutputNoDataValue( int bandNo, double noData );
};
@@ -50,21 +50,6 @@ class QgsRasterProjector : QgsRasterInterface
/** \brief set maximum source resolution */
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes );

/** get source extent */
QgsRectangle srcExtent();

/** get/set source width/height */
int srcRows();
int srcCols();
void setSrcRows( int theRows );
void setSrcCols( int theCols );

/** \brief Get source row and column indexes for current source extent and resolution */
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

int dstRows() const;
int dstCols() const;

QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) / Factory /;
};

@@ -4,28 +4,27 @@ struct QgsRasterViewPort
%TypeHeaderCode
#include <qgsrasterviewport.h>
%End
/** \brief Coordinate (in output device coordinate system) of top left corner
* of the part of the raster that is to be rendered.*/
QgsPoint mTopLeftPoint;
/** \brief Coordinate (in output device coordinate system) of bottom right corner
* of the part of the raster that is to be rendered.*/
QgsPoint mBottomRightPoint;

// NOT IN MAP SPACE BUT DEVICE SPACE
/** \brief Coordinate (in geographic coordinate system) of top left corner of the part of the raster that
* is to be rendered.*/
QgsPoint topLeftPoint;
/** \brief Coordinate (in geographic coordinate system) of bottom right corner of the part of the raster that
* is to be rendered.*/
QgsPoint bottomRightPoint;
/** \brief Distance in map units from left edge to right edge for the part of the raster that
* is to be rendered.*/
/** \brief Width, number of columns to be rendered */
int mWidth;
/** \brief Distance in map units from bottom edge to top edge for the part of
* the raster that is to be rendered.*/
/** \brief Height, number of rows to be rendered */
int mHeight;

int drawableAreaXDim;
/** \brief Distance in map units from bottom edge to top edge for the part of the raster that
* is to be rendered.*/
int drawableAreaYDim;

// intersection of current map extent and layer extent
/** \brief Intersection of current map extent and layer extent */
QgsRectangle mDrawnExtent;

// Source coordinate system
/** \brief Source coordinate system */
QgsCoordinateReferenceSystem mSrcCRS;

// Target coordinate system
/** \brief Target coordinate system */
QgsCoordinateReferenceSystem mDestCRS;

};
@@ -46,7 +46,7 @@ class QgsRasterLayerSaveAsDialog : QDialog
QgsCoordinateReferenceSystem outputCrs();
QStringList createOptions() const;
QgsRectangle outputRectangle() const;
QList<QgsRasterNuller::NoData> noData() const;
QgsRasterRangeList noData() const;

QList< int > pyramidsList() const;
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const;
@@ -4295,7 +4295,10 @@ void QgisApp::saveAsRasterFile()
}

QgsRasterNuller *nuller = new QgsRasterNuller();
nuller->setNoData( d.noData() );
for ( int band = 1; band <= rasterLayer->dataProvider()->bandCount(); band ++ )
{
nuller->setNoData( band, d.noData() );
}
if ( !pipe->insert( 1, nuller ) )
{
QgsDebugMsg( "Cannot set pipe nuller" );
@@ -360,7 +360,7 @@ bool QgsRasterBlock::setValue( int row, int column, double value )

bool QgsRasterBlock::setColor( int row, int column, QRgb color )
{
return setColor(( size_t )row*column, color );
return setColor(( size_t )row*mWidth + column, color );
}

bool QgsRasterBlock::setColor( size_t index, QRgb color )
@@ -385,7 +385,7 @@ bool QgsRasterBlock::setColor( size_t index, QRgb color )

bool QgsRasterBlock::setIsNoData( int row, int column )
{
return setIsNoData(( size_t )row*column );
return setIsNoData(( size_t )row*mWidth + column );
}

bool QgsRasterBlock::setIsNoData( size_t index )
@@ -41,7 +41,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM

// last pipe filter has only 1 band
int bandNumber = 1;
mIterator->startRasterRead( bandNumber, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, viewPort->mDrawnExtent );
mIterator->startRasterRead( bandNumber, viewPort->mWidth, viewPort->mHeight, viewPort->mDrawnExtent );

//number of cols/rows in output pixels
int nCols = 0;
@@ -89,7 +89,7 @@ void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const
}

//top left position in device coords
QPoint tlPoint = QPoint( viewPort->topLeftPoint.x() + topLeftCol, viewPort->topLeftPoint.y() + topLeftRow );
QPoint tlPoint = QPoint( viewPort->mTopLeftPoint.x() + topLeftCol, viewPort->mTopLeftPoint.y() + topLeftRow );
p->save();
p->setRenderHint( QPainter::Antialiasing, false );
p->drawImage( tlPoint, img );
@@ -189,10 +189,10 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
destNoDataValue = srcProvider->srcNoDataValue( bandNo );
destHasNoDataValue = true;
}
else if ( nuller && nuller->noData().size() > 0 )
else if ( nuller && nuller->noData( bandNo ).size() > 0 )
{
// Use one user defined no data value
destNoDataValue = nuller->noData().value( 0 ).min;
destNoDataValue = nuller->noData( bandNo ).value( 0 ).min();
destHasNoDataValue = true;
}
else
@@ -232,7 +232,9 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
}

if ( nuller && destHasNoDataValue )
nuller->setOutputNoData( destNoDataValue );
{
nuller->setOutputNoDataValue( bandNo, destNoDataValue );
}

QgsDebugMsg( QString( "bandNo = %1 destDataType = %2 destHasNoDataValue = %3 destNoDataValue = %4" ).arg( bandNo ).arg( destDataType ).arg( destHasNoDataValue ).arg( destNoDataValue ) );
destDataTypeList.append( destDataType );
@@ -44,14 +44,12 @@ void QgsRasterIterator::startRasterRead( int bandNumber, int nCols, int nRows, c
pInfo.nRows = nRows;
pInfo.currentCol = 0;
pInfo.currentRow = 0;
pInfo.block = 0;
pInfo.prj = 0;
mRasterPartInfos.insert( bandNumber, pInfo );
}

bool QgsRasterIterator::readNextRasterPart( int bandNumber,
int& nCols, int& nRows,
//void** rasterData,
QgsRasterBlock **block,
int& topLeftCol, int& topLeftRow )
{
@@ -73,9 +71,6 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
}

//remove last data block
// TODO: block is released somewhere else (check)
//delete pInfo.block;
pInfo.block = 0;
delete pInfo.prj;
pInfo.prj = 0;

@@ -98,9 +93,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
QgsRectangle blockRect( xmin, ymin, xmax, ymax );

pInfo.block = mInput->block( bandNumber, blockRect, nCols, nRows );

*block = pInfo.block;
*block = mInput->block( bandNumber, blockRect, nCols, nRows );
topLeftCol = pInfo.currentCol;
topLeftRow = pInfo.currentRow;

@@ -129,7 +122,6 @@ void QgsRasterIterator::removePartInfo( int bandNumber )
if ( partIt != mRasterPartInfos.end() )
{
RasterPartInfo& pInfo = partIt.value();
delete pInfo.block;
delete pInfo.prj;
mRasterPartInfos.remove( bandNumber );
}
@@ -30,16 +30,6 @@ struct QgsRasterViewPort;
class CORE_EXPORT QgsRasterIterator
{
public:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterBlock *block;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterIterator( QgsRasterInterface* input );
~QgsRasterIterator();
@@ -52,7 +42,8 @@ class CORE_EXPORT QgsRasterIterator
*/
void startRasterRead( int bandNumber, int nCols, int nRows, const QgsRectangle& extent );

/**Fetches next part of raster data
/**Fetches next part of raster data, caller takes ownership of the block and
caller should delete the block.
@param bandNumber band to read
@param nCols number of columns on output device
@param nRows number of rows on output device
@@ -76,6 +67,16 @@ class CORE_EXPORT QgsRasterIterator
int maximumTileHeight() const { return mMaximumTileHeight; }

private:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterInterface* mInput;
QMap<int, RasterPartInfo> mRasterPartInfos;
QgsRectangle mExtent;
@@ -367,8 +367,8 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
}

// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
myRasterViewPort->topLeftPoint = theQgsMapToPixel.transform( myRasterExtent.xMinimum(), myRasterExtent.yMaximum() );
myRasterViewPort->bottomRightPoint = theQgsMapToPixel.transform( myRasterExtent.xMaximum(), myRasterExtent.yMinimum() );
myRasterViewPort->mTopLeftPoint = theQgsMapToPixel.transform( myRasterExtent.xMinimum(), myRasterExtent.yMaximum() );
myRasterViewPort->mBottomRightPoint = theQgsMapToPixel.transform( myRasterExtent.xMaximum(), myRasterExtent.yMinimum() );

// align to output device grid, i.e. floor/ceil to integers
// TODO: this should only be done if paint device is raster - screen, image
@@ -378,22 +378,22 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
// the provider anyway
if ( true )
{
myRasterViewPort->topLeftPoint.setX( floor( myRasterViewPort->topLeftPoint.x() ) );
myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() ) );
myRasterViewPort->mTopLeftPoint.setX( floor( myRasterViewPort->mTopLeftPoint.x() ) );
myRasterViewPort->mTopLeftPoint.setY( floor( myRasterViewPort->mTopLeftPoint.y() ) );
myRasterViewPort->mBottomRightPoint.setX( ceil( myRasterViewPort->mBottomRightPoint.x() ) );
myRasterViewPort->mBottomRightPoint.setY( ceil( myRasterViewPort->mBottomRightPoint.y() ) );
// recalc myRasterExtent to aligned values
myRasterExtent.set(
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->topLeftPoint.x(),
myRasterViewPort->bottomRightPoint.y() ),
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->bottomRightPoint.x(),
myRasterViewPort->topLeftPoint.y() )
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mTopLeftPoint.x(),
myRasterViewPort->mBottomRightPoint.y() ),
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mBottomRightPoint.x(),
myRasterViewPort->mTopLeftPoint.y() )
);

}

myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->mWidth = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->mHeight = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );

//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
@@ -407,20 +407,19 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
QgsDebugMsgLevel( QString( "myRasterExtent.yMinimum() = %1" ).arg( myRasterExtent.yMinimum() ), 3 );
QgsDebugMsgLevel( QString( "myRasterExtent.yMaximum() = %1" ).arg( myRasterExtent.yMaximum() ), 3 );

QgsDebugMsgLevel( QString( "topLeftPoint.x() = %1" ).arg( myRasterViewPort->topLeftPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "bottomRightPoint.x() = %1" ).arg( myRasterViewPort->bottomRightPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "topLeftPoint.y() = %1" ).arg( myRasterViewPort->topLeftPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "bottomRightPoint.y() = %1" ).arg( myRasterViewPort->bottomRightPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "mTopLeftPoint.x() = %1" ).arg( myRasterViewPort->mTopLeftPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "mBottomRightPoint.x() = %1" ).arg( myRasterViewPort->mBottomRightPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "mTopLeftPoint.y() = %1" ).arg( myRasterViewPort->mTopLeftPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "mBottomRightPoint.y() = %1" ).arg( myRasterViewPort->mBottomRightPoint.y() ), 3 );

QgsDebugMsgLevel( QString( "drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
QgsDebugMsgLevel( QString( "drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( myRasterViewPort->mWidth ), 3 );
QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( myRasterViewPort->mHeight ), 3 );

// /\/\/\ - added to handle zoomed-in rasters

mLastViewPort = *myRasterViewPort;

// Provider mode: See if a provider key is specified, and if so use the provider instead

// TODO: is it necessary? Probably WMS only?
mDataProvider->setDpi( rendererContext.rasterScaleFactor() * 25.4 * rendererContext.scaleFactor() );

draw( theQPainter, myRasterViewPort, &theQgsMapToPixel );
@@ -785,8 +784,8 @@ void QgsRasterLayer::init()
setDrawingStyle( QgsRasterLayer::UndefinedDrawingStyle );

//Initialize the last view port structure, should really be a class
mLastViewPort.drawableAreaXDim = 0;
mLastViewPort.drawableAreaYDim = 0;
mLastViewPort.mWidth = 0;
mLastViewPort.mHeight = 0;
}

void QgsRasterLayer::setDataProvider( QString const & provider )
@@ -1266,10 +1265,10 @@ QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor )
double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
double myPixelHeight = myExtent.height() / myMapUnitsPerPixel;

myRasterViewPort->topLeftPoint = QgsPoint( myX, myY );
myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
myRasterViewPort->drawableAreaXDim = myQPixmap.width();
myRasterViewPort->drawableAreaYDim = myQPixmap.height();
myRasterViewPort->mTopLeftPoint = QgsPoint( myX, myY );
myRasterViewPort->mBottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
myRasterViewPort->mWidth = myQPixmap.width();
myRasterViewPort->mHeight = myQPixmap.height();

myRasterViewPort->mDrawnExtent = myExtent;
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid

0 comments on commit 33d13cc

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