GDAL
gdal_rat.h
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: GDAL Core
5  * Purpose: GDALRasterAttributeTable class declarations.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef GDAL_RAT_H_INCLUDED
31 #define GDAL_RAT_H_INCLUDED
32 
33 #include "cpl_minixml.h"
34 #include "gdal_priv.h"
35 
36 // Clone and Serialize are allowed to fail if GetRowCount()*GetColCount()
37 // greater than this number
38 #define RAT_MAX_ELEM_FOR_CLONE 1000000
39 
40 /************************************************************************/
41 /* GDALRasterAttributeTable */
42 /************************************************************************/
43 
46 
48 {
49  public:
50  virtual ~GDALRasterAttributeTable();
63  virtual GDALRasterAttributeTable *Clone() const = 0;
64 
72  virtual int GetColumnCount() const = 0;
73 
83  virtual const char *GetNameOfCol(int iCol) const = 0;
84 
94  virtual GDALRATFieldUsage GetUsageOfCol(int iCol) const = 0;
95 
105  virtual GDALRATFieldType GetTypeOfCol(int iCol) const = 0;
106 
119  virtual int GetColOfUsage(GDALRATFieldUsage eUsage) const = 0;
120 
128  virtual int GetRowCount() const = 0;
129 
147  virtual const char *GetValueAsString(int iRow, int iField) const = 0;
148 
163  virtual int GetValueAsInt(int iRow, int iField) const = 0;
164 
179  virtual double GetValueAsDouble(int iRow, int iField) const = 0;
180 
194  virtual void SetValue(int iRow, int iField, const char *pszValue) = 0;
195 
209  virtual void SetValue(int iRow, int iField, int nValue) = 0;
210 
224  virtual void SetValue(int iRow, int iField, double dfValue) = 0;
225 
238  virtual int ChangesAreWrittenToFile() = 0;
239 
247  virtual CPLErr SetTableType(const GDALRATTableType eInTableType) = 0;
248 
257  virtual GDALRATTableType GetTableType() const = 0;
258 
259  virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
260  int iLength, double *pdfData);
261  virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
262  int iLength, int *pnData);
263  virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
264  int iLength, char **papszStrList);
265 
266  virtual void SetRowCount(int iCount);
267  virtual int GetRowOfValue(double dfValue) const;
268  virtual int GetRowOfValue(int nValue) const;
269 
270  virtual CPLErr CreateColumn(const char *pszFieldName,
271  GDALRATFieldType eFieldType,
272  GDALRATFieldUsage eFieldUsage);
273  virtual CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize);
274  virtual int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const;
275 
282  virtual CPLXMLNode *Serialize() const;
283  virtual void *SerializeJSON() const;
284  virtual CPLErr XMLInit(CPLXMLNode *, const char *);
285 
286  virtual CPLErr InitializeFromColorTable(const GDALColorTable *);
287  virtual GDALColorTable *TranslateToColorTable(int nEntryCount = -1);
288 
289  virtual void DumpReadable(FILE * = nullptr);
290 
294  static inline GDALRasterAttributeTableH
296  {
297  return static_cast<GDALRasterAttributeTableH>(poRAT);
298  }
299 
303  static inline GDALRasterAttributeTable *
305  {
306  return static_cast<GDALRasterAttributeTable *>(hRAT);
307  }
308 
314  virtual void RemoveStatistics() = 0;
315 };
316 
317 /************************************************************************/
318 /* GDALRasterAttributeField */
319 /* */
320 /* (private) */
321 /************************************************************************/
323 class GDALRasterAttributeField
324 {
325  public:
326  CPLString sName{};
327 
329 
331 
332  std::vector<GInt32> anValues{};
333  std::vector<double> adfValues{};
334  std::vector<CPLString> aosValues{};
335 };
337 
338 /************************************************************************/
339 /* GDALDefaultRasterAttributeTable */
340 /************************************************************************/
341 
343 
345 {
346  private:
347  std::vector<GDALRasterAttributeField> aoFields{};
348 
349  int bLinearBinning = false; // TODO(schwehr): Can this be a bool?
350  double dfRow0Min = -0.5;
351  double dfBinSize = 1.0;
352 
353  GDALRATTableType eTableType;
354 
355  void AnalyseColumns();
356  int bColumnsAnalysed = false; // TODO(schwehr): Can this be a bool?
357  int nMinCol = -1;
358  int nMaxCol = -1;
359 
360  int nRowCount = 0;
361 
362  CPLString osWorkingResult{};
363 
364  public:
367 
368  GDALDefaultRasterAttributeTable *Clone() const override;
369 
370  int GetColumnCount() const override;
371 
372  const char *GetNameOfCol(int) const override;
373  GDALRATFieldUsage GetUsageOfCol(int) const override;
374  GDALRATFieldType GetTypeOfCol(int) const override;
375 
376  int GetColOfUsage(GDALRATFieldUsage) const override;
377 
378  int GetRowCount() const override;
379 
380  const char *GetValueAsString(int iRow, int iField) const override;
381  int GetValueAsInt(int iRow, int iField) const override;
382  double GetValueAsDouble(int iRow, int iField) const override;
383 
384  void SetValue(int iRow, int iField, const char *pszValue) override;
385  void SetValue(int iRow, int iField, double dfValue) override;
386  void SetValue(int iRow, int iField, int nValue) override;
387 
388  int ChangesAreWrittenToFile() override;
389  void SetRowCount(int iCount) override;
390 
391  int GetRowOfValue(double dfValue) const override;
392  int GetRowOfValue(int nValue) const override;
393 
394  CPLErr CreateColumn(const char *pszFieldName, GDALRATFieldType eFieldType,
395  GDALRATFieldUsage eFieldUsage) override;
396  CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize) override;
397  int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const override;
398 
399  CPLErr SetTableType(const GDALRATTableType eInTableType) override;
400  GDALRATTableType GetTableType() const override;
401 
402  void RemoveStatistics() override;
403 };
404 
405 #endif /* ndef GDAL_RAT_H_INCLUDED */
GDALRATTableType
GDALRATTableType
RAT table type (thematic or athematic)
Definition: gdal.h:1882
GDALRasterAttributeTableH
void * GDALRasterAttributeTableH
Opaque type used for the C bindings of the C++ GDALRasterAttributeTable class.
Definition: gdal.h:304
cpl_minixml.h
GDALRasterAttributeTable::GetValueAsInt
virtual int GetValueAsInt(int iRow, int iField) const =0
Fetch field value as a integer.
GDALRasterAttributeTable::GetValueAsDouble
virtual double GetValueAsDouble(int iRow, int iField) const =0
Fetch field value as a double.
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:311
GDALRasterAttributeTable::CreateColumn
virtual CPLErr CreateColumn(const char *pszFieldName, GDALRATFieldType eFieldType, GDALRATFieldUsage eFieldUsage)
Definition: gdal_rat.cpp:443
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
GFU_Generic
@ GFU_Generic
Definition: gdal.h:1858
GDALRasterAttributeTable::ChangesAreWrittenToFile
virtual int ChangesAreWrittenToFile()=0
Determine whether changes made to this RAT are reflected directly in the dataset.
GDALRasterAttributeTable::SetLinearBinning
virtual CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize)
Set linear binning information.
Definition: gdal_rat.cpp:491
GDALRasterAttributeTable::GetValueAsString
virtual const char * GetValueAsString(int iRow, int iField) const =0
Fetch field value as a string.
GDALRasterAttributeTable::GetRowOfValue
virtual int GetRowOfValue(double dfValue) const
Get row for pixel value.
Definition: gdal_rat.cpp:366
GDALRasterAttributeTable::GetColOfUsage
virtual int GetColOfUsage(GDALRATFieldUsage eUsage) const =0
Fetch column index for given usage.
GDALRasterAttributeTable::Clone
virtual GDALRasterAttributeTable * Clone() const =0
Copy Raster Attribute Table.
GDALRasterAttributeTable::GetLinearBinning
virtual int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const
Get linear binning information.
Definition: gdal_rat.cpp:534
GDALRasterAttributeTable::RemoveStatistics
virtual void RemoveStatistics()=0
Remove statistics from the RAT.
GDALRasterAttributeTable::ToHandle
static GDALRasterAttributeTableH ToHandle(GDALRasterAttributeTable *poRAT)
Convert a GDALRasterAttributeTable* to a GDALRasterAttributeTableH.
Definition: gdal_rat.h:295
GDALRasterAttributeTable::GetNameOfCol
virtual const char * GetNameOfCol(int iCol) const =0
Fetch name of indicated column.
GDALRasterAttributeTable::SetTableType
virtual CPLErr SetTableType(const GDALRATTableType eInTableType)=0
Set the RAT table type.
GDALRasterAttributeTable::SetRowCount
virtual void SetRowCount(int iCount)
Set row count.
Definition: gdal_rat.cpp:318
GFT_Integer
@ GFT_Integer
Definition: gdal.h:1850
GDALRATFieldType
GDALRATFieldType
Field type of raster attribute table.
Definition: gdal.h:1848
GDALRasterAttributeTable::GetColumnCount
virtual int GetColumnCount() const =0
Fetch table column count.
gdal_priv.h
GDALRWFlag
GDALRWFlag
Definition: gdal.h:131
GDALRasterAttributeTable::GetUsageOfCol
virtual GDALRATFieldUsage GetUsageOfCol(int iCol) const =0
Fetch column usage value.
GDALRATFieldUsage
GDALRATFieldUsage
Field usage of raster attribute table.
Definition: gdal.h:1856
CPLErr
CPLErr
Error category.
Definition: cpl_error.h:52
GDALRasterAttributeTable::GetTableType
virtual GDALRATTableType GetTableType() const =0
Get the RAT table type.
GDALRasterAttributeTable::GetRowCount
virtual int GetRowCount() const =0
Fetch row count.
GDALRasterAttributeTable
Definition: gdal_rat.h:47
GDALDefaultRasterAttributeTable
Raster Attribute Table container.
Definition: gdal_rat.h:344
GDALRasterAttributeTable::GetTypeOfCol
virtual GDALRATFieldType GetTypeOfCol(int iCol) const =0
Fetch column type.
GDALRasterAttributeTable::FromHandle
static GDALRasterAttributeTable * FromHandle(GDALRasterAttributeTableH hRAT)
Convert a GDALRasterAttributeTableH to a GDALRasterAttributeTable*.
Definition: gdal_rat.h:304
GDALColorTable
A color table / palette.
Definition: gdal_priv.h:1121
GDALRasterAttributeTable::SetValue
virtual void SetValue(int iRow, int iField, const char *pszValue)=0
Set field value from string.