1 /****************************************************************************** 2 * $Id: gdal_rat.h 10645 2007-01-18 02:22:39Z warmerdam $ 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 "../port/cpl_minixml.h" 34 35 /************************************************************************/ 36 /* GDALRasterAttributeField */ 37 /* */ 38 /* (private) */ 39 /************************************************************************/ 40 41 class GDALRasterAttributeField 42 { 43 public: 44 CPLString sName; 45 46 GDALRATFieldType eType; 47 48 GDALRATFieldUsage eUsage; 49 50 std::vector<GInt32> anValues; 51 std::vector<double> adfValues; 52 std::vector<CPLString> aosValues; 53 }; 54 55 /************************************************************************/ 56 /* GDALRasterAttributeTable */ 57 /************************************************************************/ 58 59 //! Raster Attribute Table container. 60 61 class CPL_DLL GDALRasterAttributeTable 62 { 63 friend const char * CPL_STDCALL GDALRATGetNameOfCol( GDALRasterAttributeTableH, int ); 64 friend const char * CPL_STDCALL GDALRATGetValueAsString( GDALRasterAttributeTableH, int, int ); 65 66 private: 67 std::vector<GDALRasterAttributeField> aoFields; 68 69 int bLinearBinning; 70 double dfRow0Min; 71 double dfBinSize; 72 73 void AnalyseColumns(); 74 int bColumnsAnalysed; 75 int nMinCol; 76 int nMaxCol; 77 78 int nRowCount; 79 80 CPLString osWorkingResult; 81 82 public: 83 GDALRasterAttributeTable(); 84 GDALRasterAttributeTable(const GDALRasterAttributeTable&); 85 ~GDALRasterAttributeTable(); 86 87 GDALRasterAttributeTable *Clone() const; 88 89 int GetColumnCount() const; 90 91 const char *GetNameOfCol( int ) const; 92 GDALRATFieldUsage GetUsageOfCol( int ) const; 93 GDALRATFieldType GetTypeOfCol( int ) const; 94 95 int GetColOfUsage( GDALRATFieldUsage ) const; 96 97 int GetRowCount() const; 98 99 const char *GetValueAsString( int iRow, int iField ) const; 100 int GetValueAsInt( int iRow, int iField ) const; 101 double GetValueAsDouble( int iRow, int iField ) const; 102 103 void SetValue( int iRow, int iField, const char *pszValue ); 104 void SetValue( int iRow, int iField, double dfValue); 105 void SetValue( int iRow, int iField, int nValue ); 106 void SetRowCount( int iCount ); 107 108 int GetRowOfValue( double dfValue ) const; 109 int GetRowOfValue( int nValue ) const; 110 int GetColorOfValue( double dfValue, GDALColorEntry *psEntry ) const; 111 112 double GetRowMin( int iRow ) const; 113 double GetRowMax( int iRow ) const; 114 115 CPLErr CreateColumn( const char *pszFieldName, 116 GDALRATFieldType eFieldType, 117 GDALRATFieldUsage eFieldUsage ); 118 CPLErr SetLinearBinning( double dfRow0Min, double dfBinSize ); 119 int GetLinearBinning( double *pdfRow0Min, double *pdfBinSize ) const; 120 121 CPLXMLNode *Serialize() const; 122 CPLErr XMLInit( CPLXMLNode *, const char * ); 123 124 CPLErr InitializeFromColorTable( const GDALColorTable * ); 125 GDALColorTable *TranslateToColorTable( int nEntryCount = -1 ); 126 127 void DumpReadable( FILE * = NULL ); 128 }; 129 130 #endif /* ndef GDAL_RAT_H_INCLUDED */ 131