QGIS API Documentation  2.99.0-Master (c558d51)
qgsraster.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsraster.cpp - Raster namespace
3  --------------------------------------
4  Date : Apr, 2013
5  Copyright : (C) 2013 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 #include <limits>
19 
20 #include "qgsraster.h"
21 
23 {
24  switch ( theLimits )
25  {
27  return QStringLiteral( "MinMax" );
29  return QStringLiteral( "StdDev" );
31  return QStringLiteral( "CumulativeCut" );
32  default:
33  break;
34  }
35  return QStringLiteral( "None" );
36 }
37 
39 {
40  if ( theLimits == QLatin1String( "MinMax" ) )
41  {
43  }
44  else if ( theLimits == QLatin1String( "StdDev" ) )
45  {
47  }
48  else if ( theLimits == QLatin1String( "CumulativeCut" ) )
49  {
51  }
53 }
54 
55 bool QgsRaster::isRepresentableValue( double value, Qgis::DataType dataType )
56 {
57  switch ( dataType )
58  {
59  case Qgis::Byte:
61  case Qgis::UInt16:
63  case Qgis::Int16:
65  case Qgis::UInt32:
67  case Qgis::Int32:
69  case Qgis::Float32:
70  return qIsNaN( value ) || qIsInf( value ) ||
72  default:
73  return true;
74  break;
75  }
76 }
77 
78 double QgsRaster::representableValue( double value, Qgis::DataType dataType )
79 {
80  switch ( dataType )
81  {
82  case Qgis::Byte:
83  return static_cast<quint8>( value );
84  case Qgis::UInt16:
85  return static_cast<quint16>( value );
86  case Qgis::Int16:
87  return static_cast<qint16>( value );
88  case Qgis::UInt32:
89  return static_cast<quint32>( value );
90  case Qgis::Int32:
91  return static_cast<qint32>( value );
92  case Qgis::Float32:
93  return static_cast<float>( value );
94  default:
95  break;
96  }
97  return value;
98 }
Thirty two bit signed integer (qint32)
Definition: qgis.h:67
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:66
DataType
Raster data types.
Definition: qgis.h:60
Thirty two bit floating point (float)
Definition: qgis.h:68
Sixteen bit signed integer (qint16)
Definition: qgis.h:65
static ContrastEnhancementLimits contrastEnhancementLimitsFromString(const QString &theLimits)
Definition: qgsraster.cpp:38
ContrastEnhancementLimits
Contrast enhancement limits.
Definition: qgsraster.h:103
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:64
double ANALYSIS_EXPORT min(double x, double y)
Returns the minimum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:452
static QString contrastEnhancementLimitsAsString(QgsRaster::ContrastEnhancementLimits theLimits)
Definition: qgsraster.cpp:22
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
Definition: MathUtils.cc:437
static bool isRepresentableValue(double value, Qgis::DataType dataType)
Check if the specified value is representable in the given data type.
Definition: qgsraster.cpp:55
static double representableValue(double value, Qgis::DataType dataType)
Get value representable by given data type.
Definition: qgsraster.cpp:78
Eight bit unsigned integer (quint8)
Definition: qgis.h:63