navit  0.5.3-trunk
gpx2navit_txt.h
Go to the documentation of this file.
1 
20 #ifndef GPX2SHP_H_INCLUDED
21 #define GPX2SHP_H_INCLUDED
22 
23 #define PROG gpx2navit_txt
24 #define FILENAMELENGTH 255 /* 255 is max length for dbf string column */
25 #define COMMENTLENGTH 255 /* 255 is max length for dbf string column */
26 #define NAMELENGTH 32
27 #define TIMELENGTH 32
28 #define TYPELENGTH 16
29 #define BUFFSIZE 8192
30 #define DATABUFSIZE 16
31 #define failToWriteAttr(S, T) failToWriteAttrRep((S), (T),__FILE__, __LINE__ )
32 
33 #include <stdio.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <libgen.h>
39 #include <getopt.h>
40 #include <time.h>
41 #include <assert.h>
42 #include <expat.h>
43 #include "errorcode.h"
44 //#include "shapefil.h"
45 
46 
47 #define DEBUG 0
48 
51 typedef struct parent {
52  char *name;
53  struct parent *parentptr;
55 } parent;
56 
60 typedef struct g2scolumns {
64  int name;
65  int cmt;
66  int desc;
67  int src;
68  int link;
69  int type;
70  int time;
71  int number;
72  int ele;
73  int magvar;
75  int sym;
76  int fix;
77  int sat;
78  int hdop;
79  int vdop;
80  int pdop;
82  int dgpsid;
83  int length;
84  int interval;
85  int speed;
86  int points;
87  int gpxline;
88 } g2scolumns;
89 
93 typedef struct pathattr {
95  char cmt[COMMENTLENGTH];
96  char desc[COMMENTLENGTH];
97  char src[COMMENTLENGTH];
98  char link[FILENAMELENGTH];
99  int number;
101  double length;
102  double interval;
103  double speed;
104  /*
105  double *x;
106  double *y;
107  double *z;
108  */
109  double *point;
110  int count;
111 } pathattr;
112 
116 typedef struct g2sattr {
120  double lon;
121  double lat;
122  double minlon;
123  double minlat;
124  double maxlon;
125  double maxlat;
127  char cmt[COMMENTLENGTH];
128  char desc[COMMENTLENGTH];
129  char src[COMMENTLENGTH];
130  char link[FILENAMELENGTH];
132  char time[TIMELENGTH];
133  int number;
134  double ele;
135  double magvar;
136  double geoidheight;
137  char sym[NAMELENGTH];
138  char fix[NAMELENGTH];
139  int sat;
140  double hdop;
141  double vdop;
142  double pdop;
144  int dgpsid;
145  char author[NAMELENGTH];
146  char keywords[NAMELENGTH];
147  char copyright[NAMELENGTH];
148  int year;
149  char license[NAMELENGTH];
150 } g2sattr;
151 
155 typedef struct g2sstats {
156  int trkpoints;
157  int trkcount;
158  double trklength;
159  int rtepoints;
160  int rtecount;
161  double rtelength;
162  int wptpoints;
165 } g2sstats;
166 
170 //typedef struct dbfhandles {
171 // DBFHandle trk; /** for track */
172 // DBFHandle wpt; /** for waypoint */
173 // DBFHandle rte; /** for route */
174 // DBFHandle trk_edg; /** for track each edge */
175 // DBFHandle trk_pnt; /** for track each point */
176 // DBFHandle rte_edg; /** for route each edge */
177 // DBFHandle rte_pnt; /** for route each point */
178 //} dbfhandles;
179 
183 //typedef struct shphandles {
184 // SHPHandle trk; /** for track */
185 // SHPHandle wpt; /** for waypoint */
186 // SHPHandle rte; /** for route */
187 // SHPHandle trk_edg; /** for track each edge */
188 // SHPHandle trk_pnt; /** for track each point */
189 // SHPHandle rte_edg; /** for route each edge */
190 // SHPHandle rte_pnt; /** for route each point */
191 //} shphandles;
192 
196 typedef struct g2sprop {
197  int parseWpt;
198  int parseTrk;
199  int parseRte;
200  int is3d;
201  int isEdge;
202  int isPoint;
203  int isFast;
205  int minpoints;
206  int minlength;
207  int mintime;
208  int verbose;
209  char *sourcefile;
210  char *output;
211  char *ellipsoid;
212  char *lengthUnit;
213  double length2meter;
214  char *timeUnit;
215  double time2sec;
218  double speed2meter;
220  int speed2sec;
224 } g2sprop;
225 
229 typedef struct parsedata {
230  int depth;
231  char *databuf;
232  char *bufptr;
233  int failed;
234  int failedid;
235  XML_Parser parser;
237  parent *current;
238  FILE *fp;
239 // shphandles *shps; /** .shp file cluster that is used in this program */
240 // dbfhandles *dbfs; /** .dbf file cluster that is used in this program */
244 } parsedata;
245 
246 /* utils.c */
247 void checkEllpsUnit(char *unit);
248 double checkLengthUnit(char *unit);
249 int checkTimeUnit(char *unit);
250 double getTimeInterval(char *_t, char *t);
251 double getSpeed(double length, double ti, double to_meter, int to_sec);
252 double getDistance(double _x, double _y, double x, double y);
253 //void closeShpFiles(shphandles * shps);
254 //void closeDbfFiles(dbfhandles * dbfs);
255 void *myMallocRep(size_t size, const char *fileName, int line);
256 
257 /* misc.c */
258 void failToWriteAttrRep(int iShape, int col, char *file, int line);
259 void showStats(g2sprop * prop);
260 void wipePathAttr(pathattr * pattr);
261 pathattr *createPathAttr(void);
262 void wipeAttr(g2sattr * attr);
263 void setColsDefault(g2scolumns * cols);
264 g2scolumns *createCols(void);
265 g2sattr *createAttr(void);
266 g2sprop *createProp(void);
267 void closeProp(g2sprop * prop);
268 //shphandles *createShps(void);
269 //dbfhandles *createDbfs(void);
270 parsedata *createParsedata(XML_Parser parser, g2sprop * prop);
271 void closeParsedata(parsedata * pdata);
272 
273 /* parser.c */
274 void parseMain(g2sprop * pr);
275 
276 /* elementControl.c */
277 void startElementControl(parsedata * pdata, const char *element,
278  const char **attr);
279 void endElementControl(parsedata * pdata, const char *element);
280 
281 /* setwpt.c */
282 void setWpt( parsedata * pdata);
283 
284 /* setpath.c */
285 void initPathAttr(pathattr * pattr, g2sattr * attr);
286 void setPathInterval(parsedata *pdata);
287 void setPathData(pathattr * parrt, g2sattr * attr);
288 void setPath( parsedata * pdata);
289 
290 /* setmetadata.c */
291 void setMetadata(parsedata * pdata);
292 
293 #endif
double maxlon
Definition: gpx2navit_txt.h:124
int sym
Definition: gpx2navit_txt.h:75
int sat
Definition: gpx2navit_txt.h:139
int length
Definition: garmin_img.c:67
double minlat
Definition: gpx2navit_txt.h:123
double checkLengthUnit(char *unit)
Definition: utils.c:59
int trkcount
Definition: gpx2navit_txt.h:157
double getSpeed(double length, double ti, double to_meter, int to_sec)
Definition: utils.c:131
int failed
Definition: gpx2navit_txt.h:233
double trklength
Definition: gpx2navit_txt.h:158
char * bufptr
Definition: gpx2navit_txt.h:232
#define NAMELENGTH
Definition: gpx2navit_txt.h:26
int interval
Definition: gpx2navit_txt.h:84
char * databuf
Definition: gpx2navit_txt.h:231
void wipePathAttr(pathattr *pattr)
Definition: misc.c:100
#define TIMELENGTH
Definition: gpx2navit_txt.h:27
double * point
Definition: gpx2navit_txt.h:109
Definition: gpx2navit_txt.h:51
pathattr * pattr
Definition: gpx2navit_txt.h:242
GEOD_EXTERN double to_meter
Definition: geodesic.h:61
int name
Definition: gpx2navit_txt.h:64
int nospeedcheck
Definition: gpx2navit_txt.h:223
void failToWriteAttrRep(int iShape, int col, char *file, int line)
Definition: misc.c:40
double getDistance(double _x, double _y, double x, double y)
Definition: utils.c:156
g2scolumns * createCols(void)
Definition: misc.c:198
XML_Parser parser
Definition: gpx2navit_txt.h:235
struct pathattr pathattr
parsedata * createParsedata(XML_Parser parser, g2sprop *prop)
Definition: misc.c:310
int depth
Definition: gpx2navit_txt.h:230
int needsStats
Definition: gpx2navit_txt.h:204
int size
Definition: garmin_img.c:124
int gpxline
Definition: gpx2navit_txt.h:87
#define TYPELENGTH
Definition: gpx2navit_txt.h:28
#define FILENAMELENGTH
Definition: gpx2navit_txt.h:24
double time2sec
Definition: gpx2navit_txt.h:215
int ele
Definition: gpx2navit_txt.h:72
int src
Definition: gpx2navit_txt.h:67
int trkpoints
Definition: gpx2navit_txt.h:156
double getTimeInterval(char *_t, char *t)
Definition: utils.c:105
double magvar
Definition: gpx2navit_txt.h:135
double minlon
Definition: gpx2navit_txt.h:122
int isEdge
Definition: gpx2navit_txt.h:201
int speed
Definition: gpx2navit_txt.h:85
int wptpoints
Definition: gpx2navit_txt.h:162
Definition: gpx2navit_txt.h:60
void setPath(parsedata *pdata)
Definition: setpath.c:218
void checkEllpsUnit(char *unit)
Definition: utils.c:35
int number
Definition: gpx2navit_txt.h:133
int rtepoints
Definition: gpx2navit_txt.h:159
int rteunconverted
Definition: gpx2navit_txt.h:164
double geoidheight
Definition: gpx2navit_txt.h:136
char * timeUnit
Definition: gpx2navit_txt.h:214
#define COMMENTLENGTH
Definition: gpx2navit_txt.h:25
int minpoints
Definition: gpx2navit_txt.h:205
int mintime
Definition: gpx2navit_txt.h:207
parent * current
Definition: gpx2navit_txt.h:237
Definition: gpx2navit_txt.h:229
char * output
Definition: gpx2navit_txt.h:210
Definition: layout.h:31
g2sstats * stats
Definition: gpx2navit_txt.h:221
Definition: gpx2navit_txt.h:93
int isPoint
Definition: gpx2navit_txt.h:202
int number
Definition: gpx2navit_txt.h:99
struct parent parent
struct g2sstats g2sstats
double pdop
Definition: gpx2navit_txt.h:142
int desc
Definition: gpx2navit_txt.h:66
char * ellipsoid
Definition: gpx2navit_txt.h:211
int fix
Definition: gpx2navit_txt.h:76
void initPathAttr(pathattr *pattr, g2sattr *attr)
Definition: setpath.c:37
void setPathData(pathattr *parrt, g2sattr *attr)
Definition: setpath.c:129
double hdop
Definition: gpx2navit_txt.h:140
pathattr * createPathAttr(void)
Definition: misc.c:118
int checkTimeUnit(char *unit)
Definition: utils.c:87
double speed
Definition: gpx2navit_txt.h:103
double ageofdgpsdata
Definition: gpx2navit_txt.h:143
int count
Definition: gpx2navit_txt.h:110
int sat
Definition: gpx2navit_txt.h:77
int time
Definition: gpx2navit_txt.h:70
double interval
Definition: gpx2navit_txt.h:102
double rtelength
Definition: gpx2navit_txt.h:161
double speed2meter
Definition: gpx2navit_txt.h:218
void closeProp(g2sprop *prop)
Definition: misc.c:260
char * speedTimeUnit
Definition: gpx2navit_txt.h:219
int points
Definition: gpx2navit_txt.h:86
struct g2scolumns g2scolumns
Definition: attr.h:157
int vdop
Definition: gpx2navit_txt.h:79
double maxlat
Definition: gpx2navit_txt.h:125
int parseWpt
Definition: gpx2navit_txt.h:197
int geoidheight
Definition: gpx2navit_txt.h:74
char * lengthUnit
Definition: gpx2navit_txt.h:212
void setColsDefault(g2scolumns *cols)
Definition: misc.c:168
double ele
Definition: gpx2navit_txt.h:134
void startElementControl(parsedata *pdata, const char *element, const char **attr)
Definition: elementControl.c:30
char * sourcefile
Definition: gpx2navit_txt.h:209
void setMetadata(parsedata *pdata)
Definition: setmeta.c:25
Definition: gpx2navit_txt.h:196
int length
Definition: gpx2navit_txt.h:83
int is3d
Definition: gpx2navit_txt.h:200
void setWpt(parsedata *pdata)
Definition: setwpt.c:27
int pdop
Definition: gpx2navit_txt.h:80
char * speedLengthUnit
Definition: gpx2navit_txt.h:216
double lat
Definition: gpx2navit_txt.h:121
g2sprop * createProp(void)
Definition: misc.c:218
int failedid
Definition: gpx2navit_txt.h:234
g2sattr * attr
Definition: gpx2navit_txt.h:241
struct g2sprop g2sprop
FILE * fp
Definition: gpx2navit_txt.h:238
void parseMain(g2sprop *pr)
Definition: parser.c:110
g2sprop * prop
Definition: gpx2navit_txt.h:243
int speed2sec
Definition: gpx2navit_txt.h:220
void endElementControl(parsedata *pdata, const char *element)
Definition: elementControl.c:96
int isFast
Definition: gpx2navit_txt.h:203
Definition: gpx2navit_txt.h:116
void closeParsedata(parsedata *pdata)
Definition: misc.c:342
int hdop
Definition: gpx2navit_txt.h:78
char type[3]
Definition: garmin_img.c:123
int parseRte
Definition: gpx2navit_txt.h:199
double lon
Definition: gpx2navit_txt.h:120
int verbose
Definition: gpx2navit_txt.h:208
parent * parent
Definition: gpx2navit_txt.h:236
struct parsedata parsedata
double length2meter
Definition: gpx2navit_txt.h:213
int dgpsid
Definition: gpx2navit_txt.h:144
void wipeAttr(g2sattr *attr)
Definition: misc.c:128
void showStats(g2sprop *prop)
Definition: misc.c:48
double length
Definition: gpx2navit_txt.h:101
struct parent * parentptr
Definition: gpx2navit_txt.h:53
int parseTrk
Definition: gpx2navit_txt.h:198
int year
Definition: gpx2navit_txt.h:148
g2scolumns * cols
Definition: gpx2navit_txt.h:222
int cmt
Definition: gpx2navit_txt.h:65
int rtecount
Definition: gpx2navit_txt.h:160
int minlength
Definition: gpx2navit_txt.h:206
double vdop
Definition: gpx2navit_txt.h:141
int dgpsid
Definition: gpx2navit_txt.h:82
struct g2sattr g2sattr
g2sattr * createAttr(void)
Definition: misc.c:208
int ageofdgpsdata
Definition: gpx2navit_txt.h:81
int type
Definition: gpx2navit_txt.h:69
int link
Definition: gpx2navit_txt.h:68
char * name
Definition: gpx2navit_txt.h:52
Definition: gpx2navit_txt.h:155
int number
Definition: gpx2navit_txt.h:71
void * myMallocRep(size_t size, const char *fileName, int line)
int magvar
Definition: gpx2navit_txt.h:73
void setPathInterval(parsedata *pdata)
Definition: setpath.c:95
Definition: file.h:36
int trkunconverted
Definition: gpx2navit_txt.h:163