QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
22bool QgsRaster::isRepresentableValue( double value, Qgis::DataType dataType )
23{
24 switch ( dataType )
25 {
27 return value >= std::numeric_limits<quint8>::min() && value <= std::numeric_limits<quint8>::max();
29 return value >= std::numeric_limits<quint16>::min() && value <= std::numeric_limits<quint16>::max();
31 return value >= std::numeric_limits<qint16>::min() && value <= std::numeric_limits<qint16>::max();
33 return value >= std::numeric_limits<quint32>::min() && value <= std::numeric_limits<quint32>::max();
35 return value >= std::numeric_limits<qint32>::min() && value <= std::numeric_limits<qint32>::max();
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
45double QgsRaster::representableValue( double value, Qgis::DataType dataType )
46{
47 switch ( dataType )
48 {
50 return static_cast<quint8>( value );
52 return static_cast<quint16>( value );
54 return static_cast<qint16>( value );
56 return static_cast<quint32>( value );
58 return static_cast<qint32>( value );
60 return static_cast<float>( value );
61 default:
62 break;
63 }
64 return value;
65}
DataType
Raster data types.
Definition: qgis.h:129
@ Float32
Thirty two bit floating point (float)
@ Int16
Sixteen bit signed integer (qint16)
@ UInt16
Sixteen bit unsigned integer (quint16)
@ Byte
Eight bit unsigned integer (quint8)
@ Int32
Thirty two bit signed integer (qint32)
@ UInt32
Thirty two bit unsigned integer (quint32)
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)
Gets value representable by given data type.
Definition: qgsraster.cpp:45