QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
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 "qgsraster.h"
19
20#include <limits>
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 ) || ( value >= -std::numeric_limits<float>::max() && value <= std::numeric_limits<float>::max() );
41 return true;
49 break;
50 }
51 return true;
52}
53
54double QgsRaster::representableValue( double value, Qgis::DataType dataType )
55{
56 switch ( dataType )
57 {
59 return static_cast<quint8>( value );
61 return static_cast<qint8>( value );
63 return static_cast<quint16>( value );
65 return static_cast<qint16>( value );
67 return static_cast<quint32>( value );
69 return static_cast<qint32>( value );
71 return static_cast<float>( value );
73 return value;
81 break;
82 }
83 return value;
84}
DataType
Raster data types.
Definition qgis.h:393
@ CInt32
Complex Int32.
Definition qgis.h:404
@ Float32
Thirty two bit floating point (float).
Definition qgis.h:401
@ CFloat64
Complex Float64.
Definition qgis.h:406
@ Int16
Sixteen bit signed integer (qint16).
Definition qgis.h:398
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition qgis.h:408
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30).
Definition qgis.h:396
@ UInt16
Sixteen bit unsigned integer (quint16).
Definition qgis.h:397
@ Byte
Eight bit unsigned integer (quint8).
Definition qgis.h:395
@ UnknownDataType
Unknown or unspecified type.
Definition qgis.h:394
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition qgis.h:407
@ Int32
Thirty two bit signed integer (qint32).
Definition qgis.h:400
@ Float64
Sixty four bit floating point (double).
Definition qgis.h:402
@ CFloat32
Complex Float32.
Definition qgis.h:405
@ CInt16
Complex Int16.
Definition qgis.h:403
@ UInt32
Thirty two bit unsigned integer (quint32).
Definition qgis.h:399
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:54