QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
interpolation
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
"
24
#include "
qgsgeometryutils_base.h
"
25
26
QgsIDWInterpolator::QgsIDWInterpolator
(
const
QList<LayerData> &
layerData
)
27
:
QgsInterpolator
(
layerData
)
28
{}
29
30
int
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
}
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition
qgsfeedback.h:44
QgsGeometryUtilsBase::distance2D
static double distance2D(double x1, double y1, double x2, double y2)
Returns the 2D distance between (x1, y1) and (x2, y2).
Definition
qgsgeometryutils_base.h:64
QgsIDWInterpolator::interpolatePoint
int interpolatePoint(double x, double y, double &result, QgsFeedback *feedback=nullptr) override
Calculates interpolation value for map coordinates x, y.
Definition
qgsidwinterpolator.cpp:30
QgsIDWInterpolator::QgsIDWInterpolator
QgsIDWInterpolator(const QList< QgsInterpolator::LayerData > &layerData)
Constructor for QgsIDWInterpolator, with the specified layerData sources.
Definition
qgsidwinterpolator.cpp:26
QgsInterpolator::mCachedBaseData
QVector< QgsInterpolatorVertexData > mCachedBaseData
Cached vertex data for input sources.
Definition
qgsinterpolator.h:134
QgsInterpolator::QgsInterpolator
QgsInterpolator(const QList< QgsInterpolator::LayerData > &layerData)
Definition
qgsinterpolator.cpp:27
QgsInterpolator::mDataIsCached
bool mDataIsCached
Flag that tells if the cache already has been filled.
Definition
qgsinterpolator.h:137
QgsInterpolator::layerData
QList< LayerData > layerData() const
Definition
qgsinterpolator.h:119
QgsInterpolator::cacheBaseData
Result cacheBaseData(QgsFeedback *feedback=nullptr)
Caches the vertex and value data from the provider.
Definition
qgsinterpolator.cpp:31
qgis.h
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition
qgis.h:7771
qgsgeometryutils_base.h
qgsidwinterpolator.h
QgsInterpolatorVertexData
Interpolation data for an individual source vertex.
Definition
qgsinterpolator.h:43
Generated on
for QGIS API Documentation by
1.17.0