Skip to content

Commit 10c9bb6

Browse files
authored
Merge pull request #5512 from nyalldawson/interp
Cleanup and optimise interpolation code
2 parents 151fb08 + b36dd12 commit 10c9bb6

36 files changed

+969
-1588
lines changed

doc/api_break.dox

+13-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
195195
<tr><td>QgsSymbolV2SelectorDialog<td>QgsSymbolSelectorDialog
196196
<tr><td>QgsSymbolV2SelectorWidget<td>QgsSymbolSelectorWidget
197197
<tr><td>QgsTicksScaleBarStyle<td>QgsTicksScaleBarRenderer
198+
<tr><td>QgsTINInterpolator<td>QgsTinInterpolator
198199
<tr><td>QgsVectorColorBrewerColorRampV2<td>QgsColorBrewerColorRamp
199200
<tr><td>QgsVectorColorBrewerColorRampV2Dialog<td>QgsColorBrewerColorRampDialog
200201
<tr><td>QgsVectorColorBrewerColorRampV2DialogBase<td>QgsColorBrewerColorRampDialogBase
@@ -210,6 +211,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
210211
<tr><td>QgsVectorRandomColorRampV2<td>QgsLimitedRandomColorRamp
211212
<tr><td>QgsVectorRandomColorRampV2Dialog<td>QgsLimitedRandomColorRampDialog
212213
<tr><td>QgsVectorRandomColorRampV2DialogBase<td>QgsLimitedRandomColorRampDialogBase
214+
<tr><td>vertexData<td>QgsInterpolatorVertexData
213215
</table>
214216

