QGIS API Documentation 3.99.0-Master (752b475928d)
Loading...
Searching...
No Matches
qgsidwinterpolator.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsidwinterpolator.cpp
3 ----------------------
4 begin : Marco 10, 2008
5 copyright : (C) 2008 by Marco Hugentobler
6 email : marco dot hugentobler at karto dot baug dot ethz dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsidwinterpolator.h"
19
20#include <cmath>
21#include <limits>
22
23#include "qgis.h"
25
29
30int QgsIDWInterpolator::interpolatePoint( double x, double y, double &result, QgsFeedback *feedback )
31{
32 if ( !mDataIsCached )
33 {
34 cacheBaseData( feedback );
35 }
36
37 double sumCounter = 0;
38 double sumDenominator = 0;
39
40 for ( const QgsInterpolatorVertexData &vertex : std::as_const( mCachedBaseData ) )
41 {
42 double distance = QgsGeometryUtilsBase::distance2D( vertex.x, vertex.y, x, y );
43 if ( qgsDoubleNear( distance, 0.0 ) )
44 {
45 result = vertex.z;
46 return 0;
47 }
48 double currentWeight = 1 / ( std::pow( distance, mDistanceCoefficient ) );
49 sumCounter += ( currentWeight * vertex.z );
50 sumDenominator += currentWeight;
51 }
52
53 if ( sumDenominator == 0.0 )
54 {
55 return 1;
56 }
57
58 result = sumCounter / sumDenominator;
59 return 0;
60}
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
static double distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
int interpolatePoint(double x, double y, double &result, QgsFeedback *feedback=nullptr) override
Calculates interpolation value for map coordinates x, y.
QgsIDWInterpolator(const QList< QgsInterpolator::LayerData > &layerData)
Constructor for QgsIDWInterpolator, with the specified layerData sources.
QVector< QgsInterpolatorVertexData > mCachedBaseData
Cached vertex data for input sources.
QgsInterpolator(const QList< QgsInterpolator::LayerData > &layerData)
bool mDataIsCached
Flag that tells if the cache already has been filled.
QList< LayerData > layerData() const
Result cacheBaseData(QgsFeedback *feedback=nullptr)
Caches the vertex and value data from the provider.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607
Interpolation data for an individual source vertex.