QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
analysis
raster
qgsruggednessfilter.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsruggednessfilter.cpp - description
3
-----------------------
4
begin : August 7th, 2009
5
copyright : (C) 2009 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 "
qgsruggednessfilter.h
"
19
20
#include <cmath>
21
22
QgsRuggednessFilter::QgsRuggednessFilter
(
const
QString &inputFile,
const
QString &outputFile,
const
QString &outputFormat )
23
:
QgsNineCellFilter
( inputFile, outputFile, outputFormat )
24
{}
25
26
27
float
QgsRuggednessFilter::processNineCellWindow
(
float
*x11,
float
*x21,
float
*x31,
float
*x12,
float
*x22,
float
*x32,
float
*x13,
float
*x23,
float
*x33 )
28
{
29
//the formula would be that easy without nodata values...
30
/*
31
//return *x22; //test: write the raster value of the middle cell
32
float diff1 = *x11 - *x22;
33
float diff2 = *x21 - *x22;
34
float diff3 = *x31 - *x22;
35
float diff4 = *x12 - *x22;
36
float diff5 = *x32 - *x22;
37
float diff6 = *x13 - *x22;
38
float diff7 = *x23 - *x22;
39
float diff8 = *x33 - *x22;
40
return sqrt(diff1 * diff1 + diff2 * diff2 + diff3 * diff3 + diff4 * diff4 + diff5 * diff5 + diff6 * diff6 + diff7 * diff7 + diff8 * diff8);
41
*/
42
43
if
( *x22 ==
mInputNodataValue
)
44
{
45
return
mOutputNodataValue
;
46
}
47
48
double
sum = 0;
49
if
( *x11 !=
mInputNodataValue
)
50
{
51
sum += ( *x11 - *x22 ) * ( *x11 - *x22 );
52
}
53
if
( *x21 !=
mInputNodataValue
)
54
{
55
sum += ( *x21 - *x22 ) * ( *x21 - *x22 );
56
}
57
if
( *x31 !=
mInputNodataValue
)
58
{
59
sum += ( *x31 - *x22 ) * ( *x31 - *x22 );
60
}
61
if
( *x12 !=
mInputNodataValue
)
62
{
63
sum += ( *x12 - *x22 ) * ( *x12 - *x22 );
64
}
65
if
( *x32 !=
mInputNodataValue
)
66
{
67
sum += ( *x32 - *x22 ) * ( *x32 - *x22 );
68
}
69
if
( *x13 !=
mInputNodataValue
)
70
{
71
sum += ( *x13 - *x22 ) * ( *x13 - *x22 );
72
}
73
if
( *x23 !=
mInputNodataValue
)
74
{
75
sum += ( *x23 - *x22 ) * ( *x23 - *x22 );
76
}
77
if
( *x33 !=
mInputNodataValue
)
78
{
79
sum += ( *x33 - *x22 ) * ( *x33 - *x22 );
80
}
81
82
return
std::sqrt( sum );
83
}
QgsNineCellFilter::QgsNineCellFilter
QgsNineCellFilter(const QString &inputFile, const QString &outputFile, const QString &outputFormat)
Constructor that takes input file, output file and output format (GDAL string).
Definition
qgsninecellfilter.cpp:42
QgsNineCellFilter::mOutputNodataValue
double mOutputNodataValue
The nodata value of the output layer.
Definition
qgsninecellfilter.h:174
QgsNineCellFilter::mInputNodataValue
double mInputNodataValue
The nodata value of the input layer.
Definition
qgsninecellfilter.h:172
QgsRuggednessFilter::QgsRuggednessFilter
QgsRuggednessFilter(const QString &inputFile, const QString &outputFile, const QString &outputFormat)
Definition
qgsruggednessfilter.cpp:22
QgsRuggednessFilter::processNineCellWindow
float processNineCellWindow(float *x11, float *x21, float *x31, float *x12, float *x22, float *x32, float *x13, float *x23, float *x33) override
Calculates output value from nine input values.
Definition
qgsruggednessfilter.cpp:27
qgsruggednessfilter.h
Generated on
for QGIS API Documentation by
1.17.0