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 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef GDAL_RAT_H_INCLUDED
15#define GDAL_RAT_H_INCLUDED
16
17#include "cpl_minixml.h"
18#include "gdal_priv.h"
19
20// Clone and Serialize are allowed to fail if GetRowCount()*GetColCount()
21// greater than this number
22#define RAT_MAX_ELEM_FOR_CLONE 1000000
23
24/************************************************************************/
25/* GDALRasterAttributeTable */
26/************************************************************************/
27
30
32{
33 public:
47 virtual GDALRasterAttributeTable *Clone() const = 0;
48
56 virtual int GetColumnCount() const = 0;
57
67 virtual const char *GetNameOfCol(int iCol) const = 0;
68
78 virtual GDALRATFieldUsage GetUsageOfCol(int iCol) const = 0;
79
89 virtual GDALRATFieldType GetTypeOfCol(int iCol) const = 0;
90
103 virtual int GetColOfUsage(GDALRATFieldUsage eUsage) const = 0;
104
112 virtual int GetRowCount() const = 0;
113
131 virtual const char *GetValueAsString(int iRow, int iField) const = 0;
132
147 virtual int GetValueAsInt(int iRow, int iField) const = 0;
148
163 virtual double GetValueAsDouble(int iRow, int iField) const = 0;
164
178 virtual void SetValue(int iRow, int iField, const char *pszValue) = 0;
179
193 virtual void SetValue(int iRow, int iField, int nValue) = 0;
194
208 virtual void SetValue(int iRow, int iField, double dfValue) = 0;
209
222 virtual int ChangesAreWrittenToFile() = 0;
223
231 virtual CPLErr SetTableType(const GDALRATTableType eInTableType) = 0;
232
241 virtual GDALRATTableType GetTableType() const = 0;
242
243 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
244 int iLength, double *pdfData);
245 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
246 int iLength, int *pnData);
247 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow,
248 int iLength, char **papszStrList);
249
250 virtual void SetRowCount(int iCount);
251 virtual int GetRowOfValue(double dfValue) const;
252 virtual int GetRowOfValue(int nValue) const;
253
254 virtual CPLErr CreateColumn(const char *pszFieldName,
255 GDALRATFieldType eFieldType,
256 GDALRATFieldUsage eFieldUsage);
257 virtual CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize);
258 virtual int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const;
259
266 virtual CPLXMLNode *Serialize() const;
267 virtual void *SerializeJSON() const;
268 virtual CPLErr XMLInit(const CPLXMLNode *, const char *);
269
270 virtual CPLErr InitializeFromColorTable(const GDALColorTable *);
271 virtual GDALColorTable *TranslateToColorTable(int nEntryCount = -1);
272
273 virtual void DumpReadable(FILE * = nullptr);
274
278 static inline GDALRasterAttributeTableH
280 {
281 return static_cast<GDALRasterAttributeTableH>(poRAT);
282 }
283
287 static inline GDALRasterAttributeTable *
289 {
290 return static_cast<GDALRasterAttributeTable *>(hRAT);
291 }
292
298 virtual void RemoveStatistics() = 0;
299};
300
301/************************************************************************/
302/* GDALRasterAttributeField */
303/* */
304/* (private) */
305/************************************************************************/
307class GDALRasterAttributeField
308{
309 public:
310 CPLString sName{};
311
313
315
316 std::vector<GInt32> anValues{};
317 std::vector<double> adfValues{};
318 std::vector<CPLString> aosValues{};
319};
320
322
323/************************************************************************/
324/* GDALDefaultRasterAttributeTable */
325/************************************************************************/
326
328
330{
331 private:
332 std::vector<GDALRasterAttributeField> aoFields{};
333
334 int bLinearBinning = false; // TODO(schwehr): Can this be a bool?
335 double dfRow0Min = -0.5;
336 double dfBinSize = 1.0;
337
338 GDALRATTableType eTableType;
339
340 void AnalyseColumns();
341 int bColumnsAnalysed = false; // TODO(schwehr): Can this be a bool?
342 int nMinCol = -1;
343 int nMaxCol = -1;
344
345 int nRowCount = 0;
346
347 CPLString osWorkingResult{};
348
349 public:
352
353 GDALDefaultRasterAttributeTable *Clone() const override;
354
355 int GetColumnCount() const override;
356
357 const char *GetNameOfCol(int) const override;
358 GDALRATFieldUsage GetUsageOfCol(int) const override;
359 GDALRATFieldType GetTypeOfCol(int) const override;
360
361 int GetColOfUsage(GDALRATFieldUsage) const override;
362
363 int GetRowCount() const override;
364
365 const char *GetValueAsString(int iRow, int iField) const override;
366 int GetValueAsInt(int iRow, int iField) const override;
367 double GetValueAsDouble(int iRow, int iField) const override;
368
369 void SetValue(int iRow, int iField, const char *pszValue) override;
370 void SetValue(int iRow, int iField, double dfValue) override;
371 void SetValue(int iRow, int iField, int nValue) override;
372
373 int ChangesAreWrittenToFile() override;
374 void SetRowCount(int iCount) override;
375
376 int GetRowOfValue(double dfValue) const override;
377 int GetRowOfValue(int nValue) const override;
378
379 CPLErr CreateColumn(const char *pszFieldName, GDALRATFieldType eFieldType,
380 GDALRATFieldUsage eFieldUsage) override;
381 CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize) override;
382 int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const override;
383
384 CPLErr SetTableType(const GDALRATTableType eInTableType) override;
385 GDALRATTableType GetTableType() const override;
386
387 void RemoveStatistics() override;
388};
389
390#endif /* ndef GDAL_RAT_H_INCLUDED */
Convenient string class based on std::string.
Definition cpl_string.h:307
A color table / palette.
Definition gdal_priv.h:1362
Raster Attribute Table container.
Definition gdal_rat.h:330
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition gdal_rat.h:32
virtual void SetValue(int iRow, int iField, const char *pszValue)=0
Set field value from string.
virtual const char * GetValueAsString(int iRow, int iField) const =0
Fetch field value as a string.
virtual double GetValueAsDouble(int iRow, int iField) const =0
Fetch field value as a double.
static GDALRasterAttributeTableH ToHandle(GDALRasterAttributeTable *poRAT)
Convert a GDALRasterAttributeTable* to a GDALRasterAttributeTableH.
Definition gdal_rat.h:279
virtual void RemoveStatistics()=0
Remove statistics from the RAT.
virtual int GetRowCount() const =0
Fetch row count.
virtual int ChangesAreWrittenToFile()=0
Determine whether changes made to this RAT are reflected directly in the dataset.
virtual CPLErr SetTableType(const GDALRATTableType eInTableType)=0
Set the RAT table type.
static GDALRasterAttributeTable * FromHandle(GDALRasterAttributeTableH hRAT)
Convert a GDALRasterAttributeTableH to a GDALRasterAttributeTable*.
Definition gdal_rat.h:288
virtual int GetColumnCount() const =0
Fetch table column count.
virtual GDALRATFieldUsage GetUsageOfCol(int iCol) const =0
Fetch column usage value.
virtual void SetValue(int iRow, int iField, int nValue)=0
Set field value from integer.
virtual GDALRasterAttributeTable * Clone() const =0
Copy Raster Attribute Table.
virtual GDALRATTableType GetTableType() const =0
Get the RAT table type.
virtual void SetValue(int iRow, int iField, double dfValue)=0
Set field value from double.
virtual const char * GetNameOfCol(int iCol) const =0
Fetch name of indicated column.
virtual int GetValueAsInt(int iRow, int iField) const =0
Fetch field value as a integer.
virtual int GetColOfUsage(GDALRATFieldUsage eUsage) const =0
Fetch column index for given usage.
virtual GDALRATFieldType GetTypeOfCol(int iCol) const =0
Fetch column type.
CPLErr
Error category.
Definition cpl_error.h:37
Definitions for CPL mini XML Parser/Serializer.
GDALRATTableType
RAT table type (thematic or athematic)
Definition gdal.h:2132
GDALRATFieldUsage
Field usage of raster attribute table.
Definition gdal.h:2106
@ GFU_Generic
Definition gdal.h:2107
GDALRATFieldType
Field type of raster attribute table.
Definition gdal.h:2098
@ GFT_Integer
Definition gdal.h:2099
void * GDALRasterAttributeTableH
Opaque type used for the C bindings of the C++ GDALRasterAttributeTable class.
Definition gdal.h:389
GDALRWFlag
Definition gdal.h:117
C++ GDAL entry points.
Document node structure.
Definition cpl_minixml.h:55