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