summaryrefslogtreecommitdiff
path: root/tools/gpx2navit_txt/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/gpx2navit_txt/src')
-rw-r--r--tools/gpx2navit_txt/src/Makefile.am26
-rw-r--r--tools/gpx2navit_txt/src/config.h.in99
-rw-r--r--tools/gpx2navit_txt/src/elementControl.c245
-rw-r--r--tools/gpx2navit_txt/src/emess.h51
-rw-r--r--tools/gpx2navit_txt/src/errorcode.h41
-rw-r--r--tools/gpx2navit_txt/src/geod_for.c127
-rw-r--r--tools/gpx2navit_txt/src/geod_inv.c92
-rw-r--r--tools/gpx2navit_txt/src/geod_set.c114
-rw-r--r--tools/gpx2navit_txt/src/geodesic.h70
-rw-r--r--tools/gpx2navit_txt/src/gpx2navit_txt.h292
-rw-r--r--tools/gpx2navit_txt/src/main.c408
-rw-r--r--tools/gpx2navit_txt/src/misc.c363
-rw-r--r--tools/gpx2navit_txt/src/parser.c167
-rw-r--r--tools/gpx2navit_txt/src/setmeta.c73
-rw-r--r--tools/gpx2navit_txt/src/setpath.c260
-rw-r--r--tools/gpx2navit_txt/src/setwpt.c71
-rw-r--r--tools/gpx2navit_txt/src/utils.c218
17 files changed, 2717 insertions, 0 deletions
diff --git a/tools/gpx2navit_txt/src/Makefile.am b/tools/gpx2navit_txt/src/Makefile.am
new file mode 100644
index 00000000..5cce6fa3
--- /dev/null
+++ b/tools/gpx2navit_txt/src/Makefile.am
@@ -0,0 +1,26 @@
+bin_PROGRAMS = gpx2navit_txt
+
+gpx2navit_txt_SOURCES = \
+ emess.h \
+ geod_for.c \
+ geod_inv.c \
+ geod_set.c \
+ geodesic.h \
+ gpx2navit_txt.h \
+ main.c \
+ misc.c \
+ utils.c \
+ parser.c \
+ elementControl.c\
+ setwpt.c \
+ setpath.c \
+ setmeta.c \
+ errorcode.h
+
+INCLUDES= -I$(srcdir)
+
+AM_CFLAGS = -g
+
+debian-dist:
+ dpkg-buildpackage -rfakeroot -d -tc -us -uc
+
diff --git a/tools/gpx2navit_txt/src/config.h.in b/tools/gpx2navit_txt/src/config.h.in
new file mode 100644
index 00000000..724d6f65
--- /dev/null
+++ b/tools/gpx2navit_txt/src/config.h.in
@@ -0,0 +1,99 @@
+/* src/config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have the `alarm' function. */
+#undef HAVE_ALARM
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
+/* Define to 1 if you have the `expat' library (-lexpat). */
+#undef HAVE_LIBEXPAT
+
+/* Define to 1 if you have the `m' library (-lm). */
+#undef HAVE_LIBM
+
+/* Define to 1 if you have the `proj' library (-lproj). */
+#undef HAVE_LIBPROJ
+
+/* Define to 1 if you have the <limits.h> header file. */
+#undef HAVE_LIMITS_H
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+ to 0 otherwise. */
+#undef HAVE_MALLOC
+
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
+/* Define to 1 if you have the `memset' function. */
+#undef HAVE_MEMSET
+
+/* Define to 1 if your system has a GNU libc compatible `realloc' function,
+ and to 0 otherwise. */
+#undef HAVE_REALLOC
+
+/* Define to 1 if you have the `sqrt' function. */
+#undef HAVE_SQRT
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Name of package */
+#undef PACKAGE
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+#undef TIME_WITH_SYS_TIME
+
+/* Define to 1 if your <sys/time.h> declares `struct tm'. */
+#undef TM_IN_SYS_TIME
+
+/* Version number of package */
+#undef VERSION
+
+/* Define to empty if `const' does not conform to ANSI C. */
+#undef const
+
+/* Define to rpl_malloc if the replacement function should be used. */
+#undef malloc
+
+/* Define to rpl_realloc if the replacement function should be used. */
+#undef realloc
diff --git a/tools/gpx2navit_txt/src/elementControl.c b/tools/gpx2navit_txt/src/elementControl.c
new file mode 100644
index 00000000..924e1080
--- /dev/null
+++ b/tools/gpx2navit_txt/src/elementControl.c
@@ -0,0 +1,245 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+void startElementControl(parsedata * pdata, const char *element,
+ const char **attr);
+void endElementControl(parsedata * pdata, const char *element);
+
+/*
+ * This method controls tag start event.
+ * It corrects attributes.
+ */
+void
+startElementControl(parsedata * pdata, const char *element,
+ const char **attr)
+{
+ int i;
+ static int isFirstTrk = 1;
+ static int isFirstRte = 1;
+ static int isFirstPathpt = 1;
+ for (i = 0; attr[i]; i += 2) {
+ if (!strcmp(attr[i], "lon")) {
+ pdata->attr->lon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "lat")) {
+ pdata->attr->lat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlon")) {
+ pdata->attr->minlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlat")) {
+ pdata->attr->minlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlon")) {
+ pdata->attr->maxlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlat")) {
+ pdata->attr->maxlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "author")) {
+ strcpy(pdata->attr->author, attr[i + 1]);
+ }
+ }
+ if (pdata->prop->parseTrk) {
+ if (!strcmp(element, "trk")) {
+ if (isFirstTrk) {
+ isFirstTrk = 0;
+ }
+ }
+ if (!strcmp(element, "trkseg")) {
+ isFirstPathpt = 1;
+ }
+ if (!strcmp(element, "trkpt")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
+ }
+ if (pdata->prop->parseRte) {
+ if (!strcmp(element, "rte")) {
+ if (isFirstRte) {
+ isFirstRte = 0;
+ isFirstPathpt = 1;
+ }
+ }
+ if (!strcmp(element, "rtept")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
+ }
+}
+
+/**
+ * This method is kicked by tag end event.
+ * It corrects char elements when the element tag has some data,
+ * then start to convert when tag is top level tag like <wpt>.
+ */
+void endElementControl(parsedata * pdata, const char *element)
+{
+ static int isFirstWpt = 1;
+ static int isFirstTrkAsPoint = 1;
+ static int isFirstRteAsPoint = 1;
+ /* common elements */
+ if (!strcmp(element, "name")) {
+ strcpy(pdata->attr->name, pdata->databuf);
+ }
+ if (!strcmp(element, "cmt")) {
+ strcpy(pdata->attr->cmt, pdata->databuf);
+ }
+ if (!strcmp(element, "desc")) {
+ strcpy(pdata->attr->desc, pdata->databuf);
+ }
+ if (!strcmp(element, "src")) {
+ strcpy(pdata->attr->src, pdata->databuf);
+ }
+ if (!strcmp(element, "link")) {
+ strcpy(pdata->attr->link, pdata->databuf);
+ }
+ if (!strcmp(element, "type")) {
+ strcpy(pdata->attr->type, pdata->databuf);
+ }
+ /* waypoint and metadata elements */
+ if (!strcmp(element, "time")) {
+ strcpy(pdata->attr->time, pdata->databuf);
+ }
+ /* route and track point elements */
+ if (!strcmp(element, "number")) {
+ pdata->attr->number = atoi(pdata->databuf);
+ }
+ /* waypoint elements */
+ if (!strcmp(element, "ele")) {
+ pdata->attr->ele = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "magvar")) {
+ pdata->attr->magvar = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "geoidheight")) {
+ pdata->attr->geoidheight = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "sym")) {
+ strcpy(pdata->attr->sym, pdata->databuf);
+ }
+ if (!strcmp(element, "fix")) {
+ strcpy(pdata->attr->fix, pdata->databuf);
+ }
+ if (!strcmp(element, "sat")) {
+ pdata->attr->sat = atoi(pdata->databuf);
+ }
+ if (!strcmp(element, "hdop")) {
+ pdata->attr->hdop = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "vdop")) {
+ pdata->attr->vdop = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "pdop")) {
+ pdata->attr->pdop = atof(pdata->databuf);
+ }
+ if (!strcmp(element, "ageofdgpsdata")) {
+ pdata->attr->ageofdgpsdata = atof(pdata->databuf);
+ }
+ /* metadata elements */
+ if (!strcmp(element, "author")) {
+ strcpy(pdata->attr->author, pdata->databuf);
+ }
+ if (!strcmp(element, "keywords")) {
+ strcpy(pdata->attr->keywords, pdata->databuf);
+ }
+ if (!strcmp(element, "copyright")) {
+ strcpy(pdata->attr->copyright, pdata->databuf);
+ }
+ if (!strcmp(element, "year")) {
+ pdata->attr->year = atoi(pdata->databuf);
+ }
+ if (!strcmp(element, "license")) {
+ strcpy(pdata->attr->license, pdata->databuf);
+ }
+ if (!strcmp(element, "bounds")) {
+ /* none */
+ }
+ /* top elements */
+ /* set waypoint data */
+ if (!strcmp(element, "wpt")) {
+ if (pdata->prop->parseWpt) {
+ if (isFirstWpt) {
+ isFirstWpt = 0;
+ }
+ //todo
+ if (DEBUG) {
+ fprintf(stderr,"\neectrl wpt %s %s",
+ pdata->attr->desc,pdata->attr->name);
+ }
+ setWpt(pdata);
+ wipeAttr(pdata->attr);
+ }
+ }
+ /* set trackpoint data */
+ if (!strcmp(element, "trkpt")) {
+ if (pdata->prop->parseTrk) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set trackpoint data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstTrkAsPoint) {
+ isFirstTrkAsPoint = 0;
+ }
+ setWpt(pdata);
+ }
+ wipeAttr(pdata->attr);
+ }
+ /* write trackpoint */
+ if (!strcmp(element, "trkseg")) {
+ if (pdata->prop->parseTrk) {
+ setPath( pdata);
+ }
+ }
+ /* set route data */
+ if (!strcmp(element, "rtept")) {
+ if (pdata->prop->parseRte) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set route data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstRteAsPoint) {
+ isFirstRteAsPoint = 0;
+ }
+ setWpt( pdata);
+ }
+ wipeAttr(pdata->attr);
+ }
+ /* write route */
+ if (!strcmp(element, "rte")) {
+ if (pdata->prop->parseRte) {
+ setPath( pdata);
+ }
+ }
+ if (!strcmp(element, "metadata")) {
+ setMetadata(pdata);
+ wipeAttr(pdata->attr);
+ }
+ pdata->bufptr = NULL; //reset bufptr now
+}
diff --git a/tools/gpx2navit_txt/src/emess.h b/tools/gpx2navit_txt/src/emess.h
new file mode 100644
index 00000000..7c0375bd
--- /dev/null
+++ b/tools/gpx2navit_txt/src/emess.h
@@ -0,0 +1,51 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+/* Error message processing header file */
+#ifndef EMESS_H
+#define EMESS_H
+
+#ifndef lint
+/*static char EMESS_H_ID[] = "@(#)emess.h 4.1 93/03/08 GIE REL";*/
+#endif
+
+struct EMESS {
+ char *File_name, /* input file name */
+ *Prog_name; /* name of program */
+ int File_line; /* approximate line read
+ where error occured */
+};
+
+#ifdef EMESS_ROUTINE /* use type */
+/* for emess procedure */
+struct EMESS emess_dat = { (char *)0, (char *)0, 0 };
+
+#ifdef sun /* Archaic SunOs 4.1.1, etc. */
+extern char *sys_errlist[];
+#define strerror(n) (sys_errlist[n])
+#endif
+
+#else /* for for calling procedures */
+
+extern struct EMESS emess_dat;
+void emess(int, char *, ...);
+
+#endif /* use type */
+
+#endif /* end EMESS_H */
diff --git a/tools/gpx2navit_txt/src/errorcode.h b/tools/gpx2navit_txt/src/errorcode.h
new file mode 100644
index 00000000..f12d6cff
--- /dev/null
+++ b/tools/gpx2navit_txt/src/errorcode.h
@@ -0,0 +1,41 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef ERRORCODE_H
+#define ERRORCODE_H
+
+/* os level */
+#define ERR_OUTOFMEMORY 11
+#define ERR_CANNOTOPEN 12
+#define ERR_CREATEFILE 13
+#define ERR_READERROR 14
+#define ERR_FREEFAILED 15
+/* option */
+#define ERR_NOARGS 21
+#define ERR_WRONGOPTION 22
+#define ERR_OPTIONCONFRICT 23
+/* parser */
+#define ERR_ISNOTGPX 31
+#define ERR_PARSEERROR 32
+/* unit */
+#define ERR_ELLPSUNIT 41
+#define ERR_LENGTHUNIT 42
+#define ERR_TIMEUNIT 43
+
+#endif /* ERRORCODE_H */
diff --git a/tools/gpx2navit_txt/src/geod_for.c b/tools/gpx2navit_txt/src/geod_for.c
new file mode 100644
index 00000000..ebff3bcb
--- /dev/null
+++ b/tools/gpx2navit_txt/src/geod_for.c
@@ -0,0 +1,127 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef lint
+static const char SCCSID[] =
+ "@(#)geod_for.c 4.6 95/09/23 GIE REL";
+#endif
+# include "projects.h"
+# include "geodesic.h"
+# define MERI_TOL 1e-9
+static double th1, costh1, sinth1, sina12, cosa12, M, N, c1, c2, D, P, s1;
+static int merid, signS;
+void geod_pre(void)
+{
+ al12 = adjlon(al12); /* reduce to +- 0-PI */
+ signS = fabs(al12) > HALFPI ? 1 : 0;
+ th1 = ellipse ? atan(onef * tan(phi1)) : phi1;
+ costh1 = cos(th1);
+ sinth1 = sin(th1);
+ if ((merid = fabs(sina12 = sin(al12)) < MERI_TOL)) {
+ sina12 = 0.;
+ cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
+ M = 0.;
+ } else {
+ cosa12 = cos(al12);
+ M = costh1 * sina12;
+ }
+ N = costh1 * cosa12;
+ if (ellipse) {
+ if (merid) {
+ c1 = 0.;
+ c2 = f4;
+ D = 1. - c2;
+ D *= D;
+ P = c2 / D;
+ } else {
+ c1 = geod_f * M;
+ c2 = f4 * (1. - M * M);
+ D = (1. - c2) * (1. - c2 - c1 * M);
+ P = (1. + .5 * c1 * M) * c2 / D;
+ }
+ }
+ if (merid)
+ s1 = HALFPI - th1;
+ else {
+ s1 = (fabs(M) >= 1.) ? 0. : acos(M);
+ s1 = sinth1 / sin(s1);
+ s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
+ }
+}
+void geod_for(void)
+{
+ double d, sind, u, V, X, ds, cosds, sinds, ss = 0, de;
+
+ if (ellipse) {
+ d = geod_S / (D * geod_a);
+ if (signS)
+ d = -d;
+ u = 2. * (s1 - d);
+ V = cos(u + d);
+ X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
+ ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
+ ss = s1 + s1 - ds;
+ } else {
+ ds = geod_S / geod_a;
+ if (signS)
+ ds = -ds;
+ }
+ cosds = cos(ds);
+ sinds = sin(ds);
+ if (signS)
+ sinds = -sinds;
+ al21 = N * cosds - sinth1 * sinds;
+ if (merid) {
+ phi2 = atan(tan(HALFPI + s1 - ds) / onef);
+ if (al21 > 0.) {
+ al21 = PI;
+ if (signS)
+ de = PI;
+ else {
+ phi2 = -phi2;
+ de = 0.;
+ }
+ } else {
+ al21 = 0.;
+ if (signS) {
+ phi2 = -phi2;
+ de = 0;
+ } else
+ de = PI;
+ }
+ } else {
+ al21 = atan(M / al21);
+ if (al21 > 0)
+ al21 += PI;
+ if (al12 < 0.)
+ al21 -= PI;
+ al21 = adjlon(al21);
+ phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
+ (ellipse ? onef * M : M));
+ de = atan2(sinds * sina12,
+ (costh1 * cosds - sinth1 * sinds * cosa12));
+ if (ellipse) {
+ if (signS)
+ de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
+ else
+ de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
+ }
+ }
+ lam2 = adjlon(lam1 + de);
+}
diff --git a/tools/gpx2navit_txt/src/geod_inv.c b/tools/gpx2navit_txt/src/geod_inv.c
new file mode 100644
index 00000000..a5412825
--- /dev/null
+++ b/tools/gpx2navit_txt/src/geod_inv.c
@@ -0,0 +1,92 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef lint
+static const char SCCSID[] =
+ "@(#)geod_inv.c 4.5 95/09/23 GIE REL";
+#endif
+# include "projects.h"
+# include "geodesic.h"
+# define DTOL 1e-12
+void geod_inv(void)
+{
+ double th1,
+ th2,
+ thm,
+ dthm,
+ dlamm,
+ dlam,
+ sindlamm,
+ costhm,
+ sinthm,
+ cosdthm,
+ sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
+
+ if (ellipse) {
+ th1 = atan(onef * tan(phi1));
+ th2 = atan(onef * tan(phi2));
+ } else {
+ th1 = phi1;
+ th2 = phi2;
+ }
+ thm = .5 * (th1 + th2);
+ dthm = .5 * (th2 - th1);
+ dlamm = .5 * (dlam = adjlon(lam2 - lam1));
+ if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
+ al12 = al21 = geod_S = 0.;
+ return;
+ }
+ sindlamm = sin(dlamm);
+ costhm = cos(thm);
+ sinthm = sin(thm);
+ cosdthm = cos(dthm);
+ sindthm = sin(dthm);
+ L = sindthm * sindthm + (cosdthm * cosdthm - sinthm * sinthm)
+ * sindlamm * sindlamm;
+ d = acos(cosd = 1 - L - L);
+ if (ellipse) {
+ E = cosd + cosd;
+ sind = sin(d);
+ Y = sinthm * cosdthm;
+ Y *= (Y + Y) / (1. - L);
+ T = sindthm * costhm;
+ T *= (T + T) / L;
+ X = Y + T;
+ Y -= T;
+ T = d / sind;
+ D = 4. * T * T;
+ A = D * E;
+ B = D + D;
+ geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
+ f64 * (X * (A + (T - .5 * (A - E)) * X) -
+ Y * (B + E * Y) + D * X * Y));
+ tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
+ (f2 * T + f64 * (32. * T - (20. * T - A)
+ * X - (B +
+ 4.) * Y)) *
+ tan(dlam)));
+ } else {
+ geod_S = geod_a * d;
+ tandlammp = tan(dlamm);
+ }
+ u = atan2(sindthm, (tandlammp * costhm));
+ v = atan2(cosdthm, (tandlammp * sinthm));
+ al12 = adjlon(TWOPI + v - u);
+ al21 = adjlon(TWOPI - v - u);
+}
diff --git a/tools/gpx2navit_txt/src/geod_set.c b/tools/gpx2navit_txt/src/geod_set.c
new file mode 100644
index 00000000..4dc4b1d7
--- /dev/null
+++ b/tools/gpx2navit_txt/src/geod_set.c
@@ -0,0 +1,114 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef lint
+/*
+ * static const char SCCSID[]="@(#)geod_set.c 4.8 95/09/23 GIE REL";
+ */
+#endif
+
+#define _IN_GEOD_SET
+
+#include <string.h>
+#include "projects.h"
+#include "geodesic.h"
+#include "emess.h"
+void geod_set(int argc, char **argv)
+{
+ paralist *start = 0, *curr = NULL; /* added NULL */
+ double es;
+ char *name;
+ int i;
+
+/*
+ * put arguments into internal linked list
+ */
+ if (argc <= 0)
+ emess(1, "no arguments in initialization list");
+ for (i = 0; i < argc; ++i)
+ if (i)
+ curr = curr->next = pj_mkparam(argv[i]);
+ else
+ start = curr = pj_mkparam(argv[i]);
+/*
+ * set elliptical parameters
+ */
+ if (pj_ell_set(start, &geod_a, &es))
+ emess(1, "ellipse setup failure");
+/*
+ * set units
+ */
+ if ((name = pj_param(start, "sunits").s)) { /* added parentheses */
+ char *s;
+
+ for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
+ if (!s)
+ emess(1, "%s unknown unit conversion id", name);
+ fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
+ } else
+ to_meter = fr_meter = 1.;
+ if ((ellipse = es != 0.)) { /* added parentheses */
+ onef = sqrt(1. - es);
+ geod_f = 1 - onef;
+ f2 = geod_f / 2;
+ f4 = geod_f / 4;
+ f64 = geod_f * geod_f / 64;
+ } else {
+ onef = 1.;
+ geod_f = f2 = f4 = f64 = 0.;
+ }
+/*
+ * check if line or arc mode
+ */
+ if (pj_param(start, "tlat_1").i) {
+ double del_S;
+#undef f
+ phi1 = pj_param(start, "rlat_1").f;
+ lam1 = pj_param(start, "rlon_1").f;
+ if (pj_param(start, "tlat_2").i) {
+ phi2 = pj_param(start, "rlat_2").f;
+ lam2 = pj_param(start, "rlon_2").f;
+ geod_inv();
+ geod_pre();
+ } else if ((geod_S = pj_param(start, "dS").f)) { /* added
+ * parentheses
+ */
+ al12 = pj_param(start, "rA").f;
+ geod_pre();
+ geod_for();
+ } else
+ emess(1, "incomplete geodesic/arc info");
+ if ((n_alpha = pj_param(start, "in_A").i) > 0) {
+ if (!(del_alpha = pj_param(start, "rdel_A").f))
+ emess(1, "del azimuth == 0");
+ } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) { /* added
+ * parentheses
+ */
+ n_S = geod_S / del_S + .5;
+ } else if ((n_S = pj_param(start, "in_S").i) <= 0)
+ emess(1, "no interval divisor selected");
+ }
+/*
+ * free up linked list
+ */
+ for (; start; start = curr) {
+ curr = start->next;
+ pj_dalloc(start);
+ }
+}
diff --git a/tools/gpx2navit_txt/src/geodesic.h b/tools/gpx2navit_txt/src/geodesic.h
new file mode 100644
index 00000000..5f818c37
--- /dev/null
+++ b/tools/gpx2navit_txt/src/geodesic.h
@@ -0,0 +1,70 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef lint
+/*static char GEODESIC_H_ID[] = "@(#)geodesic.h 4.3 95/08/19 GIE REL"; */
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _IN_GEOD_SET
+# define GEOD_EXTERN extern
+#else
+# define GEOD_EXTERN
+#endif
+
+GEOD_EXTERN struct geodesic {
+ double A;
+ double LAM1, PHI1, ALPHA12;
+ double LAM2, PHI2, ALPHA21;
+ double DIST;
+ double ONEF, FLAT, FLAT2, FLAT4, FLAT64;
+ int ELLIPSE;
+} GEODESIC;
+
+# define geod_a GEODESIC.A
+# define lam1 GEODESIC.LAM1
+# define phi1 GEODESIC.PHI1
+# define al12 GEODESIC.ALPHA12
+# define lam2 GEODESIC.LAM2
+# define phi2 GEODESIC.PHI2
+# define al21 GEODESIC.ALPHA21
+# define geod_S GEODESIC.DIST
+# define geod_f GEODESIC.FLAT
+# define onef GEODESIC.ONEF
+# define f2 GEODESIC.FLAT2
+# define f4 GEODESIC.FLAT4
+# define ff2 GEODESIC.FLAT4
+# define f64 GEODESIC.FLAT64
+# define ellipse GEODESIC.ELLIPSE
+
+
+GEOD_EXTERN int n_alpha, n_S;
+GEOD_EXTERN double to_meter, fr_meter, del_alpha;
+
+void geod_set(int, char **);
+void geod_for(void);
+void geod_pre(void);
+void geod_inv(void);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tools/gpx2navit_txt/src/gpx2navit_txt.h b/tools/gpx2navit_txt/src/gpx2navit_txt.h
new file mode 100644
index 00000000..a19c436c
--- /dev/null
+++ b/tools/gpx2navit_txt/src/gpx2navit_txt.h
@@ -0,0 +1,292 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GPX2SHP_H_INCLUDED
+#define GPX2SHP_H_INCLUDED
+
+#define PROG gpx2navit_txt
+#define FILENAMELENGTH 255 /* 255 is max length for dbf string column */
+#define COMMENTLENGTH 255 /* 255 is max length for dbf string column */
+#define NAMELENGTH 32
+#define TIMELENGTH 32
+#define TYPELENGTH 16
+#define BUFFSIZE 8192
+#define DATABUFSIZE 16
+#define failToWriteAttr(S, T) failToWriteAttrRep((S), (T),__FILE__, __LINE__ )
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <libgen.h>
+#include <getopt.h>
+#include <time.h>
+#include <assert.h>
+#include <expat.h>
+#include "errorcode.h"
+//#include "shapefil.h"
+
+
+#define DEBUG 0
+/**
+ * make xml parent and child list
+ */
+typedef struct parent {
+ char *name; /** element name */
+ struct parent *parentptr;
+ /** parent pointer */
+} parent;
+
+/**
+ * set attribute columns on/off
+ */
+typedef struct g2scolumns {
+/**
+ * each member corresponds to attribute column of attribute table
+ */
+ int name;
+ int cmt;
+ int desc;
+ int src;
+ int link;
+ int type;
+ int time;
+ int number;
+ int ele;
+ int magvar;
+ int geoidheight;
+ int sym;
+ int fix;
+ int sat;
+ int hdop;
+ int vdop;
+ int pdop;
+ int ageofdgpsdata;
+ int dgpsid;
+ int length;
+ int interval;
+ int speed;
+ int points;
+ int gpxline;
+} g2scolumns;
+
+/**
+ * store each path attribute values for trackpoint and route.
+ */
+typedef struct pathattr {
+ char name[NAMELENGTH];
+ char cmt[COMMENTLENGTH];
+ char desc[COMMENTLENGTH];
+ char src[COMMENTLENGTH];
+ char link[FILENAMELENGTH];
+ int number;
+ char type[TYPELENGTH];
+ double length;
+ double interval;
+ double speed;
+ /*
+ double *x;
+ double *y;
+ double *z;
+ */
+ double *point;
+ int count;
+} pathattr;
+
+/**
+ * store each point attribute values.
+ */
+typedef struct g2sattr {
+/**
+ * the structure cames from GPX1.1 format
+ */
+ double lon;
+ double lat;
+ double minlon;
+ double minlat;
+ double maxlon;
+ double maxlat;
+ char name[NAMELENGTH];
+ char cmt[COMMENTLENGTH];
+ char desc[COMMENTLENGTH];
+ char src[COMMENTLENGTH];
+ char link[FILENAMELENGTH];
+ char type[TYPELENGTH];
+ char time[TIMELENGTH];
+ int number;
+ double ele;
+ double magvar;
+ double geoidheight;
+ char sym[NAMELENGTH];
+ char fix[NAMELENGTH];
+ int sat;
+ double hdop;
+ double vdop;
+ double pdop;
+ double ageofdgpsdata;
+ int dgpsid;
+ char author[NAMELENGTH];
+ char keywords[NAMELENGTH];
+ char copyright[NAMELENGTH];
+ int year;
+ char license[NAMELENGTH];
+} g2sattr;
+
+/**
+ * statistics structure
+ */
+typedef struct g2sstats {
+ int trkpoints; /** track point total count */
+ int trkcount; /** track path total count */
+ double trklength; /** track total length */
+ int rtepoints; /** route point total count */
+ int rtecount; /** route path totol count */
+ double rtelength; /** route total length */
+ int wptpoints; /** way point total count */
+ int trkunconverted; /** unconverted track path count */
+ int rteunconverted; /** unconverted route path count */
+} g2sstats;
+
+/**
+ * cluster of all dbfhandles
+ */
+//typedef struct dbfhandles {
+// DBFHandle trk; /** for track */
+// DBFHandle wpt; /** for waypoint */
+// DBFHandle rte; /** for route */
+// DBFHandle trk_edg; /** for track each edge */
+// DBFHandle trk_pnt; /** for track each point */
+// DBFHandle rte_edg; /** for route each edge */
+// DBFHandle rte_pnt; /** for route each point */
+//} dbfhandles;
+
+/**
+ * cluster of all shphandles
+ */
+//typedef struct shphandles {
+// SHPHandle trk; /** for track */
+// SHPHandle wpt; /** for waypoint */
+// SHPHandle rte; /** for route */
+// SHPHandle trk_edg; /** for track each edge */
+// SHPHandle trk_pnt; /** for track each point */
+// SHPHandle rte_edg; /** for route each edge */
+// SHPHandle rte_pnt; /** for route each point */
+//} shphandles;
+
+/**
+ * propaties structure for gpx2navit_txt
+ */
+typedef struct g2sprop {
+ int parseWpt; /** convert waypoint data or not */
+ int parseTrk; /** convert track data or not */
+ int parseRte; /** convert route data or not */
+ int is3d; /** using 3D mode */
+ int isEdge; /** convert path data as each separated path */
+ int isPoint; /** convert path data as point */
+ int isFast; /** fast mode that skips path check */
+ int needsStats; /** shows statistics at last */
+ int minpoints; /** minimum points to convert as a path */
+ int minlength; /** minimum length to convert as a path */
+ int mintime; /** minimum time to convert as a path */
+ int verbose; /** verbose mode on/off */
+ char *sourcefile; /** source .gpx file */
+ char *output; /** output file base name */
+ char *ellipsoid; /** ellipsoid type to calculate length */
+ char *lengthUnit; /** length unit for attributes*/
+ double length2meter;/** meter value of lenght unit */
+ char *timeUnit; /** time unit for attributes */
+ double time2sec; /** value to convert time unit to second */
+ char *speedLengthUnit;
+ /** lenght unit to calculate speed*/
+ double speed2meter; /** meter value of speedLengthUnit */
+ char *speedTimeUnit;/** time unit to calculate speed */
+ int speed2sec; /** value to convert speedTimeUnit to seconde */
+ g2sstats *stats; /** convert statistics */
+ g2scolumns *cols; /** attribute table column switch */
+} g2sprop;
+
+/**
+ * userdata structure between expat methods
+ */
+typedef struct parsedata {
+ int depth; /** xml path depth */
+ char *databuf; /** character buffer in tags */
+ char *bufptr; /** pointer to databuf to add '\0' to databuf */
+ int failed; /** xml parse failed flag */
+ int failedid; /** xml parse failed id */
+ XML_Parser parser; /** xml parser itself*/
+ parent *parent; /** pointer to parent node */
+ parent *current; /** pointer to current node */
+ FILE *fp; /** File handle to write out data points*/
+// shphandles *shps; /** .shp file cluster that is used in this program */
+// dbfhandles *dbfs; /** .dbf file cluster that is used in this program */
+ g2sattr *attr; /** each point attributes */
+ pathattr *pattr; /** each path attributes */
+ g2sprop *prop; /** propaties for this program */
+} parsedata;
+
+/* utils.c */
+void checkEllpsUnit(char *unit);
+double checkLengthUnit(char *unit);
+int checkTimeUnit(char *unit);
+double getTimeInterval(char *_t, char *t);
+double getSpeed(double length, double ti, double to_meter, int to_sec);
+double getDistance(double _x, double _y, double x, double y);
+//void closeShpFiles(shphandles * shps);
+//void closeDbfFiles(dbfhandles * dbfs);
+void *myMallocRep(size_t size, const char *fileName, int line);
+
+/* misc.c */
+void failToWriteAttrRep(int iShape, int col, char *file, int line);
+void showStats(g2sprop * prop);
+void wipePathAttr(pathattr * pattr);
+pathattr *createPathAttr(void);
+void wipeAttr(g2sattr * attr);
+void setColsDefault(g2scolumns * cols);
+g2scolumns *createCols(void);
+g2sattr *createAttr(void);
+g2sprop *createProp(void);
+void closeProp(g2sprop * prop);
+//shphandles *createShps(void);
+//dbfhandles *createDbfs(void);
+parsedata *createParsedata(XML_Parser parser, g2sprop * prop);
+void closeParsedata(parsedata * pdata);
+
+/* parser.c */
+void parseMain(g2sprop * pr);
+
+/* elementControl.c */
+void startElementControl(parsedata * pdata, const char *element,
+ const char **attr);
+void endElementControl(parsedata * pdata, const char *element);
+
+/* setwpt.c */
+void setWpt( parsedata * pdata);
+
+/* setpath.c */
+void initPathAttr(pathattr * pattr, g2sattr * attr);
+void setPathInterval(parsedata *pdata);
+void setPathData(pathattr * parrt, g2sattr * attr);
+void setPath( parsedata * pdata);
+
+/* setmetadata.c */
+void setMetadata(parsedata * pdata);
+
+#endif
diff --git a/tools/gpx2navit_txt/src/main.c b/tools/gpx2navit_txt/src/main.c
new file mode 100644
index 00000000..834ce551
--- /dev/null
+++ b/tools/gpx2navit_txt/src/main.c
@@ -0,0 +1,408 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+#include "geodesic.h"
+
+void version(void);
+void usage(char **argv);
+void setDefault(g2sprop * prop);
+void setOptions(int argc, char **argv, g2sprop * prop);
+
+/**
+ * Shows a version
+ */
+void version(void)
+{
+ fprintf(stdout, "gpx2navit_txt 0.1\n");
+ fprintf(stdout, "\n");
+ fprintf(stdout, "by Toshihiro Hiraoka\n");
+ fprintf(stdout, " Petter Reinholdtsen\n");
+}
+
+/**
+ * Shows a usage message
+ */
+void usage(char **argv)
+{
+ fprintf(stdout, "Usage: %s gpxfile [options] [-o output basename]\n",
+ argv[0]);
+ fprintf(stdout,
+ "-o, --output Sets output basename. The default is (source file\n");
+ fprintf(stdout, " name) - (extention name)\n");
+ fprintf
+ (stdout,
+ "-w, --waypoints Converts only waypoints data from a gpx file.\n");
+ fprintf(stdout,
+ "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
+ fprintf(stdout,
+ "-r, --routes Converts only routes data from a gpx file.\n");
+ fprintf(stdout,
+ "-a, --all Converts all types of data from a gpx file.(default)\n");
+ fprintf(stdout,
+ "-e, --as-edge Makes a separated output by each edges.\n");
+ fprintf(stdout,
+ "-p, --as-point Makes a separated output by each points.\n");
+ fprintf(stdout,
+ "-s, --stats Shows simple statistics of the outputs.\n");
+ fprintf(stdout,
+ "-b, --basic-columns Stores only basic data as attribures to \n");
+ fprintf(stdout,
+ " reduce memory and storage usage.\n");
+ fprintf(stdout,
+ " (ele, name, cmt, type, time, fix, sym and number).\n");
+ fprintf(stdout,
+ "-L, --no-length Removes length column from a waypoint or trackpoint\n");
+ fprintf(stdout, " attribute table.\n");
+ fprintf
+ (stdout,
+ "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
+ fprintf(stdout, " attribute table.\n");
+ fprintf
+ (stdout,
+ "-T, --no-time Removes time column from an attribute table.\n");
+ fprintf(stdout,
+ "-g, --gpxline Adds line number of GPX file as attribures.\n");
+ fprintf
+ (stdout,
+ "-f, --fast Make it faster without any checks.\n");
+ fprintf(stdout,
+ "-3, --3d Converts data using 3d format. (It's not compatible\n");
+ fprintf(stdout, " for Arcview 3.x.)\n");
+ fprintf(stdout,
+ " --min-points Sets path minimum points to convert for noise reduction.\n");
+ fprintf(stdout, " Default is 2.\n");
+ fprintf(stdout,
+ " --min-length Sets path minimum length to convert for noise reduction.\n");
+ fprintf(stdout, " Default is 0.\n");
+ fprintf(stdout,
+ " --min-time Sets path minimum time period to convert for noise\n");
+ fprintf(stdout, " reduction.\n");
+ fprintf(stdout, " Default is 0.\n");
+ fprintf(stdout,
+ " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
+ fprintf(stdout, " The default is m.\n");
+ fprintf(stdout,
+ " You can see the unit list from \"geod -lu\" command.\n");
+ fprintf
+ (stdout,
+ " --time-unit Sets time unit. The default is sec.\n");
+ fprintf(stdout,
+ " You can set from day, hour, min and sec.\n");
+ fprintf(stdout,
+ " --speed-length-unit Sets length unit for speed.\n");
+ fprintf(stdout, " The default is km.\n");
+ fprintf(stdout,
+ " You can see the unit list from \"geod -lu\" command.\n");
+ fprintf(stdout,
+ " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
+ fprintf(stdout,
+ " You can set from day, hour, min and sec.\n");
+ fprintf(stdout,
+ " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
+ fprintf(stdout, " UGS84.\n");
+ fprintf
+ (stdout,
+ " You can see the unit list from \"geod -le\" command.\n");
+ fprintf(stdout, "-v, --verbose Gives many messages.\n");
+ fprintf(stdout, " --version Shows version.\n");
+ fprintf(stdout, "-h, --help Shows this list.\n");
+}
+
+/**
+ * Sets default values to the properties when there is no user setting.
+ */
+void setDefault(g2sprop * prop)
+{
+ char *pargv[2];
+ int pargc = 2;
+ char *ellps;
+ /* if there are no options like -p,-w,-e, sets as -a */
+ if (!(prop->parseWpt | prop->parseTrk | prop->parseRte)) {
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
+ }
+ /* if there is no output setting, sets it as [sourcefile name] - ".gpx" */
+ if (prop->output == NULL) {
+ char *dot = strrchr(prop->sourcefile, '.');
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
+ if (0 == strcmp(dot, ".gpx")) {
+ int len = dot - prop->sourcefile;
+ strncpy(prop->output, prop->sourcefile, len);
+ prop->output[len] = 0;
+ } else {
+ fprintf(stderr,
+ "The source file doesn't have .gpx extension.\n");
+ exit(ERR_ISNOTGPX);
+ }
+ }
+ /* sets ellipsoid "WGS84" */
+ if (prop->ellipsoid == NULL) {
+ prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
+ strcpy(prop->ellipsoid, "WGS84");
+ }
+ /* sets lengthUnit "m" */
+ if (prop->lengthUnit == NULL) {
+ prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
+ strcpy(prop->lengthUnit, "m");
+ }
+ /* sets timeUnit "sec" */
+ if (prop->timeUnit == NULL) {
+ prop->timeUnit = (char *) malloc(sizeof(char) * 4);
+ strcpy(prop->timeUnit, "sec");
+ }
+ /* sets speedLengthUnit "km" */
+ if (prop->speedLengthUnit == NULL) {
+ prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
+ strcpy(prop->speedLengthUnit, "km");
+ }
+ /* sets speedTimeUnit "hour" */
+ if (prop->speedTimeUnit == NULL) {
+ prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
+ strcpy(prop->speedTimeUnit, "hour");
+ }
+ /* sets ellipsoid setting to geod* programs */
+ ellps = malloc(sizeof(char) * (strlen(prop->ellipsoid) + 8));
+ strcpy(ellps, "+ellps=");
+ strcat(ellps, prop->ellipsoid);
+ pargv[0] = ellps;
+ pargv[1] = prop->lengthUnit;
+ checkEllpsUnit(prop->ellipsoid);
+ prop->length2meter = checkLengthUnit(prop->lengthUnit);
+ prop->time2sec = checkTimeUnit(prop->timeUnit);
+ prop->speed2meter = checkLengthUnit(prop->speedLengthUnit);
+ prop->speed2sec = checkTimeUnit(prop->speedTimeUnit);
+ geod_set(pargc, pargv);
+ if (prop->verbose) {
+ printf("source filename:\t%s\n", prop->sourcefile);
+ printf("output file base name:\t%s\n", prop->output);
+ }
+ free(ellps);
+}
+
+/**
+ * Set options from command arguments
+ */
+void setOptions(int argc, char **argv, g2sprop * prop)
+{
+ int result;
+ /* option struct for getopt_long */
+ struct option const long_options[] = {
+ {"waypoints", no_argument, 0, 'w'},
+ {"trackpoints", no_argument, 0, 't'},
+ {"routes", no_argument, 0, 'r'},
+ {"output", required_argument, 0, 'o'},
+ {"as-edge", no_argument, 0, 'e'},
+ {"as-point", no_argument, 0, 'p'},
+ {"min-points", required_argument, 0, 'P'},
+ {"min-length", required_argument, 0, 'l'},
+ {"min-time", required_argument, 0, 'm'},
+ {"stats", no_argument, 0, 's'},
+ {"basic-columns", no_argument, 0, 'b'},
+ {"fast", no_argument, 0, 'f'},
+ {"length-unit", required_argument, 0, '4'},
+ {"time-unit", required_argument, 0, '8'},
+ {"length-ellipsoid", required_argument, 0, '7'},
+ {"speed-length-unit", required_argument, 0, '5'},
+ {"speed-time-unit", required_argument, 0, '6'},
+ {"no-speed", no_argument, 0, 'S'},
+ {"no-length", no_argument, 0, 'L'},
+ {"no-time", no_argument, 0, 'T'},
+ {"verbose", no_argument, 0, 'v'},
+ {"gpxline", no_argument, 0, 'g'},
+ {"all", no_argument, 0, 'a'},
+ {"version", no_argument, 0, 'V'},
+ {"help", no_argument, 0, '?'},
+ {0, no_argument, 0, '0'},
+ };
+ if (argc <= 1) {
+ fprintf(stderr, "There is no argument.\n");
+ usage(argv);
+ exit(ERR_NOARGS);
+ }
+ /* set option attributes */
+ while ((result =
+ getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg0",
+ long_options, NULL)) != -1) {
+ switch (result) {
+ case '3': /* 3d output */
+ prop->is3d = 1;
+ break;
+ case 'w': /* converts only waypoint */
+ prop->parseWpt = 1;
+ break;
+ case 't': /* converts only trackpoint */
+ prop->parseTrk = 1;
+ break;
+ case 'r': /* converts only route */
+ prop->parseRte = 1;
+ break;
+ case 'a': /* converts all */
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
+ break;
+ case 'o': /* sets basename of output file */
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(optarg) + 1);
+ strcpy(prop->output, optarg);
+ break;
+ case 'e': /* make output by each edges */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -e cannot use with -f\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isEdge = 1;
+ break;
+ case 'p': /* make output by each edges */
+ prop->isPoint = 1;
+ break;
+ case 'f': /* make it faster */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -f cannot use with -e\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isFast = 1;
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'P': /* sets minimun points as a path */
+ prop->minpoints = atoi(optarg);
+ break;
+ case 'l': /* sets minimun length as a path */
+ prop->minlength = atoi(optarg);
+ break;
+ case 'm': /* sets minimun time as a path */
+ prop->mintime = atoi(optarg);
+ break;
+ case 'b': /* use only some columns */
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'S': /* doesn't make speed column */
+ prop->cols->speed = 0;
+ break;
+ case '4': /* sets length unit */
+ prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->lengthUnit, optarg);
+ break;
+ case '5': /* sets length unit for calculating speed */
+ prop->speedLengthUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedLengthUnit, optarg);
+ break;
+ case '6': /* sets time unit for calculating speed */
+ prop->speedTimeUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedTimeUnit, optarg);
+ break;
+ case '7': /* sets ellipsoid for calculating length */
+ prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->ellipsoid, optarg);
+ break;
+ case '8': /* sets time unit */
+ prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->timeUnit, optarg);
+ break;
+ case 'L': /* doesn't make length column */
+ prop->cols->length = 0;
+ break;
+ case 'T': /* doesn't make time column */
+ prop->cols->interval = 0;
+ break;
+ case 's': /* shows source file stats */
+ prop->needsStats = 1;
+ break;
+ case 'v': /* verbose mode */
+ prop->verbose = 1;
+ break;
+ case 'V': /* shows version */
+ version();
+ exit(EXIT_SUCCESS);
+ break;
+ case 'g': /* adds gpx line number column */
+ prop->cols->gpxline = 1;
+ break;
+ case ':':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ case '0':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ default:
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ }
+ }
+ /* gets a source file name */
+ if(argv[optind] == NULL) {
+ fprintf(stderr, "There is no gpxfile description.\n");
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ }
+ prop->sourcefile = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
+ /** @note needs to change here to support
+ * a several files convertion */
+ strcpy(prop->sourcefile, argv[optind]);
+ setDefault(prop);
+}
+
+/**
+ * Main
+ */
+int main(int argc, char **argv)
+{
+ g2sprop *prop;
+ prop = createProp();
+ setOptions(argc, argv, prop);
+ parseMain(prop);
+ if (prop->needsStats)
+ showStats(prop);
+ closeProp(prop);
+ return (0);
+}
diff --git a/tools/gpx2navit_txt/src/misc.c b/tools/gpx2navit_txt/src/misc.c
new file mode 100644
index 00000000..fc272e8c
--- /dev/null
+++ b/tools/gpx2navit_txt/src/misc.c
@@ -0,0 +1,363 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+void failToWriteAttrRep(int iShape, int col, char *file, int line);
+void showStats(g2sprop * prop);
+void wipePathAttr(pathattr * pattr);
+pathattr *createPathAttr(void);
+void wipeAttr(g2sattr * attr);
+void setColsDefault(g2scolumns * cols);
+g2scolumns *createCols(void);
+g2sattr *createAttr(void);
+g2sprop *createProp(void);
+void closeProp(g2sprop * prop);
+//shphandles *createShps(void);
+//dbfhandles *createDbfs(void);
+parsedata *createParsedata(XML_Parser parser, g2sprop * prop);
+void closeParsedata(parsedata * pdata);
+
+/**
+ * message when fail to write attribute
+ */
+void failToWriteAttrRep(int iShape, int col, char *file, int line)
+{
+ printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
+ line, iShape, col);
+}
+
+/**
+ * shows short statistics
+ */
+void showStats(g2sprop * prop)
+{
+ g2sstats *stats = prop->stats;
+ double ratio;
+ if (prop->needsStats) {
+ if (prop->parseTrk) {
+ if (stats->trkunconverted != 0) {
+ ratio =
+ (double) stats->trkunconverted / (stats->trkcount +
+ stats->
+ trkunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Track Points:\n");
+ printf("\ttrack count:\t%i\n", stats->trkcount);
+ printf("\tpoint count:\t%i\n", stats->trkpoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->trklength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->trkunconverted, ratio);
+ }
+ }
+ if (prop->parseRte) {
+ if (stats->rteunconverted != 0) {
+ ratio =
+ (double) stats->rteunconverted / (stats->rtecount +
+ stats->
+ rteunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Routes:\n");
+ printf("\troute count:\t%i\n", stats->rtecount);
+ printf("\tpoint count:\t%i\n", stats->rtepoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->rtelength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->rteunconverted, ratio);
+ }
+ }
+ if (prop->parseWpt) {
+ printf("Waypoints:\n");
+ printf("\tpoint count:\t%i\n", stats->wptpoints);
+ }
+ }
+}
+
+/**
+ * clears a path attribute structure
+ */
+void wipePathAttr(pathattr * pattr)
+{
+ pattr->name[0] = '\0';
+ pattr->cmt[0] = '\0';
+ pattr->desc[0] = '\0';
+ pattr->src[0] = '\0';
+ pattr->link[0] = '\0';
+ pattr->number = 0;
+ pattr->type[0] = '\0';
+ pattr->length = 0;
+ pattr->interval = 0;
+ pattr->speed = 0;
+ //pattr->point = NULL;
+ pattr->count = 0;
+}
+
+/**
+ * creates a new path attribute
+ */
+pathattr *createPathAttr(void)
+{
+ pathattr *pattr;
+ pattr = (pathattr *) malloc(sizeof(pathattr));
+ wipePathAttr(pattr);
+ return pattr;
+}
+
+/**
+ * clears a element attribute structure
+ */
+void wipeAttr(g2sattr * attr)
+{
+ attr->lon = 0;
+ attr->lat = 0;
+ attr->minlon = 0;
+ attr->minlat = 0;
+ attr->maxlon = 0;
+ attr->maxlat = 0;
+ attr->name[0] = '\0';
+ attr->cmt[0] = '\0';
+ attr->desc[0] = '\0';
+ attr->src[0] = '\0';
+ attr->link[0] = '\0';
+ attr->type[0] = '\0';
+ attr->time[0] = '\0';
+ attr->number = 0;
+ attr->ele = 0;
+ attr->magvar = 0;
+ attr->geoidheight = 0;
+ attr->sym[0] = '\0';
+ attr->fix[0] = '\0';
+ attr->sat = 0;
+ attr->hdop = 0;
+ attr->vdop = 0;
+ attr->pdop = 0;
+ attr->ageofdgpsdata = 0;
+ attr->dgpsid = 0;
+ attr->author[0] = '\0';
+ attr->keywords[0] = '\0';
+ attr->copyright[0] = '\0';
+ attr->year = 0;
+ attr->license[0] = '\0';
+ attr->minlat = 0;
+ attr->minlon = 0;
+ attr->maxlat = 0;
+ attr->maxlon = 0;
+}
+
+/**
+ * sets default values to a column properties.
+ */
+void setColsDefault(g2scolumns * cols)
+{
+ cols->name = 1;
+ cols->cmt = 1;
+ cols->desc = 1;
+ cols->src = 1;
+ cols->link = 1;
+ cols->type = 1;
+ cols->time = 1;
+ cols->number = 1;
+ cols->ele = 1;
+ cols->magvar = 1;
+ cols->geoidheight = 1;
+ cols->sym = 1;
+ cols->fix = 1;
+ cols->sat = 1;
+ cols->hdop = 1;
+ cols->vdop = 1;
+ cols->pdop = 1;
+ cols->ageofdgpsdata = 1;
+ cols->dgpsid = 1;
+ cols->length = 1;
+ cols->interval = 1;
+ cols->speed = 1;
+ cols->points = 1;
+ cols->gpxline = 0;
+}
+
+/**
+ * creates a column structure
+ */
+g2scolumns *createCols(void)
+{
+ g2scolumns *cols;
+ cols = (g2scolumns *) malloc(sizeof(g2scolumns));
+ setColsDefault(cols);
+ return cols;
+}
+
+/**
+ * creates a element attribute structure.
+ */
+g2sattr *createAttr(void)
+{
+ g2sattr *attr;
+ attr = (g2sattr *) malloc(sizeof(g2sattr));
+ wipeAttr(attr);
+ return attr;
+}
+
+/**
+ * creates a properties structure for gpx2shp
+ */
+g2sprop *createProp(void)
+{
+ g2sprop *prop;
+ g2sstats *stats;
+ g2scolumns *cols;
+ prop = malloc(sizeof(g2sprop));
+ stats = malloc(sizeof(g2sstats));
+ cols = createCols();
+ prop->stats = stats;
+ prop->parseWpt = 0;
+ prop->parseTrk = 0;
+ prop->parseRte = 0;
+ prop->minpoints = 2;
+ prop->minlength = 0;
+ prop->mintime = 0;
+ prop->is3d = 0;
+ prop->isEdge = 0;
+ prop->isPoint = 0;
+ prop->isFast = 0;
+ prop->needsStats = 0;
+ prop->verbose = 0;
+ prop->output = NULL;
+ prop->ellipsoid = NULL;
+ prop->lengthUnit = NULL;
+ prop->speedLengthUnit = NULL;
+ prop->speedTimeUnit = NULL;
+ prop->timeUnit = NULL;
+ prop->stats->trkcount = 0;
+ prop->stats->trkpoints = 0;
+ prop->stats->trklength = 0;
+ prop->stats->trkunconverted = 0;
+ prop->stats->rtecount = 0;
+ prop->stats->rtepoints = 0;
+ prop->stats->rtelength = 0;
+ prop->stats->rteunconverted = 0;
+ prop->stats->wptpoints = 0;
+ prop->cols = cols;
+ return prop;
+}
+
+/**
+ * close and free a propertires structure
+ */
+void closeProp(g2sprop * prop)
+{
+ free(prop->stats);
+ free(prop->sourcefile);
+ free(prop->ellipsoid);
+ free(prop->timeUnit);
+ free(prop->speedLengthUnit);
+ free(prop->speedTimeUnit);
+ free(prop->lengthUnit);
+ free(prop->output);
+ free(prop->cols);
+ free(prop);
+}
+
+/**
+ * creates a shapehandles structure
+ */
+//shphandles *createShps(void)
+//{
+// shphandles *shps;
+// shps = malloc(sizeof(shphandles));
+// shps->trk = NULL;
+// shps->wpt = NULL;
+// shps->rte = NULL;
+// shps->trk_edg = NULL;
+// shps->rte_edg = NULL;
+// shps->trk_pnt = NULL;
+// shps->rte_pnt = NULL;
+// return shps;
+//}
+
+/**
+ * creates a dbfhandles structure
+ */
+/* dbfhandles *createDbfs(void)
+{
+ dbfhandles *dbfs;
+ dbfs = malloc(sizeof(dbfhandles));
+ dbfs->trk = NULL;
+ dbfs->wpt = NULL;
+ dbfs->rte = NULL;
+ dbfs->trk_edg = NULL;
+ dbfs->rte_edg = NULL;
+ dbfs->trk_pnt = NULL;
+ dbfs->rte_pnt = NULL;
+ return dbfs;
+} */
+
+/**
+ * creates a parse structure
+ */
+parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
+{
+ parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
+ pdata->fp = NULL;
+ //shphandles *shps = createShps();
+ //dbfhandles *dbfs = createDbfs();
+ pathattr *pattr = createPathAttr();
+ g2sattr *attr = createAttr();
+ parent *p = (parent *) malloc(sizeof(parent));
+ parent *c = (parent *) malloc(sizeof(parent));
+ p->name = NULL;
+ p->parentptr = NULL;
+ c->name = "root";
+ c->parentptr = p;
+ pdata->depth = 0;
+ pdata->databuf = malloc(sizeof(char) * DATABUFSIZE);
+ pdata->bufptr = NULL;
+ pdata->failed = 0;
+ pdata->failedid = 0;
+ pdata->parser = parser;
+ pdata->parent = p;
+ pdata->current = c;
+ //pdata->shps = shps;
+ //pdata->dbfs = dbfs;
+ pdata->prop = prop;
+ pdata->pattr = pattr;
+ pdata->attr = attr;
+ return pdata;
+}
+
+/*
+ * close and free resoures
+ */
+void closeParsedata(parsedata * pdata)
+{
+ //free(pdata->shps);
+ //free(pdata->dbfs);
+ free(pdata->parent);
+ free(pdata->current);
+ free(pdata->databuf);
+ free(pdata->attr);
+ free(pdata->pattr);
+ free(pdata);
+}
diff --git a/tools/gpx2navit_txt/src/parser.c b/tools/gpx2navit_txt/src/parser.c
new file mode 100644
index 00000000..dc62d71f
--- /dev/null
+++ b/tools/gpx2navit_txt/src/parser.c
@@ -0,0 +1,167 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+void charHandle(void *userdata, const XML_Char * data, int length);
+void startElement(void *userdata, const char *element, const char **attr);
+void endElement(void *userdata, const char *element);
+void parseMain(g2sprop * prop);
+
+/**
+ * a handler to parse charctor data on expat
+ */
+void charHandle(void *userdata, const XML_Char * data, int length)
+{
+ static int bufsize = DATABUFSIZE;
+ static int string_length = 0;
+ int new_length;
+ static int begin_copy = 0;
+ int i;
+ parsedata *pdata = (parsedata *) userdata;
+ if (pdata->bufptr == NULL) {
+ //start of buffer -->pdata->bufptr set to 0 at endelement
+ string_length = 0;
+ begin_copy = 0; //begin to copy after first space
+ pdata->bufptr= pdata->databuf;
+ }
+ new_length = string_length + length + 1; //additonal 0
+ if (bufsize < new_length) {
+ pdata->databuf =
+ realloc(pdata->databuf, new_length);
+ bufsize = new_length;
+ //because of realloc the pointer may have changed
+ pdata->bufptr = pdata->databuf + string_length;
+ }
+ // because expat calls this routine several times on special chars
+ // we need to do following
+ // --concat strings until reset (bufptr set to NULL)
+ // --filter out blank chars at begin of string
+ for (i=0; i<length;i++) {
+ if (begin_copy || !isspace(data[i])) {
+ *pdata->bufptr = data[i];
+ pdata->bufptr++;
+ string_length ++;
+ begin_copy = 1;
+ if (DEBUG) fprintf(stderr,"%c",data[i]);
+ }
+ }
+ *pdata->bufptr = '\0';
+}
+
+/**
+ * a handler when a element starts
+ */
+void startElement(void *userdata, const char *element, const char **attr)
+{
+ parsedata *pdata = (parsedata *) userdata;
+ pdata->parent = pdata->current;
+ pdata->current = malloc(sizeof(parent));
+ pdata->current->name = malloc(sizeof(char) * (strlen(element) + 1));
+ strcpy(pdata->current->name, element);
+ pdata->current->parentptr = pdata->parent;
+ startElementControl(pdata, element, attr);
+ if (pdata->prop->verbose) {
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("<%s>: ", element);
+ for (i = 0; attr[i]; i += 2) {
+ printf(" %s='%s'", attr[i], attr[i + 1]);
+ }
+ printf("\n");
+ }
+ pdata->depth++;
+}
+
+/**
+ * a handler when a element ends
+ */
+void endElement(void *userdata, const char *element)
+{
+ parsedata *pdata = (parsedata *) userdata;
+ endElementControl(pdata, element);
+ pdata->depth--;
+ if (pdata->prop->verbose) {
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("</%s>:%s\n ", element,pdata->parent->name);
+ }
+ free(pdata->current->name);
+ free(pdata->current);
+ pdata->current = pdata->parent;
+ pdata->parent = pdata->parent->parentptr;
+}
+
+void parseMain(g2sprop * prop)
+{
+ FILE *fp;
+ char buff[BUFFSIZE];
+ XML_Parser parser;
+ parsedata *pdata;
+ fp = fopen(prop->sourcefile, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
+ exit(ERR_CANNOTOPEN);
+ }
+ parser = XML_ParserCreate(NULL);
+ if (!parser) {
+ fprintf(stderr, "Couldn't allocate memory for parser\n");
+ exit(ERR_OUTOFMEMORY);
+ }
+ pdata = createParsedata(parser, prop);
+
+ char *output_wpt =
+ (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
+ strcpy(output_wpt, pdata->prop->output);
+ strcat(output_wpt, "_nav.txt");
+ pdata->fp = fopen(output_wpt,"w");
+ if (pdata->fp == NULL)
+ {
+ //todo
+ fprintf(stderr,"Failure opening File %s for writing",output_wpt);
+ exit(1);
+ }
+ free(output_wpt);
+ XML_SetUserData(parser, pdata);
+ XML_SetElementHandler(parser, startElement, endElement);
+ XML_SetCharacterDataHandler(parser, charHandle);
+ for (;;) {
+ int done;
+ int len;
+ fgets(buff, BUFFSIZE, fp);
+ len = (int) strlen(buff);
+ if (ferror(fp)) {
+ fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
+ exit(ERR_READERROR);
+ }
+ done = feof(fp);
+ if (done)
+ break;
+ if (!XML_Parse(parser, buff, len, done)) {
+ fprintf(stderr, "Parse error at line %d:\n%s\n",
+ XML_GetCurrentLineNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+ exit(ERR_PARSEERROR);
+ }
+ }
+ fclose(pdata->fp); //close out file
+ closeParsedata(pdata);
+}
diff --git a/tools/gpx2navit_txt/src/setmeta.c b/tools/gpx2navit_txt/src/setmeta.c
new file mode 100644
index 00000000..86a22f70
--- /dev/null
+++ b/tools/gpx2navit_txt/src/setmeta.c
@@ -0,0 +1,73 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+/**
+ * store gpx metadata into text file
+ */
+void setMetadata(parsedata * pdata)
+{
+ g2sprop *prop = pdata->prop;
+ g2sattr *attr = pdata->attr;
+ FILE *metafile;
+ char *output = malloc(sizeof(char) * (strlen(prop->output) + 10));
+ strcpy(output, prop->output);
+ strcat(output, "_meta.txt");
+ metafile = fopen(output, "w");
+ if (metafile == NULL) {
+ fprintf(stderr, "Cannot create file: %s\n", output);
+ exit(ERR_CREATEFILE);
+ }
+ if (attr->name) {
+ fprintf(metafile, "name\t%s\n", attr->name);
+ }
+ if (attr->desc) {
+ fprintf(metafile, "description\t%s\n", attr->desc);
+ }
+ if (attr->author) {
+ fprintf(metafile, "author\t%s\n", attr->author);
+ }
+ if (attr->copyright) {
+ fprintf(metafile, "copyright\t%s\n", attr->copyright);
+ }
+ if (attr->link) {
+ fprintf(metafile, "link\t%s\n", attr->link);
+ }
+ if (attr->time) {
+ fprintf(metafile, "time\t%s\n", attr->time);
+ }
+ if (attr->keywords) {
+ fprintf(metafile, "keywords\t%s\n", attr->keywords);
+ }
+ if (attr->minlat) {
+ fprintf(metafile, "min latitude\t%f\n", attr->minlat);
+ }
+ if (attr->minlon) {
+ fprintf(metafile, "min longitude\t%f\n", attr->minlon);
+ }
+ if (attr->maxlat) {
+ fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
+ }
+ if (attr->maxlon) {
+ fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
+ }
+ fclose(metafile);
+ free(output);
+}
diff --git a/tools/gpx2navit_txt/src/setpath.c b/tools/gpx2navit_txt/src/setpath.c
new file mode 100644
index 00000000..6b4d1555
--- /dev/null
+++ b/tools/gpx2navit_txt/src/setpath.c
@@ -0,0 +1,260 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+void initPathAttr(pathattr * pattr, g2sattr * attr);
+void setEdge(parsedata * pdata, double _x, double _y, double _z,
+ double length, double interval, double speed);
+void setPathInterval(parsedata * pdata);
+void setPathData(pathattr * pattr, g2sattr * attr);
+void countUnconverted(parsedata * pdata);
+void countPath(parsedata * pdata);
+int checkPath(parsedata * pdata);
+void setPath( parsedata * pdata);
+
+
+
+/**
+ * initialize a path attribute
+ */
+void initPathAttr(pathattr * pattr, g2sattr * attr)
+{
+ strcpy(pattr->name, attr->name);
+ strcpy(pattr->cmt, attr->cmt);
+ strcpy(pattr->desc, attr->desc);
+ strcpy(pattr->src, attr->src);
+ strcpy(pattr->link, attr->link);
+ pattr->number = attr->number;
+ strcpy(pattr->type, attr->type);
+ pattr->length = 0;
+ pattr->interval = 0;
+ pattr->speed = 0;
+ pattr->count = 0;
+ pattr->point = NULL;
+}
+
+
+/**
+ * set edge data and store it
+ */
+void setEdge(parsedata * pdata, double _x, double _y, double _z,
+ double length, double interval, double speed)
+{
+ pathattr *pattr = pdata->pattr;
+ static int isFirstTrkAsEdge = 1;
+ static int isFirstRteAsEdge = 1;
+ double x[2], y[2], z[2];
+ double _length, _interval, _speed;
+ if (!strcmp(pdata->current->name, "trkpt")) {
+ if (isFirstTrkAsEdge) {
+ isFirstTrkAsEdge = 0;
+ }
+ } else {
+ if (isFirstRteAsEdge) {
+ isFirstRteAsEdge = 0;
+ }
+ }
+ _length = pattr->length;
+ _interval = pattr->interval;
+ _speed = pattr->speed;
+ pattr->length = length;
+ pattr->interval = interval;
+ pattr->speed = speed;
+ x[0] = _x;
+ y[0] = _y;
+ z[0] = _z;
+ x[1] = pdata->attr->lon;
+ y[1] = pdata->attr->lat;
+ z[1] = pdata->attr->ele;
+ if (pdata->prop->is3d) {
+ } else {
+ }
+ pattr->length = _length;
+ pattr->interval = _interval;
+ pattr->speed = _speed;
+}
+
+/**
+ * sets interval data between two track points
+ */
+void setPathInterval(parsedata * pdata)
+{
+ pathattr *pattr = pdata->pattr;
+ g2sattr *attr = pdata->attr;
+ g2sprop *prop = pdata->prop;
+ static char _t[TIMELENGTH];
+ double intvl = 0;
+ static double _x, _y, _z;
+ double leng = 0;
+ double spd;
+ if (pattr->count == 1) {
+ strcpy(_t, attr->time);
+ } else {
+ /* time interval */
+ intvl = getTimeInterval(_t, attr->time);
+ pattr->interval = pattr->interval + intvl;
+ strcpy(_t, attr->time);
+ /* length interval */
+ leng = getDistance(_x, _y, attr->lon, attr->lat);
+ pattr->length = pattr->length + leng;
+ /* interval speed */
+ spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
+ /* sets edge data */
+ if (prop->isEdge) {
+ setEdge(pdata, _x, _y, _z, leng, intvl, spd);
+ }
+ }
+ _x = attr->lon;
+ _y = attr->lat;
+ _z = attr->ele;
+}
+
+/**
+ * sets each track point data in array.
+ */
+void setPathData(pathattr * pattr, g2sattr * attr)
+{
+ const int reallocsize = 100;
+ if (pattr->count == 0) {
+ pattr->point = malloc(sizeof(double) * 3 * reallocsize);
+ }
+ if ((pattr->count % reallocsize) == 0) {
+ pattr->point = realloc(pattr->point,
+ sizeof(double) * 3 * (pattr->count +
+ reallocsize));
+ }
+ pattr->point[pattr->count * 3] = attr->lon;
+ pattr->point[pattr->count * 3 + 1] = attr->lat;
+ pattr->point[pattr->count * 3 + 2] = attr->ele;
+ pattr->count++;
+}
+
+/**
+ * counts paths that wasn't converted
+ */
+void countUnconverted(parsedata * pdata)
+{
+ g2sstats *stats = pdata->prop->stats;
+ if (!strcmp(pdata->current->name, "trkseg"))
+ stats->trkunconverted++;
+ else
+ stats->rteunconverted++;
+}
+
+/**
+ * counts paths
+ */
+void countPath(parsedata * pdata)
+{
+ g2sstats *stats = pdata->prop->stats;
+ pathattr *pattr = pdata->pattr;
+ if (!strcmp(pdata->current->name, "trkseg")) {
+ stats->trkcount++;
+ stats->trklength += pattr->length;
+ stats->trkpoints += pattr->count;
+ } else {
+ stats->rtecount++;
+ stats->rtelength += pattr->length;
+ stats->rtepoints += pattr->count;
+ }
+}
+
+int checkPath(parsedata * pdata)
+{
+ pathattr *pattr = pdata->pattr;
+ g2sprop *prop = pdata->prop;
+ /* check point count. */
+ if (pattr->count < prop->minpoints) {
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because of less then %d points. \n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minpoints);
+ countUnconverted(pdata);
+ return 0;
+ /* check path length */
+ } else if (pattr->length < prop->minlength * prop->length2meter) {
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %dm.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minlength);
+ countUnconverted(pdata);
+ return 0;
+ /* check path time */
+ } else if (pattr->interval < prop->mintime * prop->time2sec) {
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %d sed.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->mintime);
+ countUnconverted(pdata);
+ return 0;
+ /* check path speed */
+ } else if (pattr->speed == .0) {
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because no move recorded.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
+ countUnconverted(pdata);
+ return 0;
+ }
+ return 1;
+}
+
+/**
+ * saves path data into files.
+ */
+void setPath( parsedata * pdata)
+{
+ pathattr *pattr = pdata->pattr;
+ g2sprop *prop = pdata->prop;
+ int isOk = 0;
+ pattr->speed =
+ getSpeed(pattr->length, pattr->interval, prop->speed2meter,
+ prop->speed2sec);
+ if (prop->isFast) {
+ isOk = 1;
+ } else {
+ isOk = checkPath(pdata);
+ }
+ if (isOk) {
+ double x[pattr->count];
+ double y[pattr->count];
+ double z[pattr->count];
+ int i;
+ fprintf(pdata->fp,"type=track label=\"%s\" desc=\"%s\" type=\"%s\"\ length=\"%5.3f\" count=\"%5d\"\n"
+ ,pdata->pattr->name,pdata->pattr->desc,
+ pdata->pattr->type,pdata->pattr->length,
+ pdata->pattr->count);
+
+ for (i = 0; i < pattr->count; i++) {
+ x[i] = pattr->point[i * 3];
+ y[i] = pattr->point[i * 3 + 1];
+ z[i] = pattr->point[i * 3 + 2];
+ fprintf(pdata->fp,"%3.6f %4.6f\n",x[i],y[i]);
+ }
+ if (pdata->prop->is3d) {
+ } else {
+ }
+ countPath(pdata);
+ }
+ free(pattr->point);
+}
diff --git a/tools/gpx2navit_txt/src/setwpt.c b/tools/gpx2navit_txt/src/setwpt.c
new file mode 100644
index 00000000..3fc04f71
--- /dev/null
+++ b/tools/gpx2navit_txt/src/setwpt.c
@@ -0,0 +1,71 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+
+void setWpt(parsedata * pdata);
+
+/**
+ * save point objects in *_wpt or *_pnt file
+ */
+void setWpt( parsedata * pdata)
+{
+ double x[1], y[1], z[1];
+ x[0] = pdata->attr->lon;
+ y[0] = pdata->attr->lat;
+ z[0] = pdata->attr->ele;
+ if (pdata->prop->is3d) {
+ //nothing at the moment
+ } else {
+ //do not know if i will change something here
+ }
+ // Write attributes to file first line waypoint-info, second line coords
+ char poi_type[20]="poi_attraction";
+ if (!strcmp(pdata->attr->type,"Geocache|Traditional Cache"))
+ strcpy(poi_type,"poi_gc_tradi");
+ if (!strcmp(pdata->attr->type,"Geocache|Multi-cache"))
+ strcpy(poi_type,"poi_gc_multi");
+ if (!strcmp(pdata->attr->type,"Geocache|Unknown Cache"))
+ strcpy(poi_type,"poi_gc_mystery");
+ if (!strcmp(pdata->attr->type,"Geocache|Event Cache"))
+ strcpy(poi_type,"poi_gc_event");
+ if (!strcmp(pdata->attr->type,"Geocache")) //for OC
+ strcpy(poi_type,"poi_gc_tradi");
+ if (!strcmp(pdata->attr->type,"Waypoint|Parking Area"))
+ strcpy(poi_type,"poi_car_parking");
+ if (!strcmp(pdata->attr->type,"Waypoint|Question to Answer"))
+ strcpy(poi_type,"poi_gc_question");
+ if (!strcmp(pdata->attr->type,"Waypoint|Reference Point"))
+ strcpy(poi_type,"poi_gc_reference");
+ if (!strcmp(pdata->attr->type,"Waypoint|Stages of a Multicache"))
+ strcpy(poi_type,"poi_gc_stages");
+
+ //generate the file
+ fprintf(pdata->fp,"type=%s label=\"%s\" description=\"%s\" gc_type=\"%s\"\n",
+ poi_type,pdata->attr->name,pdata->attr->desc,pdata->attr->type);
+ fprintf(pdata->fp,"%3.6f %4.6f\n",x[0],y[0]);
+
+ //writeWptAttribute(hDBF, pdata, iShape);
+ if (!strcmp(pdata->current->name, "wpt")) {
+ pdata->prop->stats->wptpoints++;
+ }
+ return;
+}
+
+
diff --git a/tools/gpx2navit_txt/src/utils.c b/tools/gpx2navit_txt/src/utils.c
new file mode 100644
index 00000000..4a215fd9
--- /dev/null
+++ b/tools/gpx2navit_txt/src/utils.c
@@ -0,0 +1,218 @@
+/**
+ * Navit, a modular navigation system.
+ * Copyright (C) 2005-2008 Navit Team
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gpx2navit_txt.h"
+#include "projects.h"
+#include "geodesic.h"
+
+double getDistanceCore(char *p1, char *l1, char *p2, char *l2);
+void checkEllpsUnit(char *unit);
+double checkLengthUnit(char *unit);
+int checkTimeUnit(char *unit);
+double getTimeInterval(char *_t, char *t);
+double getSpeed(double length, double ti, double to_meter, int to_sec);
+double getDistance(double _x, double _y, double x, double y);
+// todo void closeShpFiles(shphandles * shps);
+// todo void closeDbfFiles(dbfhandles * dbfs);
+void *myMallocRep(size_t size, const char *fileName, int line);
+
+void checkEllpsUnit(char *unit)
+{
+/*
+ * checks ellipse unit can be used by proj4
+ */
+ int isOK = 0;
+ struct PJ_ELLPS *el; /* project.h of proj4 */
+ for (el = pj_ellps; el->id; ++el) {
+ if (!strcmp(el->id, unit)) {
+ isOK = 1;
+ }
+ }
+ if (!isOK) {
+ fputs
+ ("The ellipse argument is not correct or supported by libproj\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (el = pj_ellps; el->id; el++) {
+ printf("%10s\t%s\n", el->id, el->name);
+ }
+ exit(ERR_ELLPSUNIT);
+ }
+}
+
+double checkLengthUnit(char *unit)
+{
+/*
+ * checks length unit can be used by proj4
+ * then returns unit value to meter
+ */
+ int isOK = 0;
+ double to_meter = 0;
+ struct PJ_UNITS *ut; /* project.h of proj4 */
+ for (ut = pj_units; ut->id; ut++) {
+ if (!strcmp(ut->id, unit)) {
+ isOK = 1;
+ to_meter = atof(ut->to_meter);
+ }
+ }
+ if (!isOK) {
+ fputs
+ ("The length unit argument is not correct or supported by libproj.\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (ut = pj_units; ut->id; ut++) {
+ printf("%s\t%s\n", ut->id, ut->name);
+ }
+ exit(ERR_LENGTHUNIT);
+ }
+ return to_meter;
+}
+
+int checkTimeUnit(char *unit)
+{
+ char *u[8] = { "sec", "s", "min", "m", "hour", "h", "day", "d" };
+ int p[8] = { 1, 1, 60, 60, 3600, 3600, 86400, 86400 };
+ int i, to_sec = 0;
+ for (i = 0; i < 8; i++) {
+ if (!strcmp(u[i], unit)) {
+ to_sec = p[i];
+ }
+ }
+ if (!to_sec) {
+ fputs("The time unit argument is not correct.\n", stderr);
+ fputs("You can choose the argument from sec, min, hour or day.\n",
+ stderr);
+ exit(ERR_TIMEUNIT);
+ }
+ return to_sec;
+}
+
+double getTimeInterval(char *_t, char *t)
+{
+/*
+ * Returns a time interval between _t and t.
+ * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
+ * datetime format without time zone) format.
+ */
+ double ti;
+ struct tm _tt;
+ struct tm tt;
+ time_t _tmt, tmt;
+ memset(&_tt, 0, sizeof(_tt));
+ memset(&tt, 0, sizeof(tt));
+ sscanf(_t, "%d-%d-%dT%d:%d:%dZ", &_tt.tm_year, &_tt.tm_mon,
+ &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
+ _tt.tm_year -= 1900;
+ _tt.tm_mon -= 1;
+ sscanf(t, "%d-%d-%dT%d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday,
+ &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
+ tt.tm_year -= 1900;
+ tt.tm_mon -= 1;
+ _tmt = mktime(&_tt);
+ tmt = mktime(&tt);
+ ti = difftime(tmt, _tmt);
+ return ti;
+}
+
+double getSpeed(double length, double ti, double to_meter, int to_sec)
+{
+/*
+ * Culculates speed from length and time.
+ */
+ double speed;
+ if (!length || !ti)
+ speed = 0;
+ else
+ speed = (length / to_meter) / (ti / to_sec);
+ return speed;
+}
+
+double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
+{
+ /*
+ * Culculates a geodesic length between two points
+ * using geod_*.c
+ */
+ phi1 = dmstor(p1, &p1);
+ lam1 = dmstor(l1, &l1);
+ phi2 = dmstor(p2, &p2);
+ lam2 = dmstor(l2, &l2);
+ geod_inv();
+ return geod_S;
+}
+
+double getDistance(double _x, double _y, double x, double y)
+{
+ /*
+ * Culculates a geodesic length between two points
+ */
+ double length;
+ char p1[17], l1[17], p2[17], l2[17];
+ sprintf(p1, "%f", _x);
+ sprintf(l1, "%f", _y);
+ sprintf(p2, "%f", x);
+ sprintf(l2, "%f", y);
+ length = getDistanceCore(p1, l1, p2, l2);
+ return length;
+}
+
+//todo void closeShpFiles(shphandles * shps)
+//{
+ /*
+ * Closes all SHP files if they opened
+ */
+// if (shps->wpt)
+// SHPClose(shps->wpt);
+// if (shps->trk)
+// SHPClose(shps->trk);
+// if (shps->trk_edg)
+// SHPClose(shps->trk_edg);
+// if (shps->trk_pnt)
+// SHPClose(shps->trk_pnt);
+// if (shps->rte)
+// SHPClose(shps->rte);
+// if (shps->rte_edg)
+// SHPClose(shps->rte_edg);
+// if (shps->rte_pnt)
+// SHPClose(shps->rte_pnt);
+//}
+
+//todo void closeDbfFiles(dbfhandles * dbfs)
+//{
+ /*
+ * Closes all DBF files if they opened
+ */
+// if (dbfs->wpt)
+// DBFClose(dbfs->wpt);
+// if (dbfs->trk)
+// DBFClose(dbfs->trk);
+// if (dbfs->trk_edg)
+// DBFClose(dbfs->trk_edg);
+// if (dbfs->trk_pnt)
+// DBFClose(dbfs->trk_pnt);
+// if (dbfs->rte)
+// DBFClose(dbfs->rte);
+// if (dbfs->rte_edg)
+// DBFClose(dbfs->rte_edg);
+// if (dbfs->rte_pnt)
+// DBFClose(dbfs->rte_pnt);
+//}
+