LCOV - code coverage report
Current view: top level - frmts/ilwis - ilwisdataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 8 12 66.7 %
Date: 2024-05-04 12:52:34 Functions: 4 6 66.7 %

          Line data    Source code
       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             : #ifndef ILWISDATASET_H_INCLUDED
      30             : #define ILWISDATASET_H_INCLUDED
      31             : 
      32             : #include "gdal_pam.h"
      33             : #include "cpl_csv.h"
      34             : #include "ogr_spatialref.h"
      35             : 
      36             : #include <cstdio>
      37             : #include <cstdlib>
      38             : 
      39             : #include <map>
      40             : #include <string>
      41             : 
      42             : #define shUNDEF -32767
      43             : #define iUNDEF -2147483647
      44             : #define flUNDEF ((float)-1e38)
      45             : #define rUNDEF ((double)-1e308)
      46             : 
      47             : namespace GDAL
      48             : {
      49             : 
      50             : enum ilwisStoreType
      51             : {
      52             :     stByte,
      53             :     stInt,
      54             :     stLong,
      55             :     stFloat,
      56             :     stReal
      57             : };
      58             : 
      59             : class ValueRange
      60             : {
      61             :   public:
      62             :     ValueRange(double min, double max);  // step = 1
      63             :     ValueRange(double min, double max, double step);
      64             :     explicit ValueRange(const std::string &str);
      65             :     std::string ToString() const;
      66             : 
      67             :     ilwisStoreType get_NeededStoreType() const
      68             :     {
      69             :         return st;
      70             :     }
      71             : 
      72       16884 :     double get_rLo() const
      73             :     {
      74       16884 :         return _rLo;
      75             :     }
      76             : 
      77       16792 :     double get_rHi() const
      78             :     {
      79       16792 :         return _rHi;
      80             :     }
      81             : 
      82          12 :     double get_rStep() const
      83             :     {
      84          12 :         return _rStep;
      85             :     }
      86             : 
      87           0 :     double get_rRaw0() const
      88             :     {
      89           0 :         return _r0;
      90             :     }
      91             : 
      92           0 :     int get_iDec() const
      93             :     {
      94           0 :         return _iDec;
      95             :     }
      96             : 
      97             :     double rValue(int raw) const;
      98             :     int iRaw(double value) const;
      99             : 
     100             :   private:
     101             :     void init(double rRaw0);
     102             :     void init();
     103             :     double _rLo, _rHi;
     104             :     double _rStep;
     105             :     int _iDec;
     106             :     double _r0;
     107             :     int iRawUndef;
     108             :     short _iWidth;
     109             :     ilwisStoreType st;
     110             : };
     111             : 
     112             : /************************************************************************/
     113             : /*                     ILWISInfo                                        */
     114             : /************************************************************************/
     115             : 
     116             : struct ILWISInfo
     117             : {
     118          80 :     ILWISInfo() : bUseValueRange(false), vr(0, 0), stStoreType(stByte)
     119             :     {
     120          80 :     }
     121             : 
     122             :     bool bUseValueRange;
     123             :     ValueRange vr;
     124             :     ilwisStoreType stStoreType;
     125             :     std::string stDomain;
     126             : };
     127             : 
     128             : /************************************************************************/
     129             : /*                           ILWISRasterBand                            */
     130             : /************************************************************************/
     131             : 
     132             : class ILWISDataset;
     133             : 
     134             : class ILWISRasterBand final : public GDALPamRasterBand
     135             : {
     136             :     friend class ILWISDataset;
     137             : 
     138             :   public:
     139             :     VSILFILE *fpRaw;
     140             :     ILWISInfo psInfo;
     141             :     int nSizePerPixel;
     142             : 
     143             :     ILWISRasterBand(ILWISDataset *, int, const std::string &sBandNameIn);
     144             :     virtual ~ILWISRasterBand();
     145             :     CPLErr GetILWISInfo(const std::string &pszFileName);
     146             :     void ILWISOpen(const std::string &pszFilename);
     147             : 
     148             :     virtual CPLErr IReadBlock(int, int, void *) override;
     149             :     virtual CPLErr IWriteBlock(int, int, void *) override;
     150             :     virtual double GetNoDataValue(int *pbSuccess) override;
     151             : 
     152             :   private:
     153             :     void FillWithNoData(void *pImage);
     154             :     void SetValue(void *pImage, int i, double rV);
     155             :     double GetValue(void *pImage, int i);
     156             :     void ReadValueDomainProperties(const std::string &pszFileName);
     157             : };
     158             : 
     159             : /************************************************************************/
     160             : /*                         ILWISDataset                                 */
     161             : /************************************************************************/
     162             : class ILWISDataset final : public GDALPamDataset
     163             : {
     164             :     friend class ILWISRasterBand;
     165             :     CPLString osFileName;
     166             :     std::string pszIlwFileName;
     167             :     OGRSpatialReference m_oSRS{};
     168             :     double adfGeoTransform[6];
     169             :     int bGeoDirty;
     170             :     int bNewDataset;          /* product of Create() */
     171             :     std::string pszFileType;  // indicating the input dataset: Map/MapList
     172             :     CPLErr ReadProjection(const std::string &csyFileName);
     173             :     CPLErr WriteProjection();
     174             :     void WriteGeoReference();
     175             :     void CollectTransformCoef(std::string &pszRefFile);
     176             : 
     177             :   public:
     178             :     ILWISDataset();
     179             :     virtual ~ILWISDataset();
     180             : 
     181             :     static GDALDataset *Open(GDALOpenInfo *);
     182             : 
     183             :     static GDALDataset *CreateCopy(const char *pszFilename,
     184             :                                    GDALDataset *poSrcDS, int bStrict,
     185             :                                    char **papszOptions,
     186             :                                    GDALProgressFunc pfnProgress,
     187             :                                    void *pProgressData);
     188             : 
     189             :     static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
     190             :                                int nBands, GDALDataType eType,
     191             :                                char **papszParamList);
     192             : 
     193             :     virtual CPLErr GetGeoTransform(double *padfTransform) override;
     194             :     virtual CPLErr SetGeoTransform(double *) override;
     195             : 
     196             :     const OGRSpatialReference *GetSpatialRef() const override;
     197             :     CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
     198             : 
     199             :     virtual CPLErr FlushCache(bool bAtClosing) override;
     200             : };
     201             : 
     202             : // IniFile.h: interface for the IniFile class.
     203             : //
     204             : //////////////////////////////////////////////////////////////////////
     205             : 
     206             : class CompareAsNum
     207             : {
     208             :   public:
     209             :     bool operator()(const std::string &, const std::string &) const;
     210             : };
     211             : 
     212             : typedef std::map<std::string, std::string> SectionEntries;
     213             : typedef std::map<std::string, SectionEntries *> Sections;
     214             : 
     215             : class IniFile
     216             : {
     217             :   public:
     218             :     explicit IniFile(const std::string &filename);
     219             :     virtual ~IniFile();
     220             : 
     221             :     void SetKeyValue(const std::string &section, const std::string &key,
     222             :                      const std::string &value);
     223             :     std::string GetKeyValue(const std::string &section, const std::string &key);
     224             : 
     225             :     void RemoveKeyValue(const std::string &section, const std::string &key);
     226             :     void RemoveSection(const std::string &section);
     227             : 
     228             :   private:
     229             :     std::string filename;
     230             :     Sections sections;
     231             :     bool bChanged;
     232             : 
     233             :     void Load();
     234             :     void Store();
     235             : };
     236             : 
     237             : std::string ReadElement(const std::string &section, const std::string &entry,
     238             :                         const std::string &filename);
     239             : bool WriteElement(const std::string &sSection, const std::string &sEntry,
     240             :                   const std::string &fn, const std::string &sValue);
     241             : bool WriteElement(const std::string &sSection, const std::string &sEntry,
     242             :                   const std::string &fn, int nValue);
     243             : bool WriteElement(const std::string &sSection, const std::string &sEntry,
     244             :                   const std::string &fn, double dValue);
     245             : 
     246             : }  // namespace GDAL
     247             : 
     248             : #endif  // ILWISDATASET_H_INCLUDED

Generated by: LCOV version 1.14