QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsrasterrange.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsrasterrange.h
3 --------------------------------------
4 Date : Oct 9, 2012
5 Copyright : (C) 2012 by Radim Blazek
6 email : radim dot blazek at gmail dot com
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#ifndef QGSRASTERRANGE_H
19#define QGSRASTERRANGE_H
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
25#include <QList>
26
27class QgsRasterRange;
28
29typedef QList<QgsRasterRange> QgsRasterRangeList;
30
36class CORE_EXPORT QgsRasterRange
37{
38 public:
39
48
52 QgsRasterRange() = default;
53
61
66 double min() const { return mMin; }
67
72 double max() const { return mMax; }
73
81 BoundsType bounds() const { return mType; }
82
87 double setMin( double min ) { return mMin = min; }
88
93 double setMax( double max ) { return mMax = max; }
94
102 void setBounds( BoundsType type ) { mType = type; }
103
104 inline bool operator==( const QgsRasterRange &o ) const
105 {
106 return ( ( std::isnan( mMin ) && std::isnan( o.mMin ) ) || qgsDoubleNear( mMin, o.mMin ) )
107 && ( ( std::isnan( mMax ) && std::isnan( o.mMax ) ) || qgsDoubleNear( mMax, o.mMax ) )
108 && mType == o.mType;
109 }
110
115 bool contains( double value ) const
116 {
117 return ( value > mMin
118 || ( !std::isnan( mMin ) && qgsDoubleNear( value, mMin ) && ( mType == IncludeMinAndMax || mType == IncludeMin ) )
119 || std::isnan( mMin ) )
120 &&
121 ( value < mMax
122 || ( !std::isnan( mMax ) && qgsDoubleNear( value, mMax ) && ( mType == IncludeMinAndMax || mType == IncludeMax ) )
123 || std::isnan( mMax ) );
124 }
125
132 static bool contains( double value, const QgsRasterRangeList &rangeList )
133 {
134 for ( const QgsRasterRange &range : rangeList )
135 {
136 if ( range.contains( value ) )
137 {
138 return true;
139 }
140 }
141 return false;
142 }
143
148 bool overlaps( const QgsRasterRange &other ) const;
149
154 QString asText() const;
155
156 private:
157 double mMin = std::numeric_limits<double>::quiet_NaN();
158 double mMax = std::numeric_limits<double>::quiet_NaN();
159 BoundsType mType = IncludeMinAndMax;
160};
161
162#endif
163
164
Represents a range of raster values between min and max, optionally including the min and max value.
double setMin(double min)
Sets the minimum value for the range.
BoundsType
Handling for min and max bounds.
@ IncludeMin
Include the min value, but not the max value, e.g. min <= value < max.
@ IncludeMinAndMax
Min and max values are inclusive.
@ Exclusive
Don't include either the min or max value, e.g. min < value < max.
@ IncludeMax
Include the max value, but not the min value, e.g. min < value <= max.
bool operator==(const QgsRasterRange &o) const
double min() const
Returns the minimum value for the range.
void setBounds(BoundsType type)
Sets the bounds type for the range, which specifies whether or not the min and max values themselves ...
bool contains(double value) const
Returns true if this range contains the specified value.
double setMax(double max)
Sets the maximum value for the range.
double max() const
Returns the maximum value for the range.
QgsRasterRange()=default
Default constructor, both min and max value for the range will be set to NaN.
BoundsType bounds() const
Returns the bounds type for the range, which specifies whether or not the min and max values themselv...
static bool contains(double value, const QgsRasterRangeList &rangeList)
Tests if a value is within the list of ranges.
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
QList< QgsRasterRange > QgsRasterRangeList