NoDataType.hpp
1 #pragma once
2 
3 //OPALS
4 #include "opals/config.hpp"
5 #include "opals/CustomOptionType.hpp"
6 #include "opals/RasterDataType.hpp"
7 
8 namespace opals {
9 
10  /// Class for storing a type independent a nodata value (nodata value can be deactivated as well)
11  class OPALS_API NoDataType : public CustomOptionType<NoDataType>
12  {
13  public:
14  enum Type
15  {
16  none = -1, ///< deactivates the nodata value
17  value, ///< use the provided value
18  min, ///< use the lowest value of the raster type as nodata value
19  max, ///< use the highest value of the raster type as nodata value
20  nan, ///< use Not-A-Number for floating-point and 'max' for integer raster types as nodata value
21  bitmask ///< use a separate bitmask as nodata information instead of a specific value
22  };
23 
24  public:
25  NoDataType();
26  NoDataType(Type t);
27  NoDataType(double v);
28  virtual ~NoDataType();
29 
30  /// check if nodata value is deactivated
31  bool isEmpty() const;
32 
33  void setType(Type t); ///< set type independent nodata value or deactivate the nodata value
34  void setValue(double v); ///< set a specific nodata value
35 
36  Type getType() const; ///< returns the nodata value type
37  double getValue() const; ///< return a specific nodata value (only relevant if type is Type::value)
38 
39  /// \brief returns the nodata value for the given raster type.
40  /// If the value cannot be converted to the given raster type an exception is thrown. Reasons for exceptions:
41  /// 1. type is none (isEmpty() == true)
42  /// 2. raster type cannot represent type (getType() == nan and any integer raster type)
43  /// 3. value exceeds raster type limits
44  double getValue(RasterDataType rasterType) const;
45  /// returns the nodata value for the given raster type but doesn't throw an exception if the value exceeds raster type limits (see above)
46  double getValue(RasterDataType rasterType, bool &wasCropped) const;
47 
48  /// \brief set the nodata value for a given double value considering the raster type (useful when setting from GDAL nodata value).
49  void setFromDouble(double v, RasterDataType rasterType);
50 
51  /// \name CustomOptionType interface
52  ///@{
53  static const char * help(bool);
54  static const char * syntax();
55  static bool exportsPythonType();
56  ///@}
57 
58  protected:
59  Type type_;
60  double value_;
61  };
62 }
Base class for all custom parameter types.
Definition: CustomOptionType.hpp:39
@ max
use the highest value of the raster type as nodata value
Definition: NoDataType.hpp:19
@ value
use the provided value
Definition: NoDataType.hpp:17
Contains the public interface of OPALS.
Definition: AbsValueOrQuantile.hpp:8
RasterDataType
The data type of each pixel of a raster.
Definition: RasterDataType.hpp:8
Type
Definition: NoDataType.hpp:14
@ nan
use Not-A-Number for floating-point and 'max' for integer raster types as nodata value
Definition: NoDataType.hpp:20
@ none
Suppress all logging output.
@ min
use the lowest value of the raster type as nodata value
Definition: NoDataType.hpp:18
Class for storing a type independent a nodata value (nodata value can be deactivated as well)
Definition: NoDataType.hpp:11