Skip to content
Permalink
Browse files

Pass QgsFeedback to methods in interpolation for more responsive

cancelation and progress reports
  • Loading branch information
nyalldawson committed Nov 2, 2017
1 parent 151fb08 commit 60e98be8d3c77e6845a4c9ef4befeb895da0ce22
@@ -60,7 +60,7 @@ int QgsGridFileWriter::writeFile( QgsFeedback *feedback )
currentXValue = mInterpolationExtent.xMinimum() + mCellSizeX / 2.0; //calculate value in the center of the cell
for ( int j = 0; j < mNumColumns; ++j )
{
if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue ) == 0 )
if ( mInterpolator->interpolatePoint( currentXValue, currentYValue, interpolatedValue, feedback ) == 0 )
{
outStream << interpolatedValue << ' ';
}
@@ -31,11 +31,11 @@ QgsIDWInterpolator::QgsIDWInterpolator()

}

int QgsIDWInterpolator::interpolatePoint( double x, double y, double &result )
int QgsIDWInterpolator::interpolatePoint( double x, double y, double &result, QgsFeedback *feedback )
{
if ( !mDataIsCached )
{
cacheBaseData();
cacheBaseData( feedback );
}

double currentWeight;
@@ -30,6 +30,8 @@ class ANALYSIS_EXPORT QgsIDWInterpolator: public QgsInterpolator
public:
QgsIDWInterpolator( const QList<QgsInterpolator::LayerData> &layerData );

int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = nullptr ) override;

/**
* Calculates interpolation value for map coordinates x, y
\param x x-coordinate (in map units)
@@ -20,15 +20,15 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsgeometry.h"
#include "qgswkbptr.h"
#include "qgsfeedback.h"

QgsInterpolator::QgsInterpolator( const QList<LayerData> &layerData )
: mLayerData( layerData )
{

}

int QgsInterpolator::cacheBaseData()
QgsInterpolator::Result QgsInterpolator::cacheBaseData( QgsFeedback *feedback )
{
if ( mLayerData.empty() )
{
@@ -41,10 +41,8 @@ int QgsInterpolator::cacheBaseData()

Q_FOREACH ( const LayerData &layer, mLayerData )
{
if ( !layer.vectorLayer )
{
continue;
}
if ( feedback && feedback->isCanceled() )
return Canceled;

QgsVectorLayer *vlayer = layer.vectorLayer;
if ( !vlayer )
@@ -61,12 +59,21 @@ int QgsInterpolator::cacheBaseData()

double attributeValue = 0.0;
bool attributeConversionOk = false;
double progress = layerCount * layerStep;

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( attList ) );
double featureStep = source->featureCount() > 0 ? layerStep / source->featureCount() : layerStep;

QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
if ( feedback && feedback->isCanceled() )
return Canceled;

progress += featureStep;
if ( feedback )
feedback->setProgress( progress );

if ( !layer.zCoordInterpolation )
{
QVariant attributeVariant = feature.attribute( layer.interpolationAttribute );
@@ -24,6 +24,7 @@

class QgsVectorLayer;
class QgsGeometry;
class QgsFeedback;

struct ANALYSIS_EXPORT vertexData
{
@@ -63,11 +64,12 @@ class ANALYSIS_EXPORT QgsInterpolator

/**
* Calculates interpolation value for map coordinates x, y
\param x x-coordinate (in map units)
\param y y-coordinate (in map units)
\param result out: interpolation result
\returns 0 in case of success*/
virtual int interpolatePoint( double x, double y, double &result ) = 0;
* \param x x-coordinate (in map units)
* \param y y-coordinate (in map units)
* \param result out: interpolation result
* \param feedback optional feedback object for progress and cancelation support
* \returns 0 in case of success*/
virtual int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = nullptr ) = 0;

//! \note not available in Python bindings
QList<LayerData> layerData() const { return mLayerData; } SIP_SKIP
@@ -43,7 +43,7 @@ QgsTINInterpolator::~QgsTINInterpolator()
delete mTriangleInterpolator;
}

int QgsTINInterpolator::interpolatePoint( double x, double y, double &result )
int QgsTINInterpolator::interpolatePoint( double x, double y, double &result, QgsFeedback * )
{
if ( !mIsInitialized )
{
@@ -50,13 +50,7 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = nullptr );
~QgsTINInterpolator();

/**
* Calculates interpolation value for map coordinates x, y
\param x x-coordinate (in map units)
\param y y-coordinate (in map units)
\param result out: interpolation result
\returns 0 in case of success*/
int interpolatePoint( double x, double y, double &result ) override;
int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback ) override;

/**
* Returns the fields output by features when saving the triangulation.

0 comments on commit 60e98be

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