|
| 1 | +/*************************************************************************** |
| 2 | + qgsreclassifyutils.h |
| 3 | + --------------------- |
| 4 | + begin : June, 2018 |
| 5 | + copyright : (C) 2018 by Nyall Dawson |
| 6 | + email : nyall dot dawson 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 | +#ifndef QGSRECLASSIFYUTILS |
| 19 | +#define QGSRECLASSIFYUTILS |
| 20 | + |
| 21 | +#define SIP_NO_FILE |
| 22 | + |
| 23 | +#include "qgis.h" |
| 24 | +#include "qgis_analysis.h" |
| 25 | +#include "qgsrasterrange.h" |
| 26 | + |
| 27 | +class QgsRasterInterface; |
| 28 | +class QgsProcessingFeedback; |
| 29 | +class QgsRasterDataProvider; |
| 30 | +class QgsRectangle; |
| 31 | + |
| 32 | +///@cond PRIVATE |
| 33 | + |
| 34 | +/** |
| 35 | + * Utility functions for reclassifying raster layers. |
| 36 | + * \ingroup analysis |
| 37 | + * \since QGIS 3.4 |
| 38 | + */ |
| 39 | +class ANALYSIS_EXPORT QgsReclassifyUtils |
| 40 | +{ |
| 41 | + |
| 42 | + public: |
| 43 | + |
| 44 | + /** |
| 45 | + * Represents a single class for a reclassification operation. |
| 46 | + */ |
| 47 | + class RasterClass : public QgsRasterRange |
| 48 | + { |
| 49 | + public: |
| 50 | + |
| 51 | + //! Default constructor for an empty class |
| 52 | + RasterClass() = default; |
| 53 | + |
| 54 | + /** |
| 55 | + * Constructor for RasterClass, with the specified range of min to max values. |
| 56 | + * The \a value argument gives the desired output value for this raster class. |
| 57 | + */ |
| 58 | + RasterClass( double minValue, double maxValue, QgsRasterRange::BoundsType type, double value ) |
| 59 | + : QgsRasterRange( minValue, maxValue, type ) |
| 60 | + , value( value ) |
| 61 | + {} |
| 62 | + |
| 63 | + //! Desired output value for class |
| 64 | + double value = 0; |
| 65 | + }; |
| 66 | + |
| 67 | + /** |
| 68 | + * Performs a reclassification operation on a raster source \a sourceRaster, reclassifying to the given |
| 69 | + * list of \a classes. |
| 70 | + * |
| 71 | + * Parameters of the raster must be given by the \a band, \a extent, \a sourceWidthPixels and |
| 72 | + * \a sourceHeightPixels values. |
| 73 | + * |
| 74 | + * The raster data provider \a destinationRaster will be used to save the result of the |
| 75 | + * reclassification operation. The caller is responsible for ensuring that this data provider |
| 76 | + * has been created with the same extent, pixel dimensions and CRS as the input raster. |
| 77 | + * |
| 78 | + * The nodata value for the destination should be specified via \a destNoDataValue. This |
| 79 | + * will be used wherever the source raster has a no data value or a source pixel value |
| 80 | + * does not have a matching class. |
| 81 | + * |
| 82 | + * If \a useNoDataForMissingValues is true, then any raster values which do not match to |
| 83 | + * a class will be changed to the no data value. Otherwise they are saved unchanged. |
| 84 | + * |
| 85 | + * The \a feedback argument gives an optional processing feedback, for progress reports |
| 86 | + * and cancelation. |
| 87 | + */ |
| 88 | + static void reclassify(const QVector< RasterClass > &classes, |
| 89 | + QgsRasterInterface *sourceRaster, |
| 90 | + int band, |
| 91 | + const QgsRectangle& extent, |
| 92 | + int sourceWidthPixels, |
| 93 | + int sourceHeightPixels, |
| 94 | + QgsRasterDataProvider *destinationRaster, |
| 95 | + double destNoDataValue, bool useNoDataForMissingValues, |
| 96 | + QgsProcessingFeedback *feedback = nullptr ); |
| 97 | + |
| 98 | + /** |
| 99 | + * Reclassifies a single \a input value, using the specified list of \a classes. |
| 100 | + * |
| 101 | + * If a matching class was found, then \a reclassified will be set to true and the |
| 102 | + * class output value returned. |
| 103 | + * |
| 104 | + * If no matching class was found then \a reclassified will be set to false, and the |
| 105 | + * original \a input value returned unchanged. |
| 106 | + */ |
| 107 | + static double reclassifyValue( const QVector< RasterClass > &classes, double input, bool& reclassified ); |
| 108 | + |
| 109 | +}; |
| 110 | + |
| 111 | +///@endcond PRIVATE |
| 112 | + |
| 113 | +#endif // QGSRECLASSIFYUTILS |
| 114 | + |
| 115 | + |
0 commit comments