LCOV - code coverage report
Current view: directory - frmts/ilwis - ilwisdataset.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 7 5 71.4 %
Date: 2011-12-18 Functions: 7 5 71.4 %

       1                 : /******************************************************************************
       2                 :  *
       3                 :  * Project:  ILWIS Driver
       4                 :  * Purpose:  GDALDataset driver for ILWIS translator for read/write support.
       5                 :  * Author:   Lichun Wang, lichun@itc.nl
       6                 :  *
       7                 :  ******************************************************************************
       8                 :  * Copyright (c) 2004, ITC
       9                 :  *
      10                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      11                 :  * copy of this software and associated documentation files (the "Software"),
      12                 :  * to deal in the Software without restriction, including without limitation
      13                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14                 :  * and/or sell copies of the Software, and to permit persons to whom the
      15                 :  * Software is furnished to do so, subject to the following conditions:
      16                 :  *
      17                 :  * The above copyright notice and this permission notice shall be included
      18                 :  * in all copies or substantial portions of the Software.
      19                 :  *
      20                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26                 :  * DEALINGS IN THE SOFTWARE.
      27                 :  ****************************************************************************/
      28                 : 
      29                 : #ifdef _MSC_VER
      30                 : #pragma warning(disable : 4786)
      31                 : #pragma warning(disable : 4503)
      32                 : #endif
      33                 : 
      34                 : #include "gdal_pam.h"
      35                 : #include "cpl_csv.h"
      36                 : #include "ogr_spatialref.h"
      37                 : 
      38                 : #ifdef WIN32
      39                 : #include  <io.h>
      40                 : #endif
      41                 : 
      42                 : #include  <cstdio>
      43                 : #include  <cstdlib>
      44                 : #include <string>
      45                 : #include <map>
      46                 : 
      47                 : CPL_C_START
      48                 : void  GDALRegister_ILWIS(void);
      49                 : CPL_C_END
      50                 : 
      51                 : #define shUNDEF -32767
      52                 : #define iUNDEF  -2147483647
      53                 : #define flUNDEF ((float)-1e38)
      54                 : #define rUNDEF  ((double)-1e308)
      55                 : 
      56                 : enum ilwisStoreType
      57                 : { 
      58                 :     stByte,
      59                 :     stInt,
      60                 :     stLong,
      61                 :     stFloat,
      62                 :     stReal
      63                 : };
      64                 : 
      65                 : class ValueRange
      66                 : {
      67                 : public:
      68                 :     ValueRange(double min, double max); // step = 1
      69                 :     ValueRange(double min, double max, double step);  
      70                 :     ValueRange(std::string str);
      71                 :     std::string ToString();
      72                 :     ilwisStoreType get_NeededStoreType() { return st; }
      73           16881 :     double get_rLo() { return _rLo; }
      74           16881 :     double get_rHi() { return _rHi; }
      75              12 :     double get_rStep() { return _rStep; }
      76               0 :     double get_rRaw0() { return _r0; }  
      77               0 :     int get_iDec() { return _iDec; }  
      78                 :     double rValue(int raw);
      79                 :     int iRaw(double value);
      80                 : 
      81                 : private:
      82                 :     void init(double rRaw0);
      83                 :     void init();
      84                 :     double _rLo, _rHi;
      85                 :     double _rStep;
      86                 :     int _iDec;
      87                 :     double _r0;
      88                 :     int iRawUndef;
      89                 :     short _iWidth;
      90                 :     ilwisStoreType st;
      91                 : };
      92                 : 
      93                 : /************************************************************************/
      94                 : /*                     ILWISInfo                                        */
      95                 : /************************************************************************/
      96                 : 
      97                 : struct ILWISInfo
      98              79 : {
      99              79 :     ILWISInfo() : bUseValueRange(false), vr(0, 0) {}
     100                 :     bool bUseValueRange;
     101                 :     ValueRange vr;
     102                 :     ilwisStoreType stStoreType;
     103                 :     std::string stDomain;
     104                 : };
     105                 : 
     106                 : /************************************************************************/
     107                 : /*                           ILWISRasterBand                            */
     108                 : /************************************************************************/
     109                 : 
     110                 : class ILWISDataset;
     111                 : 
     112                 : class ILWISRasterBand : public GDALPamRasterBand
     113                 : {
     114                 :     friend class ILWISDataset;
     115                 : public:
     116                 :     VSILFILE *fpRaw;
     117                 :     ILWISInfo psInfo;
     118                 :     int nSizePerPixel;
     119                 : 
     120                 :     ILWISRasterBand( ILWISDataset *, int );
     121                 :     ~ILWISRasterBand();
     122                 :     CPLErr GetILWISInfo(std::string pszFileName);
     123                 :     void ILWISOpen( std::string pszFilename);
     124                 :         
     125                 :     virtual CPLErr IReadBlock( int, int, void * );
     126                 :     virtual CPLErr IWriteBlock( int, int, void * ); 
     127                 :     virtual double GetNoDataValue( int *pbSuccess );
     128                 : 
     129                 : private:
     130                 :     void FillWithNoData(void * pImage);
     131                 :     void SetValue(void *pImage, int i, double rV);
     132                 :     double GetValue(void *pImage, int i);
     133                 :     void ReadValueDomainProperties(std::string pszFileName);
     134                 : };
     135                 : 
     136                 : /************************************************************************/
     137                 : /*                     ILWISDataset         */
     138                 : /************************************************************************/
     139                 : class ILWISDataset : public GDALPamDataset
     140                 : {
     141                 :     friend class ILWISRasterBand;
     142                 :     CPLString osFileName;
     143                 :     std::string pszIlwFileName;
     144                 :     char   *pszProjection;
     145                 :     double adfGeoTransform[6];
     146                 :     int    bGeoDirty;
     147                 :     int    bNewDataset;            /* product of Create() */
     148                 :     std::string pszFileType; //indicating the input dataset: Map/MapList
     149                 :     CPLErr ReadProjection( std::string csyFileName);
     150                 :     CPLErr WriteProjection();
     151                 :     CPLErr WriteGeoReference();
     152                 :     void   CollectTransformCoef(std::string &pszRefFile );
     153                 :     
     154                 : public:
     155                 :     ILWISDataset();
     156                 :     ~ILWISDataset();
     157                 : 
     158                 :     static GDALDataset *Open( GDALOpenInfo * );
     159                 :     
     160                 :     static GDALDataset *CreateCopy( const char * pszFilename,
     161                 :                                     GDALDataset *poSrcDS,
     162                 :                                     int bStrict, char ** papszOptions,
     163                 :                                     GDALProgressFunc pfnProgress,
     164                 :                                     void * pProgressData );
     165                 : 
     166                 :     static GDALDataset *Create(const char* pszFilename,
     167                 :                                int nXSize, int nYSize, 
     168                 :                                int nBands, GDALDataType eType,
     169                 :                                char** papszParmList); 
     170                 :     
     171                 :     virtual CPLErr  GetGeoTransform( double * padfTransform );
     172                 :     virtual CPLErr  SetGeoTransform( double * );
     173                 : 
     174                 :     virtual const char *GetProjectionRef(void);
     175                 :     virtual CPLErr SetProjection( const char * );
     176                 : 
     177                 :     virtual void   FlushCache( void );
     178                 : };
     179                 : 
     180                 : // IniFile.h: interface for the IniFile class.
     181                 : // 
     182                 : //////////////////////////////////////////////////////////////////////
     183                 : 
     184                 : class CompareAsNum
     185                 : {
     186                 : public:
     187                 :     bool operator() (const std::string&, const std::string&) const;
     188                 : };
     189                 : 
     190                 : typedef std::map<std::string, std::string>          SectionEntries;
     191                 : typedef std::map<std::string, SectionEntries*> Sections;
     192                 : 
     193                 : class IniFile  
     194                 : {
     195                 : public:
     196                 :     IniFile(const std::string& filename);
     197                 :     virtual ~IniFile();
     198                 : 
     199                 :     void SetKeyValue(const std::string& section, const std::string& key, const std::string& value);
     200                 :     std::string GetKeyValue(const std::string& section, const std::string& key);
     201                 : 
     202                 :     void RemoveKeyValue(const std::string& section, const std::string& key);
     203                 :     void RemoveSection(const std::string& section);
     204                 : 
     205                 : private:
     206                 :     std::string filename;
     207                 :     Sections sections;
     208                 :     bool bChanged;
     209                 : 
     210                 :     void Load();
     211                 :     void Store();
     212                 : };
     213                 : 
     214                 : 

Generated by: LCOV version 1.7