1 : /******************************************************************************
2 : * $Id: ogr_gtm.h 20996 2010-10-28 18:38:15Z rouault $
3 : *
4 : * Project: GTM Driver
5 : * Purpose: Declarations for OGR wrapper classes for GTM, and OGR->GTM
6 : * translation of geometry.
7 : * Author: Leonardo de Paula Rosa Piga; http://lampiao.lsc.ic.unicamp.br/~piga
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2009, Leonardo de Paula Rosa Piga
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 : #ifndef OGR_GTM_H_INCLUDED
31 : #define OGR_GTM_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "cpl_conv.h"
35 : #include "cpl_string.h"
36 :
37 : class OGRGTMDataSource;
38 :
39 : typedef enum
40 : {
41 : GTM_NONE,
42 : GTM_WPT,
43 : GTM_TRACK
44 : } GTMGeometryType;
45 :
46 : #ifndef FILE_OFFSETS
47 : #define FILE_OFFSETS
48 : #define NWPTSTYLES_OFFSET 27
49 : #define NWPTSTYLES_SIZE 4
50 :
51 : #define NWPTS_OFFSET 35
52 : #define NWPTS_SIZE 4
53 :
54 : #define NTRCKS_OFFSET 39
55 : #define NTRCKS_SIZE 4
56 :
57 : #define NMAPS_OFFSET 63
58 : #define NMAPS_SIZE 4
59 :
60 : #define NTK_OFFSET 67
61 : #define NTK_SIZE 4
62 :
63 : #define BOUNDS_OFFSET 47
64 :
65 : #define DATUM_SIZE 58
66 :
67 : /* GTM_EPOCH is defined as the unix time for the 31 dec 1989 00:00:00 */
68 : #define GTM_EPOCH 631065600
69 :
70 : #endif
71 :
72 : #ifndef MAX
73 : # define MIN(a,b) ((a<b) ? a : b)
74 : # define MAX(a,b) ((a>b) ? a : b)
75 : #endif
76 :
77 :
78 : #include "gtm.h"
79 :
80 :
81 : /************************************************************************/
82 : /* OGRGTMLayer */
83 : /************************************************************************/
84 : class OGRGTMLayer : public OGRLayer
85 : {
86 : public:
87 : OGRGTMLayer();
88 : ~OGRGTMLayer();
89 : //
90 : // OGRLayer Interface
91 : //
92 : OGRFeatureDefn* GetLayerDefn();
93 0 : OGRSpatialReference* GetSpatialRef() {return poSRS;}
94 : virtual void ResetReading() = 0;
95 : virtual OGRFeature* GetNextFeature() = 0;
96 : virtual int GetFeatureCount(int bForce = TRUE) = 0;
97 : virtual OGRErr CreateFeature (OGRFeature *poFeature) = 0;
98 :
99 : int TestCapability( const char* pszCap );
100 :
101 : OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK );
102 :
103 : protected:
104 : OGRGTMDataSource* poDS;
105 : OGRSpatialReference* poSRS;
106 : OGRCoordinateTransformation *poCT;
107 : char* pszName;
108 :
109 : OGRFeatureDefn* poFeatureDefn;
110 : int nNextFID;
111 : int nTotalFCount;
112 :
113 : int bError;
114 :
115 : static OGRErr CheckAndFixCoordinatesValidity( double& pdfLatitude, double& pdfLongitude );
116 :
117 : };
118 :
119 :
120 : /************************************************************************/
121 : /* GTMWaypointLayer */
122 : /************************************************************************/
123 : class GTMWaypointLayer : public OGRGTMLayer
124 : {
125 : public:
126 : GTMWaypointLayer( const char* pszName,
127 : OGRSpatialReference* poSRSIn,
128 : int bWriterIn,
129 : OGRGTMDataSource* poDSIn );
130 : ~GTMWaypointLayer();
131 : OGRErr CreateFeature (OGRFeature *poFeature);
132 : void ResetReading();
133 : OGRFeature* GetNextFeature();
134 : int GetFeatureCount(int bForce = TRUE);
135 :
136 : enum WaypointFields{NAME, COMMENT, ICON, DATE};
137 : private:
138 : void WriteFeatureAttributes( OGRFeature *poFeature, float altitude );
139 : };
140 :
141 : /************************************************************************/
142 : /* GTMTrackLayer */
143 : /************************************************************************/
144 : class GTMTrackLayer : public OGRGTMLayer
145 : {
146 : public:
147 : GTMTrackLayer( const char* pszName,
148 : OGRSpatialReference* poSRSIn,
149 : int bWriterIn,
150 : OGRGTMDataSource* poDSIn );
151 : ~GTMTrackLayer();
152 : OGRErr CreateFeature (OGRFeature *poFeature);
153 : void ResetReading();
154 : OGRFeature* GetNextFeature();
155 : int GetFeatureCount(int bForce = TRUE);
156 : enum TrackFields{NAME, TYPE, COLOR};
157 :
158 : private:
159 : void WriteFeatureAttributes( OGRFeature *poFeature );
160 : void WriteTrackpoint( double lat, double lon, float altitude, bool start );
161 :
162 : };
163 :
164 :
165 : /************************************************************************/
166 : /* OGRGTMDataSource */
167 : /************************************************************************/
168 : class OGRGTMDataSource : public OGRDataSource
169 : {
170 : public:
171 :
172 : // OGRDataSource Interface
173 : OGRGTMDataSource();
174 : ~OGRGTMDataSource();
175 :
176 : int Open( const char *pszFilename, int bUpdate );
177 : int Create( const char *pszFilename, char **papszOptions );
178 :
179 6 : const char* GetName() { return pszName; }
180 11 : int GetLayerCount() { return nLayers; }
181 :
182 : OGRLayer* GetLayer( int );
183 :
184 : OGRLayer* CreateLayer (const char *pszName,
185 : OGRSpatialReference *poSpatialRef=NULL,
186 : OGRwkbGeometryType eGType=wkbUnknown,
187 : char **papszOptions=NULL);
188 : int TestCapability( const char * );
189 :
190 : // OGRGTMDataSource Methods
191 8 : VSILFILE* getOutputFP() { return fpOutput; }
192 18 : VSILFILE* getTmpTrackpointsFP() { return fpTmpTrackpoints; }
193 7 : VSILFILE* getTmpTracksFP() { return fpTmpTracks; }
194 0 : bool isFirstCTError() { return !bIssuedCTError; }
195 0 : void issuedFirstCTError() { bIssuedCTError = true; }
196 :
197 : /* Functions to handle with waypoints */
198 : int getNWpts();
199 : bool hasNextWaypoint();
200 : Waypoint* fetchNextWaypoint();
201 : void rewindWaypoint();
202 :
203 : /* Functions to handle with tracks */
204 : int getNTracks();
205 : bool hasNextTrack();
206 : Track* fetchNextTrack();
207 : void rewindTrack();
208 :
209 :
210 : /* Functions for writing ne files */
211 : float getMinLat() { return minlat; }
212 : float getMaxLat() { return maxlat; }
213 : float getMinLon() { return minlon; }
214 : float getMaxLon() { return maxlon; }
215 :
216 : void checkBounds(float newLat,
217 : float newLon);
218 : int getNumWaypoints() { return numWaypoints; }
219 : int getNumTrackpoints() { return numTrackpoints; }
220 : int getTracks() { return numTracks; };
221 :
222 4 : int incNumWaypoints() { return ++numWaypoints; }
223 15 : int incNumTrackpoints() { return ++numTrackpoints; }
224 4 : int incNumTracks() { return ++numTracks; };
225 : private:
226 : VSILFILE* fpOutput;
227 :
228 : /* GTM is not a contiguous file. We need two temporary files because
229 : trackpoints and tracks are stored separated and we don't know in
230 : advance how many trackpoints and tracks the new file will
231 : have. So, we create temporary file and append the at the end of
232 : the gtm file whe everything is done, that is, in the
233 : destructor. */
234 : VSILFILE* fpTmpTrackpoints;
235 : char* pszTmpTrackpoints;
236 :
237 : VSILFILE* fpTmpTracks;
238 : char* pszTmpTracks;
239 :
240 : GTM* poGTMFile;
241 : char* pszName;
242 :
243 : OGRGTMLayer **papoLayers;
244 : int nLayers;
245 :
246 : bool bIssuedCTError;
247 :
248 : /* Used for creating a new file */
249 : float minlat;
250 : float maxlat;
251 : float minlon;
252 : float maxlon;
253 :
254 : int numWaypoints;
255 : int numTracks;
256 : int numTrackpoints;
257 :
258 : void AppendTemporaryFiles();
259 : void WriteWaypointStyles();
260 : };
261 :
262 : /************************************************************************/
263 : /* OGRGTMDriver */
264 : /************************************************************************/
265 :
266 : class OGRGTMDriver : public OGRSFDriver
267 226 : {
268 : public:
269 : ~OGRGTMDriver();
270 :
271 : //
272 : // OGRSFDriver Interface
273 : //
274 : const char* GetName();
275 : OGRDataSource* Open( const char * pszName_, int bUpdate );
276 : OGRDataSource* CreateDataSource( const char *pszName_, char** papszOptions );
277 :
278 : int TestCapability( const char* pszCap );
279 : };
280 :
281 : #endif //OGR_GTM_H_INCLUDED
|