1 |
/**
|
2 |
* Navit, a modular navigation system.
|
3 |
* Copyright (C) 2005-2008 Navit Team
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
#include "gpx2navit_txt.h"
|
21 |
|
22 |
void failToWriteAttrRep(int iShape, int col, char *file, int line);
|
23 |
void showStats(g2sprop * prop);
|
24 |
void wipePathAttr(pathattr * pattr);
|
25 |
pathattr *createPathAttr(void);
|
26 |
void wipeAttr(g2sattr * attr);
|
27 |
void setColsDefault(g2scolumns * cols);
|
28 |
g2scolumns *createCols(void);
|
29 |
g2sattr *createAttr(void);
|
30 |
g2sprop *createProp(void);
|
31 |
void closeProp(g2sprop * prop);
|
32 |
//shphandles *createShps(void);
|
33 |
//dbfhandles *createDbfs(void);
|
34 |
parsedata *createParsedata(XML_Parser parser, g2sprop * prop);
|
35 |
void closeParsedata(parsedata * pdata);
|
36 |
|
37 |
/**
|
38 |
* message when fail to write attribute
|
39 |
*/
|
40 |
void failToWriteAttrRep(int iShape, int col, char *file, int line)
|
41 |
{
|
42 |
printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
|
43 |
line, iShape, col);
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
* shows short statistics
|
48 |
*/
|
49 |
void showStats(g2sprop * prop)
|
50 |
{
|
51 |
g2sstats *stats = prop->stats;
|
52 |
double ratio;
|
53 |
if (prop->needsStats) {
|
54 |
if (prop->parseTrk) {
|
55 |
if (stats->trkunconverted != 0) {
|
56 |
ratio =
|
57 |
(double) stats->trkunconverted / (stats->trkcount +
|
58 |
stats->
|
59 |
trkunconverted) *
|
60 |
100;
|
61 |
} else {
|
62 |
ratio = 0;
|
63 |
}
|
64 |
printf("Track Points:\n");
|
65 |
printf("\ttrack count:\t%i\n", stats->trkcount);
|
66 |
printf("\tpoint count:\t%i\n", stats->trkpoints);
|
67 |
if (!prop->isFast) {
|
68 |
printf("\ttotal length:\t%f\n", stats->trklength);
|
69 |
printf("\tunconverted:\t%i(%5.2f%%)\n",
|
70 |
stats->trkunconverted, ratio);
|
71 |
}
|
72 |
}
|
73 |
if (prop->parseRte) {
|
74 |
if (stats->rteunconverted != 0) {
|
75 |
ratio =
|
76 |
(double) stats->rteunconverted / (stats->rtecount +
|
77 |
stats->
|
78 |
rteunconverted) *
|
79 |
100;
|
80 |
} else {
|
81 |
ratio = 0;
|
82 |
}
|
83 |
printf("Routes:\n");
|
84 |
printf("\troute count:\t%i\n", stats->rtecount);
|
85 |
printf("\tpoint count:\t%i\n", stats->rtepoints);
|
86 |
if (!prop->isFast) {
|
87 |
printf("\ttotal length:\t%f\n", stats->rtelength);
|
88 |
printf("\tunconverted:\t%i(%5.2f%%)\n",
|
89 |
stats->rteunconverted, ratio);
|
90 |
}
|
91 |
}
|
92 |
if (prop->parseWpt) {
|
93 |
printf("Waypoints:\n");
|
94 |
printf("\tpoint count:\t%i\n", stats->wptpoints);
|
95 |
}
|
96 |
}
|
97 |
}
|
98 |
|
99 |
/**
|
100 |
* clears a path attribute structure
|
101 |
*/
|
102 |
void wipePathAttr(pathattr * pattr)
|
103 |
{
|
104 |
pattr->name[0] = '\0';
|
105 |
pattr->cmt[0] = '\0';
|
106 |
pattr->desc[0] = '\0';
|
107 |
pattr->src[0] = '\0';
|
108 |
pattr->link[0] = '\0';
|
109 |
pattr->number = 0;
|
110 |
pattr->type[0] = '\0';
|
111 |
pattr->length = 0;
|
112 |
pattr->interval = 0;
|
113 |
pattr->speed = 0;
|
114 |
//pattr->point = NULL;
|
115 |
pattr->count = 0;
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
* creates a new path attribute
|
120 |
*/
|
121 |
pathattr *createPathAttr(void)
|
122 |
{
|
123 |
pathattr *pattr;
|
124 |
pattr = (pathattr *) malloc(sizeof(pathattr));
|
125 |
wipePathAttr(pattr);
|
126 |
return pattr;
|
127 |
}
|
128 |
|
129 |
/**
|
130 |
* clears a element attribute structure
|
131 |
*/
|
132 |
void wipeAttr(g2sattr * attr)
|
133 |
{
|
134 |
attr->lon = 0;
|
135 |
attr->lat = 0;
|
136 |
attr->minlon = 0;
|
137 |
attr->minlat = 0;
|
138 |
attr->maxlon = 0;
|
139 |
attr->maxlat = 0;
|
140 |
attr->name[0] = '\0';
|
141 |
attr->cmt[0] = '\0';
|
142 |
attr->desc[0] = '\0';
|
143 |
attr->src[0] = '\0';
|
144 |
attr->link[0] = '\0';
|
145 |
attr->type[0] = '\0';
|
146 |
attr->time[0] = '\0';
|
147 |
attr->number = 0;
|
148 |
attr->ele = 0;
|
149 |
attr->magvar = 0;
|
150 |
attr->geoidheight = 0;
|
151 |
attr->sym[0] = '\0';
|
152 |
attr->fix[0] = '\0';
|
153 |
attr->sat = 0;
|
154 |
attr->hdop = 0;
|
155 |
attr->vdop = 0;
|
156 |
attr->pdop = 0;
|
157 |
attr->ageofdgpsdata = 0;
|
158 |
attr->dgpsid = 0;
|
159 |
attr->author[0] = '\0';
|
160 |
attr->keywords[0] = '\0';
|
161 |
attr->copyright[0] = '\0';
|
162 |
attr->year = 0;
|
163 |
attr->license[0] = '\0';
|
164 |
attr->minlat = 0;
|
165 |
attr->minlon = 0;
|
166 |
attr->maxlat = 0;
|
167 |
attr->maxlon = 0;
|
168 |
}
|
169 |
|
170 |
/**
|
171 |
* sets default values to a column properties.
|
172 |
*/
|
173 |
void setColsDefault(g2scolumns * cols)
|
174 |
{
|
175 |
cols->name = 1;
|
176 |
cols->cmt = 1;
|
177 |
cols->desc = 1;
|
178 |
cols->src = 1;
|
179 |
cols->link = 1;
|
180 |
cols->type = 1;
|
181 |
cols->time = 1;
|
182 |
cols->number = 1;
|
183 |
cols->ele = 1;
|
184 |
cols->magvar = 1;
|
185 |
cols->geoidheight = 1;
|
186 |
cols->sym = 1;
|
187 |
cols->fix = 1;
|
188 |
cols->sat = 1;
|
189 |
cols->hdop = 1;
|
190 |
cols->vdop = 1;
|
191 |
cols->pdop = 1;
|
192 |
cols->ageofdgpsdata = 1;
|
193 |
cols->dgpsid = 1;
|
194 |
cols->length = 1;
|
195 |
cols->interval = 1;
|
196 |
cols->speed = 1;
|
197 |
cols->points = 1;
|
198 |
cols->gpxline = 0;
|
199 |
}
|
200 |
|
201 |
/**
|
202 |
* creates a column structure
|
203 |
*/
|
204 |
g2scolumns *createCols(void)
|
205 |
{
|
206 |
g2scolumns *cols;
|
207 |
cols = (g2scolumns *) malloc(sizeof(g2scolumns));
|
208 |
setColsDefault(cols);
|
209 |
return cols;
|
210 |
}
|
211 |
|
212 |
/**
|
213 |
* creates a element attribute structure.
|
214 |
*/
|
215 |
g2sattr *createAttr(void)
|
216 |
{
|
217 |
g2sattr *attr;
|
218 |
attr = (g2sattr *) malloc(sizeof(g2sattr));
|
219 |
wipeAttr(attr);
|
220 |
return attr;
|
221 |
}
|
222 |
|
223 |
/**
|
224 |
* creates a properties structure for gpx2shp
|
225 |
*/
|
226 |
g2sprop *createProp(void)
|
227 |
{
|
228 |
g2sprop *prop;
|
229 |
g2sstats *stats;
|
230 |
g2scolumns *cols;
|
231 |
prop = malloc(sizeof(g2sprop));
|
232 |
stats = malloc(sizeof(g2sstats));
|
233 |
cols = createCols();
|
234 |
prop->stats = stats;
|
235 |
prop->parseWpt = 0;
|
236 |
prop->parseTrk = 0;
|
237 |
prop->parseRte = 0;
|
238 |
prop->minpoints = 2;
|
239 |
prop->minlength = 0;
|
240 |
prop->mintime = 0;
|
241 |
prop->is3d = 0;
|
242 |
prop->isEdge = 0;
|
243 |
prop->isPoint = 0;
|
244 |
prop->isFast = 0;
|
245 |
prop->needsStats = 0;
|
246 |
prop->verbose = 0;
|
247 |
prop->output = NULL;
|
248 |
prop->ellipsoid = NULL;
|
249 |
prop->lengthUnit = NULL;
|
250 |
prop->speedLengthUnit = NULL;
|
251 |
prop->speedTimeUnit = NULL;
|
252 |
prop->timeUnit = NULL;
|
253 |
prop->stats->trkcount = 0;
|
254 |
prop->stats->trkpoints = 0;
|
255 |
prop->stats->trklength = 0;
|
256 |
prop->stats->trkunconverted = 0;
|
257 |
prop->stats->rtecount = 0;
|
258 |
prop->stats->rtepoints = 0;
|
259 |
prop->stats->rtelength = 0;
|
260 |
prop->stats->rteunconverted = 0;
|
261 |
prop->stats->wptpoints = 0;
|
262 |
prop->cols = cols;
|
263 |
return prop;
|
264 |
}
|
265 |
|
266 |
/**
|
267 |
* close and free a propertires structure
|
268 |
*/
|
269 |
void closeProp(g2sprop * prop)
|
270 |
{
|
271 |
free(prop->stats);
|
272 |
free(prop->sourcefile);
|
273 |
free(prop->ellipsoid);
|
274 |
free(prop->timeUnit);
|
275 |
free(prop->speedLengthUnit);
|
276 |
free(prop->speedTimeUnit);
|
277 |
free(prop->lengthUnit);
|
278 |
free(prop->output);
|
279 |
free(prop->cols);
|
280 |
free(prop);
|
281 |
}
|
282 |
|
283 |
/**
|
284 |
* creates a shapehandles structure
|
285 |
*/
|
286 |
//shphandles *createShps(void)
|
287 |
//{
|
288 |
// shphandles *shps;
|
289 |
// shps = malloc(sizeof(shphandles));
|
290 |
// shps->trk = NULL;
|
291 |
// shps->wpt = NULL;
|
292 |
// shps->rte = NULL;
|
293 |
// shps->trk_edg = NULL;
|
294 |
// shps->rte_edg = NULL;
|
295 |
// shps->trk_pnt = NULL;
|
296 |
// shps->rte_pnt = NULL;
|
297 |
// return shps;
|
298 |
//}
|
299 |
|
300 |
/**
|
301 |
* creates a dbfhandles structure
|
302 |
*/
|
303 |
/* dbfhandles *createDbfs(void)
|
304 |
{
|
305 |
dbfhandles *dbfs;
|
306 |
dbfs = malloc(sizeof(dbfhandles));
|
307 |
dbfs->trk = NULL;
|
308 |
dbfs->wpt = NULL;
|
309 |
dbfs->rte = NULL;
|
310 |
dbfs->trk_edg = NULL;
|
311 |
dbfs->rte_edg = NULL;
|
312 |
dbfs->trk_pnt = NULL;
|
313 |
dbfs->rte_pnt = NULL;
|
314 |
return dbfs;
|
315 |
} */
|
316 |
|
317 |
/**
|
318 |
* creates a parse structure
|
319 |
*/
|
320 |
parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
|
321 |
{
|
322 |
parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
|
323 |
pdata->fp = NULL;
|
324 |
//shphandles *shps = createShps();
|
325 |
//dbfhandles *dbfs = createDbfs();
|
326 |
pathattr *pattr = createPathAttr();
|
327 |
g2sattr *attr = createAttr();
|
328 |
parent *p = (parent *) malloc(sizeof(parent));
|
329 |
parent *c = (parent *) malloc(sizeof(parent));
|
330 |
p->name = NULL;
|
331 |
p->parentptr = NULL;
|
332 |
c->name = "root";
|
333 |
c->parentptr = p;
|
334 |
pdata->depth = 0;
|
335 |
pdata->databuf = malloc(sizeof(char) * DATABUFSIZE);
|
336 |
pdata->bufptr = NULL;
|
337 |
pdata->failed = 0;
|
338 |
pdata->failedid = 0;
|
339 |
pdata->parser = parser;
|
340 |
pdata->parent = p;
|
341 |
pdata->current = c;
|
342 |
//pdata->shps = shps;
|
343 |
//pdata->dbfs = dbfs;
|
344 |
pdata->prop = prop;
|
345 |
pdata->pattr = pattr;
|
346 |
pdata->attr = attr;
|
347 |
return pdata;
|
348 |
}
|
349 |
|
350 |
/*
|
351 |
* close and free resoures
|
352 |
*/
|
353 |
void closeParsedata(parsedata * pdata)
|
354 |
{
|
355 |
//free(pdata->shps);
|
356 |
//free(pdata->dbfs);
|
357 |
free(pdata->parent);
|
358 |
free(pdata->current);
|
359 |
free(pdata->databuf);
|
360 |
free(pdata->attr);
|
361 |
free(pdata->pattr);
|
362 |
free(pdata);
|
363 |
}
|