215217
<table>
@@ -1484,6 +1486,16 @@ QgsIFeatureSelectionManager {#qgis_api_break_3_0_QgsIFeatureSelectionMana
14841486
- selectedFeaturesIds() has been renamed to selectedFeatureIds()
14851487

14861488

1489+
QgsInterpolator {#qgis_api_break_3_0_QgsInterpolator}
1490+
---------------
1491+
1492+
- The InputType enum was renamed to SourceType and the enum values were renamed.
1493+
- LayerData.vectorLayer was renamed to LayerData.source
1494+
- LayerData.zCoordInterpolation was renamed to LayerData.valueSource and now takes a QgsInterpolator.ValueSource enum value.
1495+
- LayerData.mInputType was renamed to LayerData.sourceType
1496+
1497+
1498+
14871499
QgsJSONExporter {#qgis_api_break_3_0_QgsJSONExporter}
14881500
---------------
14891501

@@ -2454,7 +2466,7 @@ QgsSymbolsListWidget {#qgis_api_break_3_0_QgsSymbolsListWidget}
24542466
- expressionContext(), setExpressionContext(), setMapCanvas() and mapCanvas() have been removed in favor of setContext()/context()
24552467

24562468

2457-
QgsTINInterpolator {#qgis_api_break_3_0_QgsTINInterpolator}
2469+
QgsTinInterpolator {#qgis_api_break_3_0_QgsTinInterpolator}
24582470
------------------
24592471

24602472
- The constructor takes a QgsFeedback argument instead of using a QProgressDialog.

python/analysis/interpolation/Line3D.sip

-75
This file was deleted.

python/analysis/interpolation/Node.sip

-52
This file was deleted.

python/analysis/interpolation/qgsidwinterpolator.sip

+29-8
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,46 @@
1111

1212
class QgsIDWInterpolator: QgsInterpolator
1313
{
14+
%Docstring
15+
Inverse distance weight interpolator.
16+
%End
1417

1518
%TypeHeaderCode
1619
#include "qgsidwinterpolator.h"
1720
%End
1821
public:
22+
1923
QgsIDWInterpolator( const QList<QgsInterpolator::LayerData> &layerData );
24+
%Docstring
25+
Constructor for QgsIDWInterpolator, with the specified ``layerData`` sources.
26+
%End
27+
28+
virtual int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = 0 );
2029

21-
virtual int interpolatePoint( double x, double y, double &result );
2230

31+
void setDistanceCoefficient( double coefficient );
2332
%Docstring
24-
Calculates interpolation value for map coordinates x, y
25-
\param x x-coordinate (in map units)
26-
\param y y-coordinate (in map units)
27-
\param result out: interpolation result
28-
:return: 0 in case of success*
29-
:rtype: int
33+
Sets the distance ``coefficient``, the parameter that sets how the values are
34+
weighted with distance. Smaller values mean sharper peaks at the data points.
35+
36+
Point values are weighted by 1 / ( distance ^ coefficient ).
37+
38+
.. seealso:: distanceCoefficient()
39+
.. versionadded:: 3.0
3040
%End
3141

32-
void setDistanceCoefficient( double p );
42+
double distanceCoefficient() const;
43+
%Docstring
44+
Returns the distance coefficient, the parameter that sets how the values are
45+
weighted with distance. Smaller values mean sharper peaks at the data points.
46+
The default is a coefficient of 2.
47+
48+
Point values are weighted by 1 / ( distance ^ coefficient ).
49+
50+
.. seealso:: setDistanceCoefficient()
51+
.. versionadded:: 3.0
52+
:rtype: float
53+
%End
3354

3455
};
3556

python/analysis/interpolation/qgsinterpolator.sip

+73-19
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,117 @@
1010

1111

1212

13-
struct vertexData
13+
struct QgsInterpolatorVertexData
1414
{
15+
16+
QgsInterpolatorVertexData( double x, double y, double z );
17+
%Docstring
18+
Constructor for QgsInterpolatorVertexData with the specified
19+
``x``, ``y``, and ``z`` coordinate.
20+
%End
21+
22+
QgsInterpolatorVertexData();
23+
%Docstring
24+
Constructor for QgsInterpolatorVertexData
25+
%End
26+
1527
double x;
28+
%Docstring
29+
X-coordinate
30+
%End
1631
double y;
32+
%Docstring
33+
Y-coordinate
34+
%End
1735
double z;
36+
%Docstring
37+
Z-coordinate
38+
%End
1839
};
1940

2041
class QgsInterpolator
2142
{
2243
%Docstring
2344
Interface class for interpolations. Interpolators take
24-
the vertices of a vector layer as base data. The z-Value
25-
can be an attribute or the z-coordinates in case of 25D types*
45+
the vertices of a vector layer as base data. The z-Value
46+
can be an attribute or the z-coordinates in case of 3D types.
2647
%End
2748

2849
%TypeHeaderCode
2950
#include "qgsinterpolator.h"
3051
%End
3152
public:
32-
enum InputType
53+
54+
enum SourceType
3355
{
34-
POINTS,
35-
STRUCTURE_LINES,
36-
BREAK_LINES
56+
SourcePoints,
57+
SourceStructureLines,
58+
SourceBreakLines,
59+
};
60+
61+
enum ValueSource
62+
{
63+
ValueAttribute,
64+
ValueZ,
65+
ValueM,
66+
};
67+
68+
enum Result
69+
{
70+
Success,
71+
Canceled,
72+
InvalidSource,
73+
FeatureGeometryError,
3774
};
3875

3976
struct LayerData
4077
{
41-
QgsVectorLayer *vectorLayer;
42-
bool zCoordInterpolation;
78+
QgsFeatureSource *source;
79+
%Docstring
80+
Feature source
81+
%End
82+
QgsInterpolator::ValueSource valueSource;
83+
%Docstring
84+
Source for feature values to interpolate
85+
%End
4386
int interpolationAttribute;
44-
QgsInterpolator::InputType mInputType;
87+
%Docstring
88+
Index of feature attribute to use for interpolation
89+
%End
90+
QgsInterpolator::SourceType sourceType;
91+
%Docstring
92+
Source type
93+
%End
4594
};
4695

4796
QgsInterpolator( const QList<QgsInterpolator::LayerData> &layerData );
4897

4998
virtual ~QgsInterpolator();
5099

51-
virtual int interpolatePoint( double x, double y, double &result ) = 0;
100+
virtual int interpolatePoint( double x, double y, double &result, QgsFeedback *feedback = 0 ) = 0;
52101
%Docstring
53102
Calculates interpolation value for map coordinates x, y
54-
\param x x-coordinate (in map units)
55-
\param y y-coordinate (in map units)
56-
\param result out: interpolation result
57-
:return: 0 in case of success*
103+
\param x x-coordinate (in map units)
104+
\param y y-coordinate (in map units)
105+
\param result out: interpolation result
106+
\param feedback optional feedback object for progress and cancelation support
107+
:return: 0 in case of success*
58108
:rtype: int
59109
%End
60110

61111

62112
protected:
63113

64-
int cacheBaseData();
114+
Result cacheBaseData( QgsFeedback *feedback = 0 );
65115
%Docstring
66116
Caches the vertex and value data from the provider. All the vertex data
67-
will be held in virtual memory
68-
:return: 0 in case of success*
69-
:rtype: int
117+
will be held in virtual memory.
118+
119+
An optional ``feedback`` argument may be specified to allow cancelation and
120+
progress reports from the cache operation.
121+
122+
:return: Success in case of success
123+
:rtype: Result
70124
%End
71125

72126

0 commit comments

Comments
 (0)