QGIS API Documentation  2.99.0-Master (9fdd060)
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:
27  return value >= std::numeric_limits<quint8>::min() && value <= std::numeric_limits<quint8>::max();
28  case Qgis::UInt16:
29  return value >= std::numeric_limits<quint16>::min() && value <= std::numeric_limits<quint16>::max();
30  case Qgis::Int16:
31  return value >= std::numeric_limits<qint16>::min() && value <= std::numeric_limits<qint16>::max();
32  case Qgis::UInt32:
33  return value >= std::numeric_limits<quint32>::min() && value <= std::numeric_limits<quint32>::max();
34  case Qgis::Int32:
35  return value >= std::numeric_limits<qint32>::min() && value <= std::numeric_limits<qint32>::max();
36  case Qgis::Float32:
37  return std::isnan( value ) || std::isinf( value ) ||
38  ( value >= -std::numeric_limits<float>::max() && value <= std::numeric_limits<float>::max() );
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:85
Thirty two bit unsigned integer (quint32)
Definition: qgis.h:84
DataType
Raster data types.
Definition: qgis.h:78
Thirty two bit floating point (float)
Definition: qgis.h:86
Sixteen bit signed integer (qint16)
Definition: qgis.h:83
Sixteen bit unsigned integer (quint16)
Definition: qgis.h:82
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:81