GDAL
|
00001 /****************************************************************************** 00002 * $Id: gdal_rat.h 29243 2015-05-24 15:53:26Z rouault $ 00003 * 00004 * Project: GDAL Core 00005 * Purpose: GDALRasterAttributeTable class declarations. 00006 * Author: Frank Warmerdam, warmerdam@pobox.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com> 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a 00012 * copy of this software and associated documentation files (the "Software"), 00013 * to deal in the Software without restriction, including without limitation 00014 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00015 * and/or sell copies of the Software, and to permit persons to whom the 00016 * Software is furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included 00019 * in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00022 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00024 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00026 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00027 * DEALINGS IN THE SOFTWARE. 00028 ****************************************************************************/ 00029 00030 #ifndef GDAL_RAT_H_INCLUDED 00031 #define GDAL_RAT_H_INCLUDED 00032 00033 #include "cpl_minixml.h" 00034 00035 // Clone and Serialize are allowed to fail if GetRowCount()*GetColCount() greater 00036 // than this number 00037 #define RAT_MAX_ELEM_FOR_CLONE 1000000 00038 00039 /************************************************************************/ 00040 /* GDALRasterAttributeTable */ 00041 /************************************************************************/ 00042 00044 class GDALDefaultRasterAttributeTable; 00045 00046 class CPL_DLL GDALRasterAttributeTable 00047 { 00048 public: 00049 virtual ~GDALRasterAttributeTable(); 00062 virtual GDALDefaultRasterAttributeTable *Clone() const = 0; 00063 00071 virtual int GetColumnCount() const = 0; 00072 00082 virtual const char *GetNameOfCol( int ) const = 0; 00083 00093 virtual GDALRATFieldUsage GetUsageOfCol( int ) const = 0; 00094 00104 virtual GDALRATFieldType GetTypeOfCol( int ) const = 0; 00105 00118 virtual int GetColOfUsage( GDALRATFieldUsage ) const = 0; 00119 00127 virtual int GetRowCount() const = 0; 00128 00146 virtual const char *GetValueAsString( int iRow, int iField ) const = 0; 00147 00162 virtual int GetValueAsInt( int iRow, int iField ) const = 0; 00163 00178 virtual double GetValueAsDouble( int iRow, int iField ) const = 0; 00179 00193 virtual void SetValue( int iRow, int iField, const char *pszValue ) = 0; 00194 00208 virtual void SetValue( int iRow, int iField, int nValue ) = 0; 00209 00223 virtual void SetValue( int iRow, int iField, double dfValue) = 0; 00224 00234 virtual int ChangesAreWrittenToFile() = 0; 00235 00236 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, double *pdfData); 00237 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, int *pnData); 00238 virtual CPLErr ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, char **papszStrList); 00239 00240 virtual void SetRowCount( int iCount ); 00241 virtual int GetRowOfValue( double dfValue ) const; 00242 virtual int GetRowOfValue( int nValue ) const; 00243 00244 virtual CPLErr CreateColumn( const char *pszFieldName, 00245 GDALRATFieldType eFieldType, 00246 GDALRATFieldUsage eFieldUsage ); 00247 virtual CPLErr SetLinearBinning( double dfRow0Min, double dfBinSize ); 00248 virtual int GetLinearBinning( double *pdfRow0Min, double *pdfBinSize ) const; 00249 00256 virtual CPLXMLNode *Serialize() const; 00257 virtual void *SerializeJSON() const; 00258 virtual CPLErr XMLInit( CPLXMLNode *, const char * ); 00259 00260 virtual CPLErr InitializeFromColorTable( const GDALColorTable * ); 00261 virtual GDALColorTable *TranslateToColorTable( int nEntryCount = -1 ); 00262 00263 virtual void DumpReadable( FILE * = NULL ); 00264 }; 00265 00266 /************************************************************************/ 00267 /* GDALRasterAttributeField */ 00268 /* */ 00269 /* (private) */ 00270 /************************************************************************/ 00271 00272 class GDALRasterAttributeField 00273 { 00274 public: 00275 CPLString sName; 00276 00277 GDALRATFieldType eType; 00278 00279 GDALRATFieldUsage eUsage; 00280 00281 std::vector<GInt32> anValues; 00282 std::vector<double> adfValues; 00283 std::vector<CPLString> aosValues; 00284 }; 00285 00286 /************************************************************************/ 00287 /* GDALDefaultRasterAttributeTable */ 00288 /************************************************************************/ 00289 00291 00292 class CPL_DLL GDALDefaultRasterAttributeTable : public GDALRasterAttributeTable 00293 { 00294 private: 00295 std::vector<GDALRasterAttributeField> aoFields; 00296 00297 int bLinearBinning; 00298 double dfRow0Min; 00299 double dfBinSize; 00300 00301 void AnalyseColumns(); 00302 int bColumnsAnalysed; 00303 int nMinCol; 00304 int nMaxCol; 00305 00306 int nRowCount; 00307 00308 CPLString osWorkingResult; 00309 00310 public: 00311 GDALDefaultRasterAttributeTable(); 00312 GDALDefaultRasterAttributeTable(const GDALDefaultRasterAttributeTable&); 00313 ~GDALDefaultRasterAttributeTable(); 00314 00315 GDALDefaultRasterAttributeTable *Clone() const; 00316 00317 virtual int GetColumnCount() const; 00318 00319 virtual const char *GetNameOfCol( int ) const; 00320 virtual GDALRATFieldUsage GetUsageOfCol( int ) const; 00321 virtual GDALRATFieldType GetTypeOfCol( int ) const; 00322 00323 virtual int GetColOfUsage( GDALRATFieldUsage ) const; 00324 00325 virtual int GetRowCount() const; 00326 00327 virtual const char *GetValueAsString( int iRow, int iField ) const; 00328 virtual int GetValueAsInt( int iRow, int iField ) const; 00329 virtual double GetValueAsDouble( int iRow, int iField ) const; 00330 00331 virtual void SetValue( int iRow, int iField, const char *pszValue ); 00332 virtual void SetValue( int iRow, int iField, double dfValue); 00333 virtual void SetValue( int iRow, int iField, int nValue ); 00334 00335 virtual int ChangesAreWrittenToFile(); 00336 virtual void SetRowCount( int iCount ); 00337 00338 virtual int GetRowOfValue( double dfValue ) const; 00339 virtual int GetRowOfValue( int nValue ) const; 00340 00341 virtual CPLErr CreateColumn( const char *pszFieldName, 00342 GDALRATFieldType eFieldType, 00343 GDALRATFieldUsage eFieldUsage ); 00344 virtual CPLErr SetLinearBinning( double dfRow0Min, double dfBinSize ); 00345 virtual int GetLinearBinning( double *pdfRow0Min, double *pdfBinSize ) const; 00346 00347 }; 00348 00349 #endif /* ndef GDAL_RAT_H_INCLUDED */