Skip to content

Commit

Permalink
Added progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 29, 2015
1 parent d6d2f1a commit 515de28
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
21 changes: 21 additions & 0 deletions python/analysis/raster/qgsalignraster.sip
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ class QgsAlignRaster
};
typedef QList<QgsAlignRaster::Item> List;

//! Helper struct to be sub-classed for progress reporting
struct ProgressHandler
{
//! Method to be overridden for progress reporting.
//! @param complete Overall progress of the alignment operation
//! @return false if the execution should be cancelled, true otherwise
virtual bool progress( double complete ) = 0;

virtual ~ProgressHandler();
};

//! Assign a progress handler instance. Does not take ownership. NULL can be passed.
void setProgressHandler( ProgressHandler* progressHandler );
//! Get associated progress handler. May be NULL (default)
ProgressHandler* progressHandler() const;

//! Set list of rasters that will be aligned
void setRasters( const List& list );
//! Get list of rasters that will be aligned
Expand All @@ -88,6 +104,11 @@ class QgsAlignRaster
//! Get output cell size
QSizeF cellSize() const;

//! Set the output CRS in WKT format
void setDestinationCRS( const QString& crsWkt );
//! Get the output CRS in WKT format
QString destinationCRS() const;

// TODO: first need to run determineTransformAndSize() before this
//QSize rasterSize() const { return QSize(mXSize, mYSize); }
// TODO: add method for access to final extent
Expand Down
15 changes: 8 additions & 7 deletions src/analysis/raster/qgsalignraster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ static QgsRectangle transform_to_extent( const double* geotransform, double xSiz

static int CPL_STDCALL _progress( double dfComplete, const char* pszMessage, void* pProgressArg )
{
QgsAlignRaster* align = ( QgsAlignRaster* ) pProgressArg;
Q_UNUSED( align );
Q_UNUSED( pszMessage );

// TODO: report the progress somehow
qDebug( "progress %f", dfComplete * 100 );
return 1; // 1 = all is well, 0 = user terminated
QgsAlignRaster::ProgressHandler* handler = (( QgsAlignRaster* ) pProgressArg )->progressHandler();
if ( handler )
return handler->progress( dfComplete );
else
return true;
}


Expand Down Expand Up @@ -110,6 +110,7 @@ static CPLErr rescalePostWarpChunkProcessor( void* pKern, void* pArg )


QgsAlignRaster::QgsAlignRaster()
: mProgressHandler( 0 )
{
mCellSizeX = mCellSizeY = 0;
mGridOffsetX = mGridOffsetY = 0;
Expand All @@ -126,7 +127,7 @@ void QgsAlignRaster::setClipExtent( double xmin, double ymin, double xmax, doubl
mClipExtent[3] = ymax;
}

void QgsAlignRaster::setClipExtent(const QgsRectangle& extent)
void QgsAlignRaster::setClipExtent( const QgsRectangle& extent )
{
setClipExtent( extent.xMinimum(), extent.yMinimum(),
extent.xMaximum(), extent.yMaximum() );
Expand Down Expand Up @@ -332,7 +333,7 @@ bool QgsAlignRaster::createAndWarp( const Item& raster )
psWarpOptions->eResampleAlg = ( GDALResampleAlg ) raster.resampleMethod;

// our progress function
psWarpOptions->pfnProgress = _progress; //GDALTermProgress;
psWarpOptions->pfnProgress = _progress;
psWarpOptions->pProgressArg = this;

// Establish reprojection transformer.
Expand Down
24 changes: 24 additions & 0 deletions src/analysis/raster/qgsalignraster.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ class ANALYSIS_EXPORT QgsAlignRaster
};
typedef QList<Item> List;

//! Helper struct to be sub-classed for progress reporting
struct ProgressHandler
{
//! Method to be overridden for progress reporting.
//! @param complete Overall progress of the alignment operation
//! @return false if the execution should be cancelled, true otherwise
virtual bool progress( double complete ) = 0;

virtual ~ProgressHandler() {}
};

//! Assign a progress handler instance. Does not take ownership. NULL can be passed.
void setProgressHandler( ProgressHandler* progressHandler ) { mProgressHandler = progressHandler; }
//! Get associated progress handler. May be NULL (default)
ProgressHandler* progressHandler() const { return mProgressHandler; }

//! Set list of rasters that will be aligned
void setRasters( const List& list ) { mRasters = list; }
//! Get list of rasters that will be aligned
Expand All @@ -134,6 +150,11 @@ class ANALYSIS_EXPORT QgsAlignRaster
//! Get output cell size
QSizeF cellSize() const { return QSizeF( mCellSizeX, mCellSizeY ); }

//! Set the output CRS in WKT format
void setDestinationCRS( const QString& crsWkt ) { mCrsWkt = crsWkt.toAscii(); }
//! Get the output CRS in WKT format
QString destinationCRS() const { return mCrsWkt; }

// TODO: first need to run determineTransformAndSize() before this
//QSize rasterSize() const { return QSize(mXSize, mYSize); }
// TODO: add method for access to final extent
Expand Down Expand Up @@ -172,6 +193,9 @@ class ANALYSIS_EXPORT QgsAlignRaster

// set by the client

//! Object that facilitates reporting of progress / cancellation
ProgressHandler* mProgressHandler;

//! List of rasters to be aligned (with their output files and other options)
List mRasters;

Expand Down

0 comments on commit 515de28

Please sign in to comment.