GDAL
gdal_rat.h
1/******************************************************************************
2 * $Id: gdal_rat.h 2519a7eb0e1649dbf8625ae8ffc7bb7c3ef9514b 2018-07-10 12:05:23 +0100 Robert Coup $
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{
49public:
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,
195 const char *pszValue ) = 0;
196
210 virtual void SetValue( int iRow, int iField, int nValue ) = 0;
211
225 virtual void SetValue( int iRow, int iField, double dfValue) = 0;
226
239 virtual int ChangesAreWrittenToFile() = 0;
240
248 virtual CPLErr SetTableType(const GDALRATTableType eInTableType) = 0;
249
258 virtual GDALRATTableType GetTableType() const = 0;
259
260 virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
261 int iStartRow, int iLength,
262 double *pdfData);
263 virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
264 int iStartRow, int iLength, int *pnData);
265 virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
266 int iStartRow, int iLength,
267 char **papszStrList);
268
269 virtual void SetRowCount( int iCount );
270 virtual int GetRowOfValue( double dfValue ) const;
271 virtual int GetRowOfValue( int nValue ) const;
272
273 virtual CPLErr CreateColumn( const char *pszFieldName,
274 GDALRATFieldType eFieldType,
275 GDALRATFieldUsage eFieldUsage );
276 virtual CPLErr SetLinearBinning( double dfRow0Min,
277 double dfBinSize );
278 virtual int GetLinearBinning( double *pdfRow0Min,
279 double *pdfBinSize ) const;
280
287 virtual CPLXMLNode *Serialize() const;
288 virtual void *SerializeJSON() const;
289 virtual CPLErr XMLInit( CPLXMLNode *, const char * );
290
291 virtual CPLErr InitializeFromColorTable( const GDALColorTable * );
292 virtual GDALColorTable *TranslateToColorTable( int nEntryCount = -1 );
293
294 virtual void DumpReadable( FILE * = nullptr );
295
300 { return static_cast<GDALRasterAttributeTableH>(poRAT); }
301
306 { return static_cast<GDALRasterAttributeTable*>(hRAT); }
307
313 virtual void RemoveStatistics() = 0;
314};
315
316/************************************************************************/
317/* GDALRasterAttributeField */
318/* */
319/* (private) */
320/************************************************************************/
322class GDALRasterAttributeField
323{
324 public:
325 CPLString sName{};
326
328
330
331 std::vector<GInt32> anValues{};
332 std::vector<double> adfValues{};
333 std::vector<CPLString> aosValues{};
334};
336
337/************************************************************************/
338/* GDALDefaultRasterAttributeTable */
339/************************************************************************/
340
342
344{
345 private:
346 std::vector<GDALRasterAttributeField> aoFields{};
347
348 int bLinearBinning = false; // TODO(schwehr): Can this be a bool?
349 double dfRow0Min = -0.5;
350 double dfBinSize = 1.0;
351
352 GDALRATTableType eTableType;
353
354 void AnalyseColumns();
355 int bColumnsAnalysed = false; // TODO(schwehr): Can this be a bool?
356 int nMinCol = -1;
357 int nMaxCol = -1;
358
359 int nRowCount = 0;
360
361 CPLString osWorkingResult{};
362
363 public:
366
367 GDALDefaultRasterAttributeTable *Clone() const override;
368
369 int GetColumnCount() const override;
370
371 const char *GetNameOfCol( int ) const override;
372 GDALRATFieldUsage GetUsageOfCol( int ) const override;
373 GDALRATFieldType GetTypeOfCol( int ) const override;
374
375 int GetColOfUsage( GDALRATFieldUsage ) const override;
376
377 int GetRowCount() const override;
378
379 const char *GetValueAsString( int iRow, int iField ) const override;
380 int GetValueAsInt( int iRow, int iField ) const override;
381 double GetValueAsDouble( int iRow, int iField ) const override;
382
383 void SetValue( int iRow, int iField,
384 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,
395 GDALRATFieldType eFieldType,
396 GDALRATFieldUsage eFieldUsage ) override;
397 CPLErr SetLinearBinning( double dfRow0Min,
398 double dfBinSize ) override;
399 int GetLinearBinning( double *pdfRow0Min,
400 double *pdfBinSize ) const override;
401
402 CPLErr SetTableType(const GDALRATTableType eInTableType) override;
403 GDALRATTableType GetTableType() const override;
404
405 void RemoveStatistics() override;
406};
407
408#endif /* ndef GDAL_RAT_H_INCLUDED */
Convenient string class based on std::string.
Definition: cpl_string.h:330
A color table / palette.
Definition: gdal_priv.h:965
Raster Attribute Table container.
Definition: gdal_rat.h:344
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:48
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:299
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:305
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:53
Definitions for CPL mini XML Parser/Serializer.
GDALRATTableType
RAT table type (thematic or athematic)
Definition: gdal.h:1123
GDALRATFieldUsage
Field usage of raster attribute table.
Definition: gdal.h:1098
@ GFU_Generic
Definition: gdal.h:1099
GDALRATFieldType
Field type of raster attribute table.
Definition: gdal.h:1091
@ GFT_Integer
Definition: gdal.h:1092
void * GDALRasterAttributeTableH
Opaque type used for the C bindings of the C++ GDALRasterAttributeTable class.
Definition: gdal.h:267
GDALRWFlag
Definition: gdal.h:119
C++ GDAL entry points.
Document node structure.
Definition: cpl_minixml.h:67

Generated for GDAL by doxygen 1.9.4.