QGIS API Documentation  2.99.0-Master (314842d)
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 
22 bool QgsRaster::isRepresentableValue( double value, Qgis::DataType dataType )
23 {
24  switch ( dataType )
25  {
26  case Qgis::Byte:
28  case Qgis::UInt16:
30  case Qgis::Int16:
32  case Qgis::UInt32:
34  case Qgis::Int32:
36  case Qgis::Float32:
37  return qIsNaN( value ) || qIsInf( value ) ||
39  default:
40  return true;
41  break;
42  }
43 }
44 
45 double QgsRaster::representableValue( double value, Qgis::DataType dataType )
46 {
47  switch ( dataType )
48  {
49  case Qgis::Byte:
50  return static_cast<quint8>( value );
51  case Qgis::UInt16:
52  return static_cast<quint16>( value );
53  case Qgis::Int16:
54  return static_cast<qint16>( value );
55  case Qgis::UInt32:
56  return static_cast<quint32>( value );
57  case Qgis::Int32:
58  return static_cast<qint32>( value );
59  case Qgis::Float32:
60  return static_cast<float>( value );
61  default:
62  break;
63  }
64  return value;
65 }
Thirty two bit signed integer (qint32)
Definition: qgis.h:68
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:67
DataType
Raster data types.
Definition: qgis.h:61
Thirty two bit floating point (float)
Definition: qgis.h:69
Sixteen bit signed integer (qint16)
Definition: qgis.h:66
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:65
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
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:22
static double representableValue(double value, Qgis::DataType dataType)
Get value representable by given data type.
Definition: qgsraster.cpp:45
Eight bit unsigned integer (quint8)
Definition: qgis.h:64