GDAL
gdal_rat.h
1 /******************************************************************************
2  * $Id: gdal_rat.h 36501 2016-11-25 14:09:24Z rouault $
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 
35 // Clone and Serialize are allowed to fail if GetRowCount()*GetColCount()
36 // greater than this number
37 #define RAT_MAX_ELEM_FOR_CLONE 1000000
38 
39 /************************************************************************/
40 /* GDALRasterAttributeTable */
41 /************************************************************************/
42 
45 
47 {
48 public:
49  virtual ~GDALRasterAttributeTable();
62  virtual GDALDefaultRasterAttributeTable *Clone() const = 0;
63 
71  virtual int GetColumnCount() const = 0;
72 
82  virtual const char *GetNameOfCol( int iCol ) const = 0;
83 
93  virtual GDALRATFieldUsage GetUsageOfCol( int iCol ) const = 0;
94 
104  virtual GDALRATFieldType GetTypeOfCol( int iCol ) const = 0;
105 
118  virtual int GetColOfUsage( GDALRATFieldUsage eUsage ) const = 0;
119 
127  virtual int GetRowCount() const = 0;
128 
146  virtual const char *GetValueAsString( int iRow, int iField ) const = 0;
147 
162  virtual int GetValueAsInt( int iRow, int iField ) const = 0;
163 
178  virtual double GetValueAsDouble( int iRow, int iField ) const = 0;
179 
193  virtual void SetValue( int iRow, int iField,
194  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 
240  virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
241  int iStartRow, int iLength,
242  double *pdfData);
243  virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
244  int iStartRow, int iLength, int *pnData);
245  virtual CPLErr ValuesIO( GDALRWFlag eRWFlag, int iField,
246  int iStartRow, int iLength,
247  char **papszStrList);
248 
249  virtual void SetRowCount( int iCount );
250  virtual int GetRowOfValue( double dfValue ) const;
251  virtual int GetRowOfValue( int nValue ) const;
252 
253  virtual CPLErr CreateColumn( const char *pszFieldName,
254  GDALRATFieldType eFieldType,
255  GDALRATFieldUsage eFieldUsage );
256  virtual CPLErr SetLinearBinning( double dfRow0Min,
257  double dfBinSize );
258  virtual int GetLinearBinning( double *pdfRow0Min,
259  double *pdfBinSize ) const;
260 
267  virtual CPLXMLNode *Serialize() const;
268  virtual void *SerializeJSON() const;
269  virtual CPLErr XMLInit( CPLXMLNode *, const char * );
270 
271  virtual CPLErr InitializeFromColorTable( const GDALColorTable * );
272  virtual GDALColorTable *TranslateToColorTable( int nEntryCount = -1 );
273 
274  virtual void DumpReadable( FILE * = NULL );
275 };
276 
277 /************************************************************************/
278 /* GDALRasterAttributeField */
279 /* */
280 /* (private) */
281 /************************************************************************/
283 class GDALRasterAttributeField
284 {
285  public:
286  CPLString sName;
287 
288  GDALRATFieldType eType;
289 
290  GDALRATFieldUsage eUsage;
291 
292  std::vector<GInt32> anValues;
293  std::vector<double> adfValues;
294  std::vector<CPLString> aosValues;
295 };
297 
298 /************************************************************************/
299 /* GDALDefaultRasterAttributeTable */
300 /************************************************************************/
301 
303 
305 {
306  private:
307  std::vector<GDALRasterAttributeField> aoFields;
308 
309  int bLinearBinning; // TODO(schwehr): Can this be a bool?
310  double dfRow0Min;
311  double dfBinSize;
312 
313  void AnalyseColumns();
314  int bColumnsAnalysed; // TODO(schwehr): Can this be a bool?
315  int nMinCol;
316  int nMaxCol;
317 
318  int nRowCount;
319 
320  CPLString osWorkingResult;
321 
322  public:
326 
328 
329  virtual int GetColumnCount() const CPL_OVERRIDE;
330 
331  virtual const char *GetNameOfCol( int ) const CPL_OVERRIDE;
332  virtual GDALRATFieldUsage GetUsageOfCol( int ) const CPL_OVERRIDE;
333  virtual GDALRATFieldType GetTypeOfCol( int ) const CPL_OVERRIDE;
334 
335  virtual int GetColOfUsage( GDALRATFieldUsage ) const CPL_OVERRIDE;
336 
337  virtual int GetRowCount() const CPL_OVERRIDE;
338 
339  virtual const char *GetValueAsString( int iRow, int iField ) const CPL_OVERRIDE;
340  virtual int GetValueAsInt( int iRow, int iField ) const CPL_OVERRIDE;
341  virtual double GetValueAsDouble( int iRow, int iField ) const CPL_OVERRIDE;
342 
343  virtual void SetValue( int iRow, int iField,
344  const char *pszValue ) CPL_OVERRIDE;
345  virtual void SetValue( int iRow, int iField, double dfValue) CPL_OVERRIDE;
346  virtual void SetValue( int iRow, int iField, int nValue ) CPL_OVERRIDE;
347 
349  virtual void SetRowCount( int iCount ) CPL_OVERRIDE;
350 
351  virtual int GetRowOfValue( double dfValue ) const CPL_OVERRIDE;
352  virtual int GetRowOfValue( int nValue ) const CPL_OVERRIDE;
353 
354  virtual CPLErr CreateColumn( const char *pszFieldName,
355  GDALRATFieldType eFieldType,
356  GDALRATFieldUsage eFieldUsage ) CPL_OVERRIDE;
357  virtual CPLErr SetLinearBinning( double dfRow0Min,
358  double dfBinSize ) CPL_OVERRIDE;
359  virtual int GetLinearBinning( double *pdfRow0Min,
360  double *pdfBinSize ) const CPL_OVERRIDE;
361 };
362 
363 #endif /* ndef GDAL_RAT_H_INCLUDED */
The GDALRasterAttributeTable (or RAT) class is used to encapsulate a table used to provide attribute ...
Definition: gdal_rat.h:46
virtual int GetValueAsInt(int iRow, int iField) const =0
Fetch field value as a integer.
Raster Attribute Table container.
Definition: gdal_rat.h:304
Document node structure.
Definition: cpl_minixml.h:66
Definitions for CPL mini XML Parser/Serializer.
virtual GDALRATFieldType GetTypeOfCol(int iCol) const =0
Fetch column type.
#define CPL_OVERRIDE
To be used in public headers only.
Definition: cpl_port.h:1054
GDALRATFieldType
Field type of raster attribute table.
Definition: gdal.h:1029
virtual void SetValue(int iRow, int iField, const char *pszValue)=0
Set field value from string.
virtual int GetRowOfValue(double dfValue) const
Get row for pixel value.
Definition: gdal_rat.cpp:361
virtual void SetRowCount(int iCount)
Set row count.
Definition: gdal_rat.cpp:315
virtual int GetColOfUsage(GDALRATFieldUsage eUsage) const =0
Fetch column index for given usage.
GDALRWFlag
Definition: gdal.h:105
virtual GDALRATFieldUsage GetUsageOfCol(int iCol) const =0
Fetch column usage value.
Convenient string class based on std::string.
Definition: cpl_string.h:363
virtual GDALDefaultRasterAttributeTable * Clone() const =0
Copy Raster Attribute Table.
virtual int GetRowCount() const =0
Fetch row count.
virtual int GetLinearBinning(double *pdfRow0Min, double *pdfBinSize) const
Get linear binning information.
Definition: gdal_rat.cpp:530
virtual int ChangesAreWrittenToFile()=0
Determine whether changes made to this RAT are reflected directly in the dataset. ...
virtual CPLErr SetLinearBinning(double dfRow0Min, double dfBinSize)
Set linear binning information.
Definition: gdal_rat.cpp:486
virtual double GetValueAsDouble(int iRow, int iField) const =0
Fetch field value as a double.
virtual CPLErr CreateColumn(const char *pszFieldName, GDALRATFieldType eFieldType, GDALRATFieldUsage eFieldUsage)
Create new column.
Definition: gdal_rat.cpp:438
virtual const char * GetNameOfCol(int iCol) const =0
Fetch name of indicated column.
GDALRATFieldUsage
Field usage of raster attribute table.
Definition: gdal.h:1036
virtual int GetColumnCount() const =0
Fetch table column count.
virtual const char * GetValueAsString(int iRow, int iField) const =0
Fetch field value as a string.
A color table / palette.
Definition: gdal_priv.h:747
CPLErr
Error category.
Definition: cpl_error.h:52

Generated for GDAL by doxygen 1.8.8.