QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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<qint8>::min() && value <= std::numeric_limits<qint8>::max();
31 return value >= std::numeric_limits<quint16>::min() && value <= std::numeric_limits<quint16>::max();
33 return value >= std::numeric_limits<qint16>::min() && value <= std::numeric_limits<qint16>::max();
35 return value >= std::numeric_limits<quint32>::min() && value <= std::numeric_limits<quint32>::max();
37 return value >= std::numeric_limits<qint32>::min() && value <= std::numeric_limits<qint32>::max();
39 return std::isnan( value ) || std::isinf( value ) ||
40 ( value >= -std::numeric_limits<float>::max() && value <= std::numeric_limits<float>::max() );
42 return true;
50 break;
51 }
52 return true;
53}
54
55double QgsRaster::representableValue( double value, Qgis::DataType dataType )
56{
57 switch ( dataType )
58 {
60 return static_cast<quint8>( value );
62 return static_cast<qint8>( value );
64 return static_cast<quint16>( value );
66 return static_cast<qint16>( value );
68 return static_cast<quint32>( value );
70 return static_cast<qint32>( value );
72 return static_cast<float>( value );
74 return value;
82 break;
83 }
84 return value;
85}
DataType
Raster data types.
Definition: qgis.h:269
@ CInt32
Complex Int32.
@ Float32
Thirty two bit floating point (float)
@ CFloat64
Complex Float64.
@ Int16
Sixteen bit signed integer (qint16)
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30)
@ UInt16
Sixteen bit unsigned integer (quint16)
@ Byte
Eight bit unsigned integer (quint8)
@ UnknownDataType
Unknown or unspecified type.
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
@ Int32
Thirty two bit signed integer (qint32)
@ Float64
Sixty four bit floating point (double)
@ CFloat32
Complex Float32.
@ CInt16
Complex Int16.
@ 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:55