Changeset 11455
- Timestamp:
- 05/10/07 13:58:36 (2 years ago)
- Files:
-
- sandbox/warmerdam/1.4-esri/gdal/frmts/idrisi/IdrisiDataset.cpp (modified) (106 diffs)
- sandbox/warmerdam/1.4-esri/gdal/gcore/gdal_priv.h (modified) (1 diff)
- sandbox/warmerdam/1.4-esri/gdal/gcore/gdal_version.h (modified) (2 diffs)
- sandbox/warmerdam/1.4-esri/gdal/gcore/gdalcolortable.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/warmerdam/1.4-esri/gdal/frmts/idrisi/IdrisiDataset.cpp
r10646 r11455 1 1 /***************************************************************************** 2 * $Id$3 *4 * Project: Idrisi Raster Image File Driver5 * Purpose: Read/write Idrisi Raster Image Format RST6 * Author: Ivan Lucena, ivan@ilucena.net 7 *8 ******************************************************************************9 * Copyright (c) 2006, Ivan Lucena10 *11 * Permission is hereby granted, free of charge, to any person obtaining a12 * copy of this software and associated documentation files (the "Software"),13 * to deal in the Software without restriction, including without limitation14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,15 * and/or sell copies of the Software, and to permit persons to whom the16 * Software is furnished to do so, subject to the following conditions:17 *18 * The above copyright notice and this permission notice shall be included19 * in all copies or substantial portions of the Software.20 *21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER27 * DEALINGS IN THE SOFTWARE.28 ****************************************************************************/2 * $Id$ 3 * 4 * Project: Idrisi Raster Image File Driver 5 * Purpose: Read/write Idrisi Raster Image Format RST 6 * Author: Ivan Lucena, ivan.lucena@pmldnet.com 7 * 8 ****************************************************************************** 9 * Copyright( c ) 2006, Ivan Lucena 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 29 30 30 #include "gdal_priv.h" … … 34 34 #include "ogr_spatialref.h" 35 35 #include "gdal_pam.h" 36 #include "gdal_rat.h" 36 37 #include "gdal_alg.h" 37 38 38 CPL_CVSID( "$Id$");39 CPL_CVSID( "$Id$" ); 39 40 40 41 CPL_C_START 41 void GDALRegister_IDRISI( void);42 void GDALRegister_IDRISI( void); 42 43 CPL_C_END 43 44 … … 59 60 60 61 //----- field names on rdc file: 61 #define rdcFILE_FORMAT "file format "62 #define rdcFILE_TITLE "file title "63 #define rdcDATA_TYPE "data type "64 #define rdcFILE_TYPE "file type "65 #define rdcCOLUMNS "columns "66 #define rdcROWS "rows "67 #define rdcREF_SYSTEM "ref. system "68 #define rdcREF_UNITS "ref. units "69 #define rdcUNIT_DIST "unit dist. "70 #define rdcMIN_X "min. X "71 #define rdcMAX_X "max. X "72 #define rdcMIN_Y "min. Y "73 #define rdcMAX_Y "max. Y "74 #define rdcPOSN_ERROR "pos'n error "75 #define rdcRESOLUTION "resolution "76 #define rdcMIN_VALUE "min. value "77 #define rdcMAX_VALUE "max. value "78 #define rdcDISPLAY_MIN "display min "79 #define rdcDISPLAY_MAX "display max "80 #define rdcVALUE_UNITS "value units "81 #define rdcVALUE_ERROR "value error "82 #define rdcFLAG_VALUE "flag value "83 #define rdcFLAG_DEFN "flag def'n "84 #define rdcFLAG_DEFN2 "flag def`n "85 #define rdcLEGEND_CATS "legend cats "86 #define rdcLINEAGES "lineage "87 #define rdcCOMMENTS "comment "88 #define rdcCODE_N "code %6d "62 #define rdcFILE_FORMAT "file format " 63 #define rdcFILE_TITLE "file title " 64 #define rdcDATA_TYPE "data type " 65 #define rdcFILE_TYPE "file type " 66 #define rdcCOLUMNS "columns " 67 #define rdcROWS "rows " 68 #define rdcREF_SYSTEM "ref. system " 69 #define rdcREF_UNITS "ref. units " 70 #define rdcUNIT_DIST "unit dist. " 71 #define rdcMIN_X "min. X " 72 #define rdcMAX_X "max. X " 73 #define rdcMIN_Y "min. Y " 74 #define rdcMAX_Y "max. Y " 75 #define rdcPOSN_ERROR "pos'n error " 76 #define rdcRESOLUTION "resolution " 77 #define rdcMIN_VALUE "min. value " 78 #define rdcMAX_VALUE "max. value " 79 #define rdcDISPLAY_MIN "display min " 80 #define rdcDISPLAY_MAX "display max " 81 #define rdcVALUE_UNITS "value units " 82 #define rdcVALUE_ERROR "value error " 83 #define rdcFLAG_VALUE "flag value " 84 #define rdcFLAG_DEFN "flag def'n " 85 #define rdcFLAG_DEFN2 "flag def`n " 86 #define rdcLEGEND_CATS "legend cats " 87 #define rdcLINEAGES "lineage " 88 #define rdcCOMMENTS "comment " 89 #define rdcCODE_N "code %6d " 89 90 90 91 //----- ".ref" file field names: … … 118 119 #define rstPLANE "plane" 119 120 #define rstUTM "utm-%d%c" 120 #define rstSPC "spc%2d%2s%d"121 122 //----- palette file (.smp) header size:123 #define smpHEADERSIZE 18121 #define rstSPC "spc%2d%2s%d" 122 123 //----- palette file( .smp ) header size: 124 #define smpHEADERSIZE 18 124 125 125 126 //----- check if file exists: 126 bool FileExists( const char *pszFilename);127 bool FileExists( const char *pszPath ); 127 128 128 129 //----- Reference Table 129 130 struct ReferenceTab { 130 int nCode;131 char *pszName;131 int nCode; 132 const char *pszName; 132 133 }; 133 134 134 135 //----- USA State's reference table to USGS PCS Code 135 136 static ReferenceTab aoUSStateTable[] = { 136 {101, "al"},137 {201, "az"},138 {301, "ar"},139 {401, "ca"},140 {501, "co"},141 {600, "ct"},142 {700, "de"},143 {901, "fl"},144 {1001, "ga"},145 {1101, "id"},146 {1201, "il"},147 {1301, "in"},148 {1401, "ia"},149 {1501, "ks"},150 {1601, "ky"},151 {1701, "la"},152 {1801, "me"},153 {1900, "md"},154 {2001, "ma"},155 {2111, "mi"},156 {2201, "mn"},157 {2301, "ms"},158 {2401, "mo"},159 {2500, "mt"},160 {2600, "ne"},161 {2701, "nv"},162 {2800, "nh"},163 {2900, "nj"},164 {3001, "nm"},165 {3101, "ny"},166 {3200, "nc"},167 {3301, "nd"},168 {3401, "oh"},169 {3501, "ok"},170 {3601, "or"},171 {3701, "pa"},172 {3800, "ri"},173 {3900, "sc"},174 {4001, "sd"},175 {4100, "tn"},176 {4201, "tx"},177 {4301, "ut"},178 {4400, "vt"},179 {4501, "va"},180 {4601, "wa"},181 {4701, "wv"},182 {4801, "wv"},183 {4901, "wy"},184 {5001, "ak"},185 {5101, "hi"},186 {5200, "pr"}137 {101, "al"}, 138 {201, "az"}, 139 {301, "ar"}, 140 {401, "ca"}, 141 {501, "co"}, 142 {600, "ct"}, 143 {700, "de"}, 144 {901, "fl"}, 145 {1001, "ga"}, 146 {1101, "id"}, 147 {1201, "il"}, 148 {1301, "in"}, 149 {1401, "ia"}, 150 {1501, "ks"}, 151 {1601, "ky"}, 152 {1701, "la"}, 153 {1801, "me"}, 154 {1900, "md"}, 155 {2001, "ma"}, 156 {2111, "mi"}, 157 {2201, "mn"}, 158 {2301, "ms"}, 159 {2401, "mo"}, 160 {2500, "mt"}, 161 {2600, "ne"}, 162 {2701, "nv"}, 163 {2800, "nh"}, 164 {2900, "nj"}, 165 {3001, "nm"}, 166 {3101, "ny"}, 167 {3200, "nc"}, 168 {3301, "nd"}, 169 {3401, "oh"}, 170 {3501, "ok"}, 171 {3601, "or"}, 172 {3701, "pa"}, 173 {3800, "ri"}, 174 {3900, "sc"}, 175 {4001, "sd"}, 176 {4100, "tn"}, 177 {4201, "tx"}, 178 {4301, "ut"}, 179 {4400, "vt"}, 180 {4501, "va"}, 181 {4601, "wa"}, 182 {4701, "wv"}, 183 {4801, "wv"}, 184 {4901, "wy"}, 185 {5001, "ak"}, 186 {5101, "hi"}, 187 {5200, "pr"} 187 188 }; 188 #define US_STATE_COUNT ( sizeof(aoUSStateTable) / sizeof(ReferenceTab))189 #define US_STATE_COUNT ( sizeof( aoUSStateTable ) / sizeof( ReferenceTab ) ) 189 190 190 191 //----- Get the Code of a US State 191 int GetStateCode (const char *pszState);192 int GetStateCode ( const char *pszState ); 192 193 193 194 //----- Get the state name of a Code 194 const char *GetStateName( int nCode);195 const char *GetStateName( int nCode ); 195 196 196 197 //----- Conversion Table definition 197 198 struct ConvertionTab { 198 char *pszName;199 const char *pszName; 199 200 int nDefault; 200 201 double dfConv; … … 219 220 #define LINEAR_UNITS_COUNT (sizeof(aoLinearUnitsConv) / sizeof(ConvertionTab)) 220 221 221 //----- Get the index of a given linear unit s222 int GetUnitIndex( const char *pszUnitName);222 //----- Get the index of a given linear unit 223 int GetUnitIndex( const char *pszUnitName ); 223 224 224 225 //----- Get the defaut name 225 const char *GetUnitDefault( const char *pszUnitName);226 const char *GetUnitDefault( const char *pszUnitName ); 226 227 227 228 //----- Classes pre-definition: … … 230 231 231 232 // ---------------------------------------------------------------------------- 232 // Idrisi GDALDataset233 // Idrisi GDALDataset 233 234 // ---------------------------------------------------------------------------- 234 235 235 236 class IdrisiDataset : public GDALPamDataset 236 237 { 237 friend class IdrisiRasterBand;238 friend class IdrisiRasterBand; 238 239 239 240 private: 240 FILE *fp;241 242 char *pszFilename;243 char *pszDocFilename;244 char **papszRDC;245 double adfGeoTransform[6];246 247 char *pszProjection;248 char **papszCategories;249 char *pszUnitType;250 251 CPLErr GeoReference2Wkt( const char *pszRefSystem,252 const char *pszRefUnits,253 char **pszProjString);254 255 CPLErr Wkt2GeoReference( const char *pszProjString,256 const char **pszRefSystem,257 const char **pszRefUnit);241 FILE *fp; 242 243 char *pszFilename; 244 char *pszDocFilename; 245 char **papszRDC; 246 double adfGeoTransform[6]; 247 248 char *pszProjection; 249 char **papszCategories; 250 char *pszUnitType; 251 252 CPLErr GeoReference2Wkt( const char *pszRefSystem, 253 const char *pszRefUnits, 254 char **pszProjString ); 255 256 CPLErr Wkt2GeoReference( const char *pszProjString, 257 const char **pszRefSystem, 258 const char **pszRefUnit ); 258 259 259 260 protected: 260 GDALColorTable *poColorTable;261 GDALColorTable *poColorTable; 261 262 262 263 public: 263 IdrisiDataset();264 ~IdrisiDataset();265 266 static GDALDataset *Open(GDALOpenInfo *poOpenInfo);267 static GDALDataset *Create(const char *pszFilename,268 int nXSize,269 int nYSize,270 int nBands,271 GDALDataType eType,272 char **papszOptions);273 static GDALDataset *CreateCopy(const char *pszFilename,274 GDALDataset *poSrcDS,275 int bStrict,276 char **papszOptions,277 GDALProgressFunc pfnProgress,278 void * pProgressData);279 280 virtual CPLErr GetGeoTransform(double *padfTransform);281 virtual CPLErr SetGeoTransform(double *padfTransform);282 virtual const char *GetProjectionRef(void);283 virtual CPLErr SetProjection(const char *pszProjString);264 IdrisiDataset(); 265 ~IdrisiDataset(); 266 267 static GDALDataset *Open( GDALOpenInfo *poOpenInfo ); 268 static GDALDataset *Create( const char *pszFilename, 269 int nXSize, 270 int nYSize, 271 int nBands, 272 GDALDataType eType, 273 char **papszOptions ); 274 static GDALDataset *CreateCopy( const char *pszFilename, 275 GDALDataset *poSrcDS, 276 int bStrict, 277 char **papszOptions, 278 GDALProgressFunc pfnProgress, 279 void * pProgressData ); 280 281 virtual CPLErr GetGeoTransform( double *padfTransform ); 282 virtual CPLErr SetGeoTransform( double *padfTransform ); 283 virtual const char *GetProjectionRef( void ); 284 virtual CPLErr SetProjection( const char *pszProjString ); 284 285 }; 285 286 286 287 // ---------------------------------------------------------------------------- 287 // Idrisi GDALPamRasterBand288 // Idrisi GDALPamRasterBand 288 289 // ---------------------------------------------------------------------------- 289 290 290 291 class IdrisiRasterBand : public GDALPamRasterBand 291 292 { 292 friend class IdrisiDataset; 293 friend class IdrisiDataset; 294 295 GDALRasterAttributeTable *poDefaultRAT; 293 296 294 297 private: 295 intnRecordSize;296 GByte *pabyScanLine;298 int nRecordSize; 299 GByte *pabyScanLine; 297 300 298 301 public: 299 IdrisiRasterBand(IdrisiDataset *poDS, 300 int nBand, 301 GDALDataType eDataType); 302 ~IdrisiRasterBand(); 303 304 virtual double GetNoDataValue(int *pbSuccess = NULL); 305 virtual double GetMinimum(int *pbSuccess = NULL); 306 virtual double GetMaximum(int *pbSuccess = NULL); 307 virtual CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage); 308 virtual CPLErr IWriteBlock(int nBlockXOff, int nBlockYOff, void *pImage); 309 virtual GDALColorTable *GetColorTable(); 310 virtual GDALColorInterp GetColorInterpretation(); 311 virtual char **GetCategoryNames(); 312 virtual const char *GetUnitType(); 313 314 virtual CPLErr SetCategoryNames(char **papszCategoryNames); 315 virtual CPLErr SetNoDataValue(double dfNoDataValue); 316 virtual CPLErr SetColorTable(GDALColorTable *poColorTable); 317 virtual CPLErr SetUnitType(const char *pszUnitType); 318 virtual CPLErr SetStatistics(double dfMin, double dfMax, 319 double dfMean, double dfStdDev); 302 IdrisiRasterBand( IdrisiDataset *poDS, 303 int nBand, 304 GDALDataType eDataType ); 305 ~IdrisiRasterBand(); 306 307 virtual double GetNoDataValue( int *pbSuccess = NULL ); 308 virtual double GetMinimum( int *pbSuccess = NULL ); 309 virtual double GetMaximum( int *pbSuccess = NULL ); 310 virtual CPLErr IReadBlock( int nBlockXOff, int nBlockYOff, void *pImage ); 311 virtual CPLErr IWriteBlock( int nBlockXOff, int nBlockYOff, void *pImage ); 312 virtual GDALColorTable *GetColorTable(); 313 virtual GDALColorInterp GetColorInterpretation(); 314 virtual char **GetCategoryNames(); 315 virtual const char *GetUnitType(); 316 317 virtual CPLErr SetCategoryNames( char **papszCategoryNames ); 318 virtual CPLErr SetNoDataValue( double dfNoDataValue ); 319 virtual CPLErr SetColorTable( GDALColorTable *poColorTable ); 320 virtual CPLErr SetUnitType( const char *pszUnitType ); 321 virtual CPLErr SetStatistics( double dfMin, double dfMax, 322 double dfMean, double dfStdDev ); 323 virtual const GDALRasterAttributeTable *GetDefaultRAT(); 324 virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * ); 320 325 }; 321 326 322 327 // ------------------------------------------------------------------------ // 323 // Implementation of IdrisiDataset//328 // Implementation of IdrisiDataset // 324 329 // ------------------------------------------------------------------------ // 325 330 … … 330 335 IdrisiDataset::IdrisiDataset() 331 336 { 332 pszFilename = NULL;333 fp = NULL;334 papszRDC = NULL;335 pszDocFilename = NULL;336 pszProjection = NULL;337 poColorTable = new GDALColorTable();338 papszCategories = NULL;339 pszUnitType = NULL;340 341 adfGeoTransform[0] = 0.0;342 adfGeoTransform[1] = 1.0;343 adfGeoTransform[2] = 0.0;344 adfGeoTransform[3] = 0.0;345 adfGeoTransform[4] = 0.0;346 adfGeoTransform[5] = 1.0;337 pszFilename = NULL; 338 fp = NULL; 339 papszRDC = NULL; 340 pszDocFilename = NULL; 341 pszProjection = NULL; 342 poColorTable = new GDALColorTable(); 343 papszCategories = NULL; 344 pszUnitType = NULL; 345 346 adfGeoTransform[0] = 0.0; 347 adfGeoTransform[1] = 1.0; 348 adfGeoTransform[2] = 0.0; 349 adfGeoTransform[3] = 0.0; 350 adfGeoTransform[4] = 0.0; 351 adfGeoTransform[5] = 1.0; 347 352 } 348 353 … … 353 358 IdrisiDataset::~IdrisiDataset() 354 359 { 355 FlushCache();356 357 if (papszRDC != NULL)358 {359 if (eAccess == GA_Update)360 {361 CSLSetNameValueSeparator(papszRDC, ": ");362 CSLSave(papszRDC, pszDocFilename);363 }364 CSLDestroy(papszRDC);365 }366 367 if (poColorTable)368 delete poColorTable;369 370 CPLFree(pszFilename);371 CPLFree(pszDocFilename);372 CPLFree(pszProjection);373 CSLDestroy(papszCategories);374 CPLFree(pszUnitType);375 376 if (fp != NULL)377 VSIFCloseL(fp);360 FlushCache(); 361 362 if( papszRDC != NULL ) 363 { 364 if( eAccess == GA_Update ) 365 { 366 CSLSetNameValueSeparator( papszRDC, ": " ); 367 CSLSave( papszRDC, pszDocFilename ); 368 } 369 CSLDestroy( papszRDC ); 370 } 371 372 if( poColorTable ) 373 delete poColorTable; 374 375 CPLFree( pszFilename ); 376 CPLFree( pszDocFilename ); 377 CPLFree( pszProjection ); 378 CSLDestroy( papszCategories ); 379 CPLFree( pszUnitType ); 380 381 if( fp != NULL ) 382 VSIFCloseL( fp ); 378 383 } 379 384 … … 382 387 /************************************************************************/ 383 388 384 GDALDataset *IdrisiDataset::Open( GDALOpenInfo *poOpenInfo)389 GDALDataset *IdrisiDataset::Open( GDALOpenInfo *poOpenInfo ) 385 390 { 386 if ((poOpenInfo->fp == NULL) ||387 ( EQUAL(CPLGetExtension(poOpenInfo->pszFilename), extRST) == FALSE))391 if( ( poOpenInfo->fp == NULL ) || 392 ( EQUAL( CPLGetExtension( poOpenInfo->pszFilename ), extRST ) == FALSE ) ) 388 393 return NULL; 389 394 … … 392 397 // -------------------------------------------------------------------- 393 398 394 const char *pszLDocFilename = 395 CPLResetExtension(poOpenInfo->pszFilename, extRDC); 396 397 char **papszLRDC = CSLLoad(pszLDocFilename); 398 399 CSLSetNameValueSeparator(papszLRDC, ":"); 400 401 const char *pszVersion = CSLFetchNameValue(papszLRDC, rdcFILE_FORMAT); 402 403 if( pszVersion == NULL || !EQUAL(pszVersion, rstVERSION) ) 404 { 405 CSLDestroy(papszLRDC); 399 const char *pszLDocFilename = CPLResetExtension( poOpenInfo->pszFilename, extRDC ); 400 401 if( ! FileExists( pszLDocFilename ) ) 402 { 403 return NULL; 404 } 405 406 char **papszLRDC = CSLLoad( pszLDocFilename ); 407 408 CSLSetNameValueSeparator( papszLRDC, ":" ); 409 410 const char *pszVersion = CSLFetchNameValue( papszLRDC, rdcFILE_FORMAT ); 411 412 if( pszVersion == NULL || !EQUAL( pszVersion, rstVERSION ) ) 413 { 414 CSLDestroy( papszLRDC ); 406 415 return NULL; 407 416 } … … 415 424 poDS = new IdrisiDataset(); 416 425 poDS->eAccess = poOpenInfo->eAccess; 417 poDS->pszFilename = CPLStrdup( poOpenInfo->pszFilename);418 419 if (poOpenInfo->eAccess == GA_ReadOnly )420 { 421 poDS->fp = VSIFOpenL( poDS->pszFilename, "rb");426 poDS->pszFilename = CPLStrdup( poOpenInfo->pszFilename ); 427 428 if( poOpenInfo->eAccess == GA_ReadOnly ) 429 { 430 poDS->fp = VSIFOpenL( poDS->pszFilename, "rb" ); 422 431 } 423 432 else 424 433 { 425 poDS->fp = VSIFOpenL( poDS->pszFilename, "r+b");426 } 427 428 if (poDS->fp == NULL)429 { 430 CSLDestroy( papszLRDC);434 poDS->fp = VSIFOpenL( poDS->pszFilename, "r+b" ); 435 } 436 437 if( poDS->fp == NULL ) 438 { 439 CSLDestroy( papszLRDC ); 431 440 return NULL; 432 441 } 433 442 434 poDS->pszDocFilename = CPLStrdup( pszLDocFilename);435 poDS->papszRDC = CSLDuplicate( papszLRDC);436 CSLDestroy( papszLRDC);443 poDS->pszDocFilename = CPLStrdup( pszLDocFilename ); 444 poDS->papszRDC = CSLDuplicate( papszLRDC ); 445 CSLDestroy( papszLRDC ); 437 446 438 447 // -------------------------------------------------------------------- … … 440 449 // -------------------------------------------------------------------- 441 450 442 poDS->nRasterXSize = atoi_nz( CSLFetchNameValue(poDS->papszRDC, rdcCOLUMNS));443 poDS->nRasterYSize = atoi_nz( CSLFetchNameValue(poDS->papszRDC, rdcROWS));451 poDS->nRasterXSize = atoi_nz( CSLFetchNameValue( poDS->papszRDC, rdcCOLUMNS ) ); 452 poDS->nRasterYSize = atoi_nz( CSLFetchNameValue( poDS->papszRDC, rdcROWS ) ); 444 453 445 454 // -------------------------------------------------------------------- … … 447 456 // -------------------------------------------------------------------- 448 457 449 const char *pszDataType = CSLFetchNameValue( poDS->papszRDC, rdcDATA_TYPE);450 451 if (EQUAL(pszDataType, rstBYTE))458 const char *pszDataType = CSLFetchNameValue( poDS->papszRDC, rdcDATA_TYPE ); 459 460 if( EQUAL( pszDataType, rstBYTE ) ) 452 461 { 453 462 poDS->nBands = 1; 454 poDS->SetBand( 1, new IdrisiRasterBand(poDS, 1, GDT_Byte));455 } 456 if (EQUAL(pszDataType, rstINTEGER))463 poDS->SetBand( 1, new IdrisiRasterBand( poDS, 1, GDT_Byte ) ); 464 } 465 if( EQUAL( pszDataType, rstINTEGER ) ) 457 466 { 458 467 poDS->nBands = 1; 459 poDS->SetBand( 1, new IdrisiRasterBand(poDS, 1, GDT_Int16));460 } 461 if (EQUAL(pszDataType, rstREAL))468 poDS->SetBand( 1, new IdrisiRasterBand( poDS, 1, GDT_Int16 ) ); 469 } 470 if( EQUAL( pszDataType, rstREAL ) ) 462 471 { 463 472 poDS->nBands = 1; 464 poDS->SetBand( 1, new IdrisiRasterBand(poDS, 1, GDT_Float32));465 } 466 if (EQUAL(pszDataType, rstRGB24))473 poDS->SetBand( 1, new IdrisiRasterBand( poDS, 1, GDT_Float32 ) ); 474 } 475 if( EQUAL( pszDataType, rstRGB24 ) ) 467 476 { 468 477 poDS->nBands = 3; 469 poDS->SetBand( 1, new IdrisiRasterBand(poDS, 1, GDT_Byte));470 poDS->SetBand( 2, new IdrisiRasterBand(poDS, 2, GDT_Byte));471 poDS->SetBand( 3, new IdrisiRasterBand(poDS, 3, GDT_Byte));478 poDS->SetBand( 1, new IdrisiRasterBand( poDS, 1, GDT_Byte ) ); 479 poDS->SetBand( 2, new IdrisiRasterBand( poDS, 2, GDT_Byte ) ); 480 poDS->SetBand( 3, new IdrisiRasterBand( poDS, 3, GDT_Byte ) ); 472 481 } 473 482 … … 476 485 // -------------------------------------------------------------------- 477 486 478 const char *pszMinX = CSLFetchNameValue( poDS->papszRDC, rdcMIN_X);479 480 if (strlen(pszMinX) > 0)487 const char *pszMinX = CSLFetchNameValue( poDS->papszRDC, rdcMIN_X ); 488 489 if( strlen( pszMinX ) > 0 ) 481 490 { 482 491 double dfMinX, dfMaxX, dfMinY, dfMaxY, dfUnit, dfXPixSz, dfYPixSz; 483 492 484 dfMinX = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcMIN_X));485 dfMaxX = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcMAX_X));486 dfMinY = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcMIN_Y));487 dfMaxY = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcMAX_Y));488 dfUnit = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcUNIT_DIST));493 dfMinX = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcMIN_X ) ); 494 dfMaxX = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcMAX_X ) ); 495 dfMinY = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcMIN_Y ) ); 496 dfMaxY = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcMAX_Y ) ); 497 dfUnit = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcUNIT_DIST ) ); 489 498 490 499 dfMinX = dfMinX * dfUnit; … … 493 502 dfMaxY = dfMaxY * dfUnit; 494 503 495 dfYPixSz = ( dfMinY - dfMaxY) / poDS->nRasterYSize;496 dfXPixSz = ( dfMaxX - dfMinX) / poDS->nRasterXSize;504 dfYPixSz = ( dfMinY - dfMaxY ) / poDS->nRasterYSize; 505 dfXPixSz = ( dfMaxX - dfMinX ) / poDS->nRasterXSize; 497 506 498 507 poDS->adfGeoTransform[0] = dfMinX; … … 508 517 // -------------------------------------------------------------------- 509 518 510 if (poDS->nBands != 3)511 { 512 const char *pszSMPFilename = CPLResetExtension( poDS->pszFilename, extSMP);519 if( poDS->nBands != 3 ) 520 { 521 const char *pszSMPFilename = CPLResetExtension( poDS->pszFilename, extSMP ); 513 522 FILE *fpSMP; 514 if ((fpSMP = VSIFOpenL(pszSMPFilename, "rb")) != NULL )515 { 516 double dfMaxValue = atof_nz( CSLFetchNameValue(poDS->papszRDC, rdcMAX_VALUE));517 VSIFSeekL( fpSMP, smpHEADERSIZE, SEEK_SET);523 if( ( fpSMP = VSIFOpenL( pszSMPFilename, "rb" ) ) != NULL ) 524 { 525 double dfMaxValue = atof_nz( CSLFetchNameValue( poDS->papszRDC, rdcMAX_VALUE ) ); 526 VSIFSeekL( fpSMP, smpHEADERSIZE, SEEK_SET ); 518 527 GDALColorEntry oEntry; 519 528 unsigned char aucRGB[3]; 520 529 int i = 0; 521 while ((VSIFReadL(&aucRGB, sizeof(aucRGB), 1, fpSMP)) && (i <= dfMaxValue))530 while( ( VSIFReadL( &aucRGB, sizeof( aucRGB ), 1, fpSMP ) ) &&( i <= dfMaxValue ) ) 522 531 { 523 532 oEntry.c1 = (short) aucRGB[0]; … … 525 534 oEntry.c3 = (short) aucRGB[2]; 526 535 oEntry.c4 = (short) 255; 527 poDS->poColorTable->SetColorEntry( i, &oEntry);536 poDS->poColorTable->SetColorEntry( i, &oEntry ); 528 537 i++; 529 538 } 530 VSIFCloseL( fpSMP);539 VSIFCloseL( fpSMP ); 531 540 } 532 541 } … … 536 545 // -------------------------------------------------------------------- 537 546 538 const char *pszValueUnit = CSLFetchNameValue( poDS->papszRDC, rdcVALUE_UNITS);539 540 if (pszValueUnit == NULL)541 poDS->pszUnitType = CPLStrdup( "unspecified");547 const char *pszValueUnit = CSLFetchNameValue( poDS->papszRDC, rdcVALUE_UNITS ); 548 549 if( pszValueUnit == NULL ) 550 poDS->pszUnitType = CPLStrdup( "unspecified" ); 542 551 else 543 552 { 544 if (EQUALN(pszValueUnit, "meter", 4))545 { 546 poDS->pszUnitType = CPLStrdup( "m");547 } 548 else if (EQUALN(pszValueUnit, "feet", 4))549 { 550 poDS->pszUnitType = CPLStrdup( "ft");553 if( EQUALN( pszValueUnit, "meter", 4 ) ) 554 { 555 poDS->pszUnitType = CPLStrdup( "m" ); 556 } 557 else if( EQUALN( pszValueUnit, "feet", 4 ) ) 558 { 559 poDS->pszUnitType = CPLStrdup( "ft" ); 551 560 } 552 561 else 553 poDS->pszUnitType = CPLStrdup( pszValueUnit);562 poDS->pszUnitType = CPLStrdup( pszValueUnit ); 554 563 } 555 564 … … 558 567 // -------------------------------------------------------------------- 559 568 560 int nCatCount = atoi_nz( CSLFetchNameValue(poDS->papszRDC, rdcLEGEND_CATS));561 562 if (nCatCount > 0)569 int nCatCount = atoi_nz( CSLFetchNameValue( poDS->papszRDC, rdcLEGEND_CATS ) ); 570 571 if( nCatCount > 0 ) 563 572 { 564 573 // ---------------------------------------------------------------- … … 569 578 int nCount = 0; 570 579 int nLine = -1; 571 for (int i = 0; (i < CSLCount(poDS->papszRDC)) && (nLine == -1); i++)572 if (EQUALN(poDS->papszRDC[i], rdcLEGEND_CATS, 11))580 for( int i = 0;( i < CSLCount( poDS->papszRDC ) ) &&( nLine == -1 ); i++ ) 581 if( EQUALN( poDS->papszRDC[i], rdcLEGEND_CATS, 11 ) ) 573 582 nLine = i; 574 if (nLine > 0)575 { 576 sscanf( poDS->papszRDC[++nLine], rdcCODE_N, &nCode);577 for (int i = 0; (i < 255) && (nCount < nCatCount); i++)583 if( nLine > 0 ) 584 { 585 sscanf( poDS->papszRDC[++nLine], rdcCODE_N, &nCode ); 586 for( int i = 0;( i < 255 ) &&( nCount < nCatCount ); i++ ) 578 587 { 579 if (i == nCode)588 if( i == nCode ) 580 589 { 581 poDS->papszCategories = CSLAddString(poDS->papszCategories, 582 CPLParseNameValue(poDS->papszRDC[nLine], NULL)); 590 poDS->papszCategories = 591 CSLAddString( poDS->papszCategories, 592 CPLParseNameValue( poDS->papszRDC[nLine], NULL ) ); 583 593 nCount++; 584 if (nCount < nCatCount)585 sscanf( poDS->papszRDC[++nLine], rdcCODE_N, &nCode);594 if( nCount < nCatCount ) 595 sscanf( poDS->papszRDC[++nLine], rdcCODE_N, &nCode ); 586 596 } 587 597 else 588 poDS->papszCategories = CSLAddString( poDS->papszCategories, "");598 poDS->papszCategories = CSLAddString( poDS->papszCategories, "" ); 589 599 } 590 600 } 601 } 602 603 /* -------------------------------------------------------------------- */ 604 /* Automatic Generated Color Table */ 605 /* -------------------------------------------------------------------- */ 606 607 if( poDS->papszCategories != NULL && 608 ( poDS->poColorTable->GetColorEntryCount() == 0 ) ) 609 { 610 int nEntryCount = CSLCount(poDS->papszCategories); 611 612 GDALColorEntry sFromColor; 613 sFromColor.c1 = (short) ( 255 ); 614 sFromColor.c2 = (short) ( 0 ); 615 sFromColor.c3 = (short) ( 0 ); 616 sFromColor.c4 = (short) ( 255 ); 617 618 GDALColorEntry sToColor; 619 sToColor.c1 = (short) ( 0 ); 620 sToColor.c2 = (short) ( 0 ); 621 sToColor.c3 = (short) ( 255 ); 622 sToColor.c4 = (short) ( 255 ); 623 624 poDS->poColorTable->CreateColorRamp( 625 0, &sFromColor, ( nEntryCount - 1 ), &sToColor ); 591 626 } 592 627 … … 595 630 /* -------------------------------------------------------------------- */ 596 631 597 poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename);632 poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename ); 598 633 599 634 /* -------------------------------------------------------------------- */ … … 601 636 /* -------------------------------------------------------------------- */ 602 637 603 poDS->SetDescription( poOpenInfo->pszFilename);638 poDS->SetDescription( poOpenInfo->pszFilename ); 604 639 poDS->TryLoadXML(); 605 640 606 return (poDS);641 return( poDS ); 607 642 } 608 643 … … 611 646 /************************************************************************/ 612 647 613 GDALDataset *IdrisiDataset::Create( const char *pszFilename,614 int nXSize,615 int nYSize,616 int nBands,617 GDALDataType eType,618 char **papszOptions)648 GDALDataset *IdrisiDataset::Create( const char *pszFilename, 649 int nXSize, 650 int nYSize, 651 int nBands, 652 GDALDataType eType, 653 char **papszOptions ) 619 654 { 620 655 // -------------------------------------------------------------------- … … 622 657 // -------------------------------------------------------------------- 623 658 624 if (nBands != 1)625 { 626 if (! (nBands == 3 && eType == GDT_Byte))627 { 628 CPLError( CE_Failure, CPLE_AppDefined,629 "Attempt to create IDRISI dataset with an illegal "630 "number of bands (%d) or data type(%s).\n",631 nBands, GDALGetDataTypeName(eType));659 if( nBands != 1 ) 660 { 661 if( !( nBands == 3 && eType == GDT_Byte ) ) 662 { 663 CPLError( CE_Failure, CPLE_AppDefined, 664 "Attempt to create IDRISI dataset with an illegal " 665 "number of bands(%d) or data type(%s).\n", 666 nBands, GDALGetDataTypeName( eType ) ); 632 667 return NULL; 633 668 } … … 640 675 const char *pszLDataType; 641 676 642 switch (eType)643 { 644 case GDT_Byte:645 if (nBands == 1)677 switch( eType ) 678 { 679 case GDT_Byte: 680 if( nBands == 1 ) 646 681 pszLDataType = rstBYTE; 647 682 else 648 683 pszLDataType = rstRGB24; 649 684 break; 650 case GDT_Int16:685 case GDT_Int16: 651 686 pszLDataType = rstINTEGER; 652 687 break; 653 case GDT_Float32:688 case GDT_Float32: 654 689 pszLDataType = rstREAL; 655 690 break; 656 default:657 CPLError( CE_Failure, CPLE_AppDefined,658 "Attempt to create IDRISI dataset with an illegal "659 "data type(%s).\n",660 GDALGetDataTypeName(eType));691 default: 692 CPLError( CE_Failure, CPLE_AppDefined, 693 "Attempt to create IDRISI dataset with an illegal " 694 "data type(%s).\n", 695 GDALGetDataTypeName( eType ) ); 661 696 return NULL; 662 697 … … 666 701 667 702 papszLRDC = NULL; 668 papszLRDC = CSLAddNameValue( papszLRDC, rdcFILE_FORMAT, rstVERSION);669 papszLRDC = CSLAddNameValue( papszLRDC, rdcFILE_TITLE, "");670 papszLRDC = CSLAddNameValue( papszLRDC, rdcDATA_TYPE, pszLDataType);671 papszLRDC = CSLAddNameValue( papszLRDC, rdcFILE_TYPE, "binary");672 papszLRDC = CSLAddNameValue( papszLRDC, rdcCOLUMNS, CPLSPrintf("%d", nXSize));673 papszLRDC = CSLAddNameValue( papszLRDC, rdcROWS, CPLSPrintf("%d", nYSize));674 papszLRDC = CSLAddNameValue( papszLRDC, rdcREF_SYSTEM, "");675 papszLRDC = CSLAddNameValue( papszLRDC, rdcREF_UNITS, "");676 papszLRDC = CSLAddNameValue( papszLRDC, rdcUNIT_DIST, "1");677 papszLRDC = CSLAddNameValue( papszLRDC, rdcMIN_X, "");678 papszLRDC = CSLAddNameValue( papszLRDC, rdcMAX_X, "");679 papszLRDC = CSLAddNameValue( papszLRDC, rdcMIN_Y, "");680 papszLRDC = CSLAddNameValue( papszLRDC, rdcMAX_Y, "");681 papszLRDC = CSLAddNameValue( papszLRDC, rdcPOSN_ERROR, "unspecified");682 papszLRDC = CSLAddNameValue( papszLRDC, rdcRESOLUTION, "");683 papszLRDC = CSLAddNameValue( papszLRDC, rdcMIN_VALUE, "");684 papszLRDC = CSLAddNameValue( papszLRDC, rdcMAX_VALUE, "");685 papszLRDC = CSLAddNameValue( papszLRDC, rdcDISPLAY_MIN, "");686 papszLRDC = CSLAddNameValue( papszLRDC, rdcDISPLAY_MAX, "");687 papszLRDC = CSLAddNameValue(<
