• R/O
  • SSH
  • HTTPS

gpx2shp: 提交


Commit MetaInfo

修订版6 (tree)
时间2013-07-03 19:48:31
作者pagong

Log Message

* Formated the codes.

更改概述

差异

--- trunk/patch/rodney.patch (nonexistent)
+++ trunk/patch/rodney.patch (revision 6)
@@ -0,0 +1,11 @@
1+--- src/setpath.c.orig 2005-02-06 09:58:47.000000000 -0500
2++++ src/setpath.c 2008-10-25 07:08:25.000000000 -0400
3+@@ -422,7 +422,7 @@
4+ countUnconverted(pdata);
5+ return 0;
6+ /* check path speed */
7+- } else if (pattr->speed == .0) {
8++ } else if (0 && pattr->speed == .0) {
9+ fprintf
10+ (stderr,
11+ "gpx2shp:%s:%i track was not converted because no move recorded.\n",
--- trunk/gpx2shp/src/utils.c (revision 5)
+++ trunk/gpx2shp/src/utils.c (revision 6)
@@ -13,187 +13,175 @@
1313 void closeDbfFiles(dbfhandles * dbfs);
1414 void *myMallocRep(size_t size, const char *fileName, int line);
1515
16-void checkEllpsUnit(char *unit)
17-{
18-/*
19- * checks ellipse unit can be used by proj4
20- */
21- int isOK = 0;
22- struct PJ_ELLPS *el; /* project.h of proj4 */
23- for (el = pj_ellps; el->id; ++el) {
24- if (!strcmp(el->id, unit)) {
25- isOK = 1;
16+void checkEllpsUnit(char *unit) {
17+ /*
18+ * checks ellipse unit can be used by proj4
19+ */
20+ int isOK = 0;
21+ struct PJ_ELLPS *el; /* project.h of proj4 */
22+ for (el = pj_ellps; el->id; ++el) {
23+ if (!strcmp(el->id, unit)) {
24+ isOK = 1;
25+ }
2626 }
27- }
28- if (!isOK) {
29- fputs
30- ("The ellipse argument is not correct or supported by libproj\n",
31- stderr);
32- fputs("You can choose the argument from a list below.\n\n",
33- stderr);
34- for (el = pj_ellps; el->id; el++) {
35- printf("%10s\t%s\n", el->id, el->name);
27+ if (!isOK) {
28+ fputs("The ellipse argument is not correct or supported by libproj\n",
29+ stderr);
30+ fputs("You can choose the argument from a list below.\n\n", stderr);
31+ for (el = pj_ellps; el->id; el++) {
32+ printf("%10s\t%s\n", el->id, el->name);
33+ }
34+ exit(ERR_ELLPSUNIT);
3635 }
37- exit(ERR_ELLPSUNIT);
38- }
3936 }
4037
41-double checkLengthUnit(char *unit)
42-{
43-/*
44- * checks length unit can be used by proj4
45- * then returns unit value to meter
46- */
47- int isOK = 0;
48- double to_meter = 0;
49- struct PJ_UNITS *ut; /* project.h of proj4 */
50- for (ut = pj_units; ut->id; ut++) {
51- if (!strcmp(ut->id, unit)) {
52- isOK = 1;
53- to_meter = atof(ut->to_meter);
54- }
55- }
56- if (!isOK) {
57- fputs
58- ("The length unit argument is not correct or supported by libproj.\n",
59- stderr);
60- fputs("You can choose the argument from a list below.\n\n",
61- stderr);
38+double checkLengthUnit(char *unit) {
39+ /*
40+ * checks length unit can be used by proj4
41+ * then returns unit value to meter
42+ */
43+ int isOK = 0;
44+ double to_meter = 0;
45+ struct PJ_UNITS *ut; /* project.h of proj4 */
6246 for (ut = pj_units; ut->id; ut++) {
63- printf("%s\t%s\n", ut->id, ut->name);
47+ if (!strcmp(ut->id, unit)) {
48+ isOK = 1;
49+ to_meter = atof(ut->to_meter);
50+ }
6451 }
65- exit(ERR_LENGTHUNIT);
66- }
67- return to_meter;
52+ if (!isOK) {
53+ fputs(
54+ "The length unit argument is not correct or supported by libproj.\n",
55+ stderr);
56+ fputs("You can choose the argument from a list below.\n\n", stderr);
57+ for (ut = pj_units; ut->id; ut++) {
58+ printf("%s\t%s\n", ut->id, ut->name);
59+ }
60+ exit(ERR_LENGTHUNIT);
61+ }
62+ return to_meter;
6863 }
6964
70-int checkTimeUnit(char *unit)
71-{
72- char *u[8] = { "sec", "s", "min", "m", "hour", "h", "day", "d" };
73- int p[8] = { 1, 1, 60, 60, 3600, 3600, 86400, 86400 };
74- int i, to_sec = 0;
75- for (i = 0; i < 8; i++) {
76- if (!strcmp(u[i], unit)) {
77- to_sec = p[i];
65+int checkTimeUnit(char *unit) {
66+ char *u[8] = { "sec", "s", "min", "m", "hour", "h", "day", "d" };
67+ int p[8] = { 1, 1, 60, 60, 3600, 3600, 86400, 86400 };
68+ int i, to_sec = 0;
69+ for (i = 0; i < 8; i++) {
70+ if (!strcmp(u[i], unit)) {
71+ to_sec = p[i];
72+ }
7873 }
79- }
80- if (!to_sec) {
81- fputs("The time unit argument is not correct.\n", stderr);
82- fputs("You can choose the argument from sec, min, hour or day.\n",
83- stderr);
84- exit(ERR_TIMEUNIT);
85- }
86- return to_sec;
74+ if (!to_sec) {
75+ fputs("The time unit argument is not correct.\n", stderr);
76+ fputs("You can choose the argument from sec, min, hour or day.\n",
77+ stderr);
78+ exit(ERR_TIMEUNIT);
79+ }
80+ return to_sec;
8781 }
8882
89-double getTimeInterval(char *_t, char *t)
90-{
91-/*
92- * Returns a time interval between _t and t.
93- * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
94- * datetime format without time zone) format.
95- */
96- double ti;
97- struct tm _tt;
98- struct tm tt;
99- time_t _tmt, tmt;
100- memset(&_tt, 0, sizeof(_tt));
101- memset(&tt, 0, sizeof(tt));
102- sscanf(_t, "%d-%d-%dT%d:%d:%dZ", &_tt.tm_year, &_tt.tm_mon,
103- &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
104- _tt.tm_year -= 1900;
105- _tt.tm_mon -= 1;
106- sscanf(t, "%d-%d-%dT%d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday,
107- &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
108- tt.tm_year -= 1900;
109- tt.tm_mon -= 1;
110- _tmt = mktime(&_tt);
111- tmt = mktime(&tt);
112- ti = difftime(tmt, _tmt);
113- return ti;
83+double getTimeInterval(char *_t, char *t) {
84+ /*
85+ * Returns a time interval between _t and t.
86+ * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
87+ * datetime format without time zone) format.
88+ */
89+ double ti;
90+ struct tm _tt;
91+ struct tm tt;
92+ time_t _tmt, tmt;
93+ memset(&_tt, 0, sizeof(_tt));
94+ memset(&tt, 0, sizeof(tt));
95+ sscanf(_t, "%d-%d-%dT%d:%d:%dZ", &_tt.tm_year, &_tt.tm_mon, &_tt.tm_mday,
96+ &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
97+ _tt.tm_year -= 1900;
98+ _tt.tm_mon -= 1;
99+ sscanf(t, "%d-%d-%dT%d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday,
100+ &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
101+ tt.tm_year -= 1900;
102+ tt.tm_mon -= 1;
103+ _tmt = mktime(&_tt);
104+ tmt = mktime(&tt);
105+ ti = difftime(tmt, _tmt);
106+ return ti;
114107 }
115108
116-double getSpeed(double length, double ti, double to_meter, int to_sec)
117-{
118-/*
119- * Culculates speed from length and time.
120- */
121- double speed;
122- if (!length || !ti)
123- speed = 0;
124- else
125- speed = (length / to_meter) / (ti / to_sec);
126- return speed;
109+double getSpeed(double length, double ti, double to_meter, int to_sec) {
110+ /*
111+ * Culculates speed from length and time.
112+ */
113+ double speed;
114+ if (!length || !ti)
115+ speed = 0;
116+ else
117+ speed = (length / to_meter) / (ti / to_sec);
118+ return speed;
127119 }
128120
129-double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
130-{
131- /*
132- * Culculates a geodesic length between two points
133- * using geod_*.c
134- */
135- phi1 = dmstor(p1, &p1);
136- lam1 = dmstor(l1, &l1);
137- phi2 = dmstor(p2, &p2);
138- lam2 = dmstor(l2, &l2);
139- geod_inv();
140- return geod_S;
121+double getDistanceCore(char *p1, char *l1, char *p2, char *l2) {
122+ /*
123+ * Culculates a geodesic length between two points
124+ * using geod_*.c
125+ */
126+ phi1 = dmstor(p1, &p1);
127+ lam1 = dmstor(l1, &l1);
128+ phi2 = dmstor(p2, &p2);
129+ lam2 = dmstor(l2, &l2);
130+ geod_inv();
131+ return geod_S;
141132 }
142133
143-double getDistance(double _x, double _y, double x, double y)
144-{
145- /*
146- * Culculates a geodesic length between two points
147- */
148- double length;
149- char p1[17], l1[17], p2[17], l2[17];
150- sprintf(p1, "%f", _x);
151- sprintf(l1, "%f", _y);
152- sprintf(p2, "%f", x);
153- sprintf(l2, "%f", y);
154- length = getDistanceCore(p1, l1, p2, l2);
155- return length;
134+double getDistance(double _x, double _y, double x, double y) {
135+ /*
136+ * Culculates a geodesic length between two points
137+ */
138+ double length;
139+ char p1[17], l1[17], p2[17], l2[17];
140+ sprintf(p1, "%f", _x);
141+ sprintf(l1, "%f", _y);
142+ sprintf(p2, "%f", x);
143+ sprintf(l2, "%f", y);
144+ length = getDistanceCore(p1, l1, p2, l2);
145+ return length;
156146 }
157147
158-void closeShpFiles(shphandles * shps)
159-{
160- /*
161- * Closes all SHP files if they opened
162- */
163- if (shps->wpt)
164- SHPClose(shps->wpt);
165- if (shps->trk)
166- SHPClose(shps->trk);
167- if (shps->trk_edg)
168- SHPClose(shps->trk_edg);
169- if (shps->trk_pnt)
170- SHPClose(shps->trk_pnt);
171- if (shps->rte)
172- SHPClose(shps->rte);
173- if (shps->rte_edg)
174- SHPClose(shps->rte_edg);
175- if (shps->rte_pnt)
176- SHPClose(shps->rte_pnt);
148+void closeShpFiles(shphandles * shps) {
149+ /*
150+ * Closes all SHP files if they opened
151+ */
152+ if (shps->wpt)
153+ SHPClose(shps->wpt);
154+ if (shps->trk)
155+ SHPClose(shps->trk);
156+ if (shps->trk_edg)
157+ SHPClose(shps->trk_edg);
158+ if (shps->trk_pnt)
159+ SHPClose(shps->trk_pnt);
160+ if (shps->rte)
161+ SHPClose(shps->rte);
162+ if (shps->rte_edg)
163+ SHPClose(shps->rte_edg);
164+ if (shps->rte_pnt)
165+ SHPClose(shps->rte_pnt);
177166 }
178167
179-void closeDbfFiles(dbfhandles * dbfs)
180-{
181- /*
182- * Closes all DBF files if they opened
183- */
184- if (dbfs->wpt)
185- DBFClose(dbfs->wpt);
186- if (dbfs->trk)
187- DBFClose(dbfs->trk);
188- if (dbfs->trk_edg)
189- DBFClose(dbfs->trk_edg);
190- if (dbfs->trk_pnt)
191- DBFClose(dbfs->trk_pnt);
192- if (dbfs->rte)
193- DBFClose(dbfs->rte);
194- if (dbfs->rte_edg)
195- DBFClose(dbfs->rte_edg);
196- if (dbfs->rte_pnt)
197- DBFClose(dbfs->rte_pnt);
168+void closeDbfFiles(dbfhandles * dbfs) {
169+ /*
170+ * Closes all DBF files if they opened
171+ */
172+ if (dbfs->wpt)
173+ DBFClose(dbfs->wpt);
174+ if (dbfs->trk)
175+ DBFClose(dbfs->trk);
176+ if (dbfs->trk_edg)
177+ DBFClose(dbfs->trk_edg);
178+ if (dbfs->trk_pnt)
179+ DBFClose(dbfs->trk_pnt);
180+ if (dbfs->rte)
181+ DBFClose(dbfs->rte);
182+ if (dbfs->rte_edg)
183+ DBFClose(dbfs->rte_edg);
184+ if (dbfs->rte_pnt)
185+ DBFClose(dbfs->rte_pnt);
198186 }
199187
--- trunk/gpx2shp/src/gpx2shp.h (revision 5)
+++ trunk/gpx2shp/src/gpx2shp.h (revision 6)
@@ -29,9 +29,9 @@
2929 * make xml parent and child list
3030 */
3131 typedef struct parent {
32- char *name; /** element name */
33- struct parent *parentptr;
34- /** parent pointer */
32+ char *name; /** element name */
33+ struct parent *parentptr;
34+/** parent pointer */
3535 } parent;
3636
3737 /**
@@ -38,33 +38,33 @@
3838 * set attribute columns on/off
3939 */
4040 typedef struct g2scolumns {
41-/**
42- * each member corresponds to attribute column of attribute table
43- */
44- int name;
45- int cmt;
46- int desc;
47- int src;
48- int link;
49- int type;
50- int time;
51- int number;
52- int ele;
53- int magvar;
54- int geoidheight;
55- int sym;
56- int fix;
57- int sat;
58- int hdop;
59- int vdop;
60- int pdop;
61- int ageofdgpsdata;
62- int dgpsid;
63- int length;
64- int interval;
65- int speed;
66- int points;
67- int gpxline;
41+ /**
42+ * each member corresponds to attribute column of attribute table
43+ */
44+ int name;
45+ int cmt;
46+ int desc;
47+ int src;
48+ int link;
49+ int type;
50+ int time;
51+ int number;
52+ int ele;
53+ int magvar;
54+ int geoidheight;
55+ int sym;
56+ int fix;
57+ int sat;
58+ int hdop;
59+ int vdop;
60+ int pdop;
61+ int ageofdgpsdata;
62+ int dgpsid;
63+ int length;
64+ int interval;
65+ int speed;
66+ int points;
67+ int gpxline;
6868 } g2scolumns;
6969
7070 /**
@@ -71,23 +71,23 @@
7171 * store each path attribute values for trackpoint and route.
7272 */
7373 typedef struct pathattr {
74- char name[NAMELENGTH];
75- char cmt[COMMENTLENGTH];
76- char desc[COMMENTLENGTH];
77- char src[COMMENTLENGTH];
78- char link[FILENAMELENGTH];
79- int number;
80- char type[TYPELENGTH];
81- double length;
82- double interval;
83- double speed;
84- /*
85- double *x;
86- double *y;
87- double *z;
88- */
89- double *point;
90- int count;
74+ char name[NAMELENGTH];
75+ char cmt[COMMENTLENGTH];
76+ char desc[COMMENTLENGTH];
77+ char src[COMMENTLENGTH];
78+ char link[FILENAMELENGTH];
79+ int number;
80+ char type[TYPELENGTH];
81+ double length;
82+ double interval;
83+ double speed;
84+ /*
85+ double *x;
86+ double *y;
87+ double *z;
88+ */
89+ double *point;
90+ int count;
9191 } pathattr;
9292
9393 /**
@@ -94,39 +94,39 @@
9494 * store each point attribute values.
9595 */
9696 typedef struct g2sattr {
97-/**
98- * the structure cames from GPX1.1 format
99- */
100- double lon;
101- double lat;
102- double minlon;
103- double minlat;
104- double maxlon;
105- double maxlat;
106- char name[NAMELENGTH];
107- char cmt[COMMENTLENGTH];
108- char desc[COMMENTLENGTH];
109- char src[COMMENTLENGTH];
110- char link[FILENAMELENGTH];
111- char type[TYPELENGTH];
112- char time[TIMELENGTH];
113- int number;
114- double ele;
115- double magvar;
116- double geoidheight;
117- char sym[NAMELENGTH];
118- char fix[NAMELENGTH];
119- int sat;
120- double hdop;
121- double vdop;
122- double pdop;
123- double ageofdgpsdata;
124- int dgpsid;
125- char author[NAMELENGTH];
126- char keywords[NAMELENGTH];
127- char copyright[NAMELENGTH];
128- int year;
129- char license[NAMELENGTH];
97+ /**
98+ * the structure cames from GPX1.1 format
99+ */
100+ double lon;
101+ double lat;
102+ double minlon;
103+ double minlat;
104+ double maxlon;
105+ double maxlat;
106+ char name[NAMELENGTH];
107+ char cmt[COMMENTLENGTH];
108+ char desc[COMMENTLENGTH];
109+ char src[COMMENTLENGTH];
110+ char link[FILENAMELENGTH];
111+ char type[TYPELENGTH];
112+ char time[TIMELENGTH];
113+ int number;
114+ double ele;
115+ double magvar;
116+ double geoidheight;
117+ char sym[NAMELENGTH];
118+ char fix[NAMELENGTH];
119+ int sat;
120+ double hdop;
121+ double vdop;
122+ double pdop;
123+ double ageofdgpsdata;
124+ int dgpsid;
125+ char author[NAMELENGTH];
126+ char keywords[NAMELENGTH];
127+ char copyright[NAMELENGTH];
128+ int year;
129+ char license[NAMELENGTH];
130130 } g2sattr;
131131
132132 /**
@@ -133,28 +133,28 @@
133133 * statistics structure
134134 */
135135 typedef struct g2sstats {
136- int trkpoints; /** track point total count */
137- int trkcount; /** track path total count */
138- double trklength; /** track total length */
139- int rtepoints; /** route point total count */
140- int rtecount; /** route path totol count */
141- double rtelength; /** route total length */
142- int wptpoints; /** way point total count */
143- int trkunconverted; /** unconverted track path count */
144- int rteunconverted; /** unconverted route path count */
136+ int trkpoints; /** track point total count */
137+ int trkcount; /** track path total count */
138+ double trklength; /** track total length */
139+ int rtepoints; /** route point total count */
140+ int rtecount; /** route path totol count */
141+ double rtelength; /** route total length */
142+ int wptpoints; /** way point total count */
143+ int trkunconverted; /** unconverted track path count */
144+ int rteunconverted; /** unconverted route path count */
145145 } g2sstats;
146146
147147 /**
148148 * cluster of all dbfhandles
149- */
149+ */
150150 typedef struct dbfhandles {
151- DBFHandle trk; /** for track */
152- DBFHandle wpt; /** for waypoint */
153- DBFHandle rte; /** for route */
154- DBFHandle trk_edg; /** for track each edge */
155- DBFHandle trk_pnt; /** for track each point */
156- DBFHandle rte_edg; /** for route each edge */
157- DBFHandle rte_pnt; /** for route each point */
151+ DBFHandle trk; /** for track */
152+ DBFHandle wpt; /** for waypoint */
153+ DBFHandle rte; /** for route */
154+ DBFHandle trk_edg; /** for track each edge */
155+ DBFHandle trk_pnt; /** for track each point */
156+ DBFHandle rte_edg; /** for route each edge */
157+ DBFHandle rte_pnt; /** for route each point */
158158 } dbfhandles;
159159
160160 /**
@@ -161,13 +161,13 @@
161161 * cluster of all shphandles
162162 */
163163 typedef struct shphandles {
164- SHPHandle trk; /** for track */
165- SHPHandle wpt; /** for waypoint */
166- SHPHandle rte; /** for route */
167- SHPHandle trk_edg; /** for track each edge */
168- SHPHandle trk_pnt; /** for track each point */
169- SHPHandle rte_edg; /** for route each edge */
170- SHPHandle rte_pnt; /** for route each point */
164+ SHPHandle trk; /** for track */
165+ SHPHandle wpt; /** for waypoint */
166+ SHPHandle rte; /** for route */
167+ SHPHandle trk_edg; /** for track each edge */
168+ SHPHandle trk_pnt; /** for track each point */
169+ SHPHandle rte_edg; /** for route each edge */
170+ SHPHandle rte_pnt; /** for route each point */
171171 } shphandles;
172172
173173 /**
@@ -174,32 +174,32 @@
174174 * propaties structure for gpx2shp
175175 */
176176 typedef struct g2sprop {
177- int parseWpt; /** convert waypoint data or not */
178- int parseTrk; /** convert track data or not */
179- int parseRte; /** convert route data or not */
180- int is3d; /** using 3D mode */
181- int isEdge; /** convert path data as each separated path */
182- int isPoint; /** convert path data as point */
183- int isFast; /** fast mode that skips path check */
184- int needsStats; /** shows statistics at last */
185- int minpoints; /** minimum points to convert as a path */
186- int minlength; /** minimum length to convert as a path */
187- int mintime; /** minimum time to convert as a path */
188- int verbose; /** verbose mode on/off */
189- char *sourcefile; /** source .gpx file */
190- char *output; /** output file base name */
191- char *ellipsoid; /** ellipsoid type to calculate length */
192- char *lengthUnit; /** length unit for attributes*/
193- double length2meter;/** meter value of lenght unit */
194- char *timeUnit; /** time unit for attributes */
195- double time2sec; /** value to convert time unit to second */
196- char *speedLengthUnit;
197- /** lenght unit to calculate speed*/
198- double speed2meter; /** meter value of speedLengthUnit */
199- char *speedTimeUnit;/** time unit to calculate speed */
200- int speed2sec; /** value to convert speedTimeUnit to seconde */
201- g2sstats *stats; /** convert statistics */
202- g2scolumns *cols; /** attribute table column switch */
177+ int parseWpt; /** convert waypoint data or not */
178+ int parseTrk; /** convert track data or not */
179+ int parseRte; /** convert route data or not */
180+ int is3d; /** using 3D mode */
181+ int isEdge; /** convert path data as each separated path */
182+ int isPoint; /** convert path data as point */
183+ int isFast; /** fast mode that skips path check */
184+ int needsStats; /** shows statistics at last */
185+ int minpoints; /** minimum points to convert as a path */
186+ int minlength; /** minimum length to convert as a path */
187+ int mintime; /** minimum time to convert as a path */
188+ int verbose; /** verbose mode on/off */
189+ char *sourcefile; /** source .gpx file */
190+ char *output; /** output file base name */
191+ char *ellipsoid; /** ellipsoid type to calculate length */
192+ char *lengthUnit; /** length unit for attributes*/
193+ double length2meter;/** meter value of lenght unit */
194+ char *timeUnit; /** time unit for attributes */
195+ double time2sec; /** value to convert time unit to second */
196+ char *speedLengthUnit;
197+ /** lenght unit to calculate speed*/
198+ double speed2meter; /** meter value of speedLengthUnit */
199+ char *speedTimeUnit;/** time unit to calculate speed */
200+ int speed2sec; /** value to convert speedTimeUnit to seconde */
201+ g2sstats *stats; /** convert statistics */
202+ g2scolumns *cols; /** attribute table column switch */
203203 } g2sprop;
204204
205205 /**
@@ -206,19 +206,19 @@
206206 * userdata structure between expat methods
207207 */
208208 typedef struct parsedata {
209- int depth; /** xml path depth */
210- char *databuf; /** character buffer in tags */
211- char *bufptr; /** pointer to databuf to add '\0' to databuf */
212- int failed; /** xml parse failed flag */
213- int failedid; /** xml parse failed id */
214- XML_Parser parser; /** xml parser itself*/
215- parent *parent; /** pointer to parent node */
216- parent *current; /** pointer to current node */
217- shphandles *shps; /** .shp file cluster that is used in this program */
218- dbfhandles *dbfs; /** .dbf file cluster that is used in this program */
219- g2sattr *attr; /** each point attributes */
220- pathattr *pattr; /** each path attributes */
221- g2sprop *prop; /** propaties for this program */
209+ int depth; /** xml path depth */
210+ char *databuf; /** character buffer in tags */
211+ char *bufptr; /** pointer to databuf to add '\0' to databuf */
212+ int failed; /** xml parse failed flag */
213+ int failedid; /** xml parse failed id */
214+ XML_Parser parser; /** xml parser itself*/
215+ parent *parent; /** pointer to parent node */
216+ parent *current; /** pointer to current node */
217+ shphandles *shps; /** .shp file cluster that is used in this program */
218+ dbfhandles *dbfs; /** .dbf file cluster that is used in this program */
219+ g2sattr *attr; /** each point attributes */
220+ pathattr *pattr; /** each path attributes */
221+ g2sprop *prop; /** propaties for this program */
222222 } parsedata;
223223
224224 /* utils.c */
@@ -253,7 +253,7 @@
253253
254254 /* elementControl.c */
255255 void startElementControl(parsedata * pdata, const char *element,
256- const char **attr);
256+ const char **attr);
257257 void endElementControl(parsedata * pdata, const char *element);
258258
259259 /* setwpt.c */
--- trunk/gpx2shp/src/setmeta.c (revision 5)
+++ trunk/gpx2shp/src/setmeta.c (revision 6)
@@ -3,52 +3,51 @@
33 /**
44 * store gpx metadata into text file
55 */
6-void setMetadata(parsedata * pdata)
7-{
8- g2sprop *prop = pdata->prop;
9- g2sattr *attr = pdata->attr;
10- FILE *metafile;
11- char *output = malloc(sizeof(char) * (strlen(prop->output) + 10));
12- strcpy(output, prop->output);
13- strcat(output, "_meta.txt");
14- metafile = fopen(output, "w");
15- if (metafile == NULL) {
16- fprintf(stderr, "Cannot create file: %s\n", output);
17- exit(ERR_CREATEFILE);
18- }
19- if (attr->name) {
20- fprintf(metafile, "name\t%s\n", attr->name);
21- }
22- if (attr->desc) {
23- fprintf(metafile, "description\t%s\n", attr->desc);
24- }
25- if (attr->author) {
26- fprintf(metafile, "author\t%s\n", attr->author);
27- }
28- if (attr->copyright) {
29- fprintf(metafile, "copyright\t%s\n", attr->copyright);
30- }
31- if (attr->link) {
32- fprintf(metafile, "link\t%s\n", attr->link);
33- }
34- if (attr->time) {
35- fprintf(metafile, "time\t%s\n", attr->time);
36- }
37- if (attr->keywords) {
38- fprintf(metafile, "keywords\t%s\n", attr->keywords);
39- }
40- if (attr->minlat) {
41- fprintf(metafile, "min latitude\t%f\n", attr->minlat);
42- }
43- if (attr->minlon) {
44- fprintf(metafile, "min longitude\t%f\n", attr->minlon);
45- }
46- if (attr->maxlat) {
47- fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
48- }
49- if (attr->maxlon) {
50- fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
51- }
52- fclose(metafile);
53- free(output);
6+void setMetadata(parsedata * pdata) {
7+ g2sprop *prop = pdata->prop;
8+ g2sattr *attr = pdata->attr;
9+ FILE *metafile;
10+ char *output = malloc(sizeof(char) * (strlen(prop->output) + 10));
11+ strcpy(output, prop->output);
12+ strcat(output, "_meta.txt");
13+ metafile = fopen(output, "w");
14+ if (metafile == NULL ) {
15+ fprintf(stderr, "Cannot create file: %s\n", output);
16+ exit(ERR_CREATEFILE);
17+ }
18+ if (attr->name) {
19+ fprintf(metafile, "name\t%s\n", attr->name);
20+ }
21+ if (attr->desc) {
22+ fprintf(metafile, "description\t%s\n", attr->desc);
23+ }
24+ if (attr->author) {
25+ fprintf(metafile, "author\t%s\n", attr->author);
26+ }
27+ if (attr->copyright) {
28+ fprintf(metafile, "copyright\t%s\n", attr->copyright);
29+ }
30+ if (attr->link) {
31+ fprintf(metafile, "link\t%s\n", attr->link);
32+ }
33+ if (attr->time) {
34+ fprintf(metafile, "time\t%s\n", attr->time);
35+ }
36+ if (attr->keywords) {
37+ fprintf(metafile, "keywords\t%s\n", attr->keywords);
38+ }
39+ if (attr->minlat) {
40+ fprintf(metafile, "min latitude\t%f\n", attr->minlat);
41+ }
42+ if (attr->minlon) {
43+ fprintf(metafile, "min longitude\t%f\n", attr->minlon);
44+ }
45+ if (attr->maxlat) {
46+ fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
47+ }
48+ if (attr->maxlon) {
49+ fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
50+ }
51+ fclose(metafile);
52+ free(output);
5453 }
--- trunk/gpx2shp/src/setpath.c (revision 5)
+++ trunk/gpx2shp/src/setpath.c (revision 6)
@@ -1,14 +1,14 @@
11 #include "gpx2shp.h"
22
3-void writePathAttribute(DBFHandle hDBF, parsedata * pdata,
4- pathattr * pattr, int iShape);
3+void writePathAttribute(DBFHandle hDBF, parsedata * pdata, pathattr * pattr,
4+ int iShape);
55 void addPathField(DBFHandle hDBF, parsedata * pdata);
66 void initPathAttr(pathattr * pattr, g2sattr * attr);
77 void initPath(parsedata * pdata);
88 void initPathAsPoint(parsedata * pdata);
99 void initPathAsEdge(parsedata * pdata);
10-void setEdge(parsedata * pdata, double _x, double _y, double _z,
11- double length, double interval, double speed);
10+void setEdge(parsedata * pdata, double _x, double _y, double _z, double length,
11+ double interval, double speed);
1212 void setPathInterval(parsedata * pdata);
1313 void setPathData(pathattr * pattr, g2sattr * attr);
1414 void countUnconverted(parsedata * pdata);
@@ -19,461 +19,438 @@
1919 /**
2020 * set each shape attribute data
2121 */
22-void writePathAttribute(DBFHandle hDBF, parsedata * pdata,
23- pathattr * pattr, int iShape)
24-{
25- g2sprop *prop = pdata->prop;
26- g2scolumns *cols = prop->cols;
27- int c = 1;
28- if (!DBFWriteIntegerAttribute(hDBF, iShape, 0, iShape)) {
29- failToWriteAttr(iShape, 0);
30- }
31- if (cols->name) {
32- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->name))
33- failToWriteAttr(iShape, c);
34- c++;
35- }
36- if (cols->cmt) {
37- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->cmt))
38- failToWriteAttr(iShape, c);
39- c++;
40- }
41- if (cols->desc) {
42- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->desc))
43- failToWriteAttr(iShape, c);
44- c++;
45- }
46- if (cols->src) {
47- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->src))
48- failToWriteAttr(iShape, c);
49- c++;
50- }
51- if (cols->link) {
52- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->link))
53- failToWriteAttr(iShape, c);
54- c++;
55- }
56- if (cols->type) {
57- if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->type))
58- failToWriteAttr(iShape, c);
59- c++;
60- }
61- if (cols->length) {
62- if (!DBFWriteDoubleAttribute
63- (hDBF, iShape, c, (pattr->length / prop->length2meter)))
64- failToWriteAttr(iShape, c);
65- c++;
66- }
67- if (cols->interval) {
68- if (!DBFWriteDoubleAttribute
69- (hDBF, iShape, c, (pattr->interval / prop->time2sec))) {
70- printf("%f, %f, %f\n", pattr->interval, prop->time2sec,
71- (pattr->interval / prop->time2sec));
72- failToWriteAttr(iShape, c);
22+void writePathAttribute(DBFHandle hDBF, parsedata * pdata, pathattr * pattr,
23+ int iShape) {
24+ g2sprop *prop = pdata->prop;
25+ g2scolumns *cols = prop->cols;
26+ int c = 1;
27+ if (!DBFWriteIntegerAttribute(hDBF, iShape, 0, iShape)) {
28+ failToWriteAttr(iShape, 0);
7329 }
74- c++;
75- }
76- if (cols->speed) {
77- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, pattr->speed))
78- failToWriteAttr(iShape, c);
79- c++;
80- }
81- if (cols->points) {
82- if (!DBFWriteIntegerAttribute(hDBF, iShape, c, pattr->count))
83- failToWriteAttr(iShape, c);
84- c++;
85- }
86- if (cols->gpxline) {
87- if (!DBFWriteIntegerAttribute
88- (hDBF, iShape, c, XML_GetCurrentLineNumber(pdata->parser)))
89- failToWriteAttr(iShape, c);
90- }
30+ if (cols->name) {
31+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->name))
32+ failToWriteAttr(iShape, c);
33+ c++;
34+ }
35+ if (cols->cmt) {
36+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->cmt))
37+ failToWriteAttr(iShape, c);
38+ c++;
39+ }
40+ if (cols->desc) {
41+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->desc))
42+ failToWriteAttr(iShape, c);
43+ c++;
44+ }
45+ if (cols->src) {
46+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->src))
47+ failToWriteAttr(iShape, c);
48+ c++;
49+ }
50+ if (cols->link) {
51+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->link))
52+ failToWriteAttr(iShape, c);
53+ c++;
54+ }
55+ if (cols->type) {
56+ if (!DBFWriteStringAttribute(hDBF, iShape, c, pattr->type))
57+ failToWriteAttr(iShape, c);
58+ c++;
59+ }
60+ if (cols->length) {
61+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c,
62+ (pattr->length / prop->length2meter)))
63+ failToWriteAttr(iShape, c);
64+ c++;
65+ }
66+ if (cols->interval) {
67+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c,
68+ (pattr->interval / prop->time2sec))) {
69+ printf("%f, %f, %f\n", pattr->interval, prop->time2sec,
70+ (pattr->interval / prop->time2sec));
71+ failToWriteAttr(iShape, c);
72+ }
73+ c++;
74+ }
75+ if (cols->speed) {
76+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, pattr->speed))
77+ failToWriteAttr(iShape, c);
78+ c++;
79+ }
80+ if (cols->points) {
81+ if (!DBFWriteIntegerAttribute(hDBF, iShape, c, pattr->count))
82+ failToWriteAttr(iShape, c);
83+ c++;
84+ }
85+ if (cols->gpxline) {
86+ if (!DBFWriteIntegerAttribute(hDBF, iShape, c,
87+ XML_GetCurrentLineNumber(pdata->parser)))
88+ failToWriteAttr(iShape, c);
89+ }
9190 }
9291
9392 /**
9493 * add a shape attribute table columns
9594 */
96-void addPathField(DBFHandle hDBF, parsedata * pdata)
97-{
98- char columnName[16];
99- g2sprop *prop = pdata->prop;
100- g2scolumns *cols = prop->cols;
101- DBFAddField(hDBF, "shapeID", FTInteger, 8, 0);
102- if (cols->name)
103- DBFAddField(hDBF, "name", FTString, NAMELENGTH, 0);
104- if (cols->cmt)
105- DBFAddField(hDBF, "cmt", FTString, COMMENTLENGTH, 0);
106- if (cols->desc)
107- DBFAddField(hDBF, "desc", FTString, COMMENTLENGTH, 0);
108- if (cols->src)
109- DBFAddField(hDBF, "src", FTString, COMMENTLENGTH, 0);
110- if (cols->link)
111- DBFAddField(hDBF, "link", FTString, FILENAMELENGTH, 0);
112- if (cols->type)
113- DBFAddField(hDBF, "type", FTString, NAMELENGTH, 0);
114- if (cols->length) {
115- sprintf(columnName, "l(%s)", prop->lengthUnit);
116- DBFAddField(hDBF, columnName, FTDouble, 17, 4);
117- }
118- if (cols->time) {
119- sprintf(columnName, "t(%s)", prop->timeUnit);
120- DBFAddField(hDBF, columnName, FTDouble, 12, 2);
121- }
122- if (cols->speed) {
123- sprintf(columnName, "s(%s/%s)", prop->speedLengthUnit,
124- prop->speedTimeUnit);
125- DBFAddField(hDBF, columnName, FTDouble, 12, 2);
126- }
127- if (cols->points) {
128- DBFAddField(hDBF, "points", FTInteger, 12, 0);
129- }
130- if (cols->gpxline) {
131- DBFAddField(hDBF, "gpxline#", FTInteger, 12, 0);
132- }
95+void addPathField(DBFHandle hDBF, parsedata * pdata) {
96+ char columnName[16];
97+ g2sprop *prop = pdata->prop;
98+ g2scolumns *cols = prop->cols;
99+ DBFAddField(hDBF, "shapeID", FTInteger, 8, 0);
100+ if (cols->name)
101+ DBFAddField(hDBF, "name", FTString, NAMELENGTH, 0);
102+ if (cols->cmt)
103+ DBFAddField(hDBF, "cmt", FTString, COMMENTLENGTH, 0);
104+ if (cols->desc)
105+ DBFAddField(hDBF, "desc", FTString, COMMENTLENGTH, 0);
106+ if (cols->src)
107+ DBFAddField(hDBF, "src", FTString, COMMENTLENGTH, 0);
108+ if (cols->link)
109+ DBFAddField(hDBF, "link", FTString, FILENAMELENGTH, 0);
110+ if (cols->type)
111+ DBFAddField(hDBF, "type", FTString, NAMELENGTH, 0);
112+ if (cols->length) {
113+ sprintf(columnName, "l(%s)", prop->lengthUnit);
114+ DBFAddField(hDBF, columnName, FTDouble, 17, 4);
115+ }
116+ if (cols->time) {
117+ sprintf(columnName, "t(%s)", prop->timeUnit);
118+ DBFAddField(hDBF, columnName, FTDouble, 12, 2);
119+ }
120+ if (cols->speed) {
121+ sprintf(columnName, "s(%s/%s)", prop->speedLengthUnit,
122+ prop->speedTimeUnit);
123+ DBFAddField(hDBF, columnName, FTDouble, 12, 2);
124+ }
125+ if (cols->points) {
126+ DBFAddField(hDBF, "points", FTInteger, 12, 0);
127+ }
128+ if (cols->gpxline) {
129+ DBFAddField(hDBF, "gpxline#", FTInteger, 12, 0);
130+ }
133131 }
134132
135133 /**
136134 * initialize a path attribute
137135 */
138-void initPathAttr(pathattr * pattr, g2sattr * attr)
139-{
140- strcpy(pattr->name, attr->name);
141- strcpy(pattr->cmt, attr->cmt);
142- strcpy(pattr->desc, attr->desc);
143- strcpy(pattr->src, attr->src);
144- strcpy(pattr->link, attr->link);
145- pattr->number = attr->number;
146- strcpy(pattr->type, attr->type);
147- pattr->length = 0;
148- pattr->interval = 0;
149- pattr->speed = 0;
150- pattr->count = 0;
151- pattr->point = NULL;
136+void initPathAttr(pathattr * pattr, g2sattr * attr) {
137+ strcpy(pattr->name, attr->name);
138+ strcpy(pattr->cmt, attr->cmt);
139+ strcpy(pattr->desc, attr->desc);
140+ strcpy(pattr->src, attr->src);
141+ strcpy(pattr->link, attr->link);
142+ pattr->number = attr->number;
143+ strcpy(pattr->type, attr->type);
144+ pattr->length = 0;
145+ pattr->interval = 0;
146+ pattr->speed = 0;
147+ pattr->count = 0;
148+ pattr->point = NULL;
152149 }
153150
154151 /**
155152 * creates *_[trk|rte].shp and *_[trk|rte].dbf file
156153 */
157-void initPath(parsedata * pdata)
158-{
159- SHPHandle shp;
160- DBFHandle dbf;
161- char *output =
162- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 5));
163- strcpy(output, pdata->prop->output);
164- if (!strcmp(pdata->current->name, "trk")) {
165- strcat(output, "_trk");
166- } else {
167- strcat(output, "_rte");
168- }
169- if (pdata->prop->is3d) {
170- shp = SHPCreate(output, SHPT_ARCZ);
171- } else {
172- shp = SHPCreate(output, SHPT_ARC);
173- }
174- dbf = DBFCreate(output);
175- if (!strcmp(pdata->current->name, "trk")) {
176- pdata->shps->trk = shp;
177- pdata->dbfs->trk = dbf;
178- } else {
179- pdata->shps->rte = shp;
180- pdata->dbfs->rte = dbf;
181- }
182- addPathField(dbf, pdata);
183- free(output);
154+void initPath(parsedata * pdata) {
155+ SHPHandle shp;
156+ DBFHandle dbf;
157+ char *output = (char *) malloc(
158+ sizeof(char) * (strlen(pdata->prop->output) + 5));
159+ strcpy(output, pdata->prop->output);
160+ if (!strcmp(pdata->current->name, "trk")) {
161+ strcat(output, "_trk");
162+ } else {
163+ strcat(output, "_rte");
164+ }
165+ if (pdata->prop->is3d) {
166+ shp = SHPCreate(output, SHPT_ARCZ);
167+ } else {
168+ shp = SHPCreate(output, SHPT_ARC);
169+ }
170+ dbf = DBFCreate(output);
171+ if (!strcmp(pdata->current->name, "trk")) {
172+ pdata->shps->trk = shp;
173+ pdata->dbfs->trk = dbf;
174+ } else {
175+ pdata->shps->rte = shp;
176+ pdata->dbfs->rte = dbf;
177+ }
178+ addPathField(dbf, pdata);
179+ free(output);
184180 }
185181
186182 /**
187183 * creates *_[trk|rte]_pnt.shp and *_[trk|rte]_pnt.dbf file
188184 */
189-void initPathAsPoint(parsedata * pdata)
190-{
191- SHPHandle shp;
192- DBFHandle dbf;
193- char *output =
194- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
195- strcpy(output, pdata->prop->output);
196- if (!strcmp(pdata->current->name, "trkpt")) {
197- strcat(output, "_trk_pnt");
198- } else {
199- strcat(output, "_rte_pnt");
200- }
201- if (pdata->prop->is3d) {
202- shp = SHPCreate(output, SHPT_POINTZ);
203- } else {
204- shp = SHPCreate(output, SHPT_POINT);
205- }
206- dbf = DBFCreate(output);
207- addWptField(dbf, pdata->prop->cols);
208- if (!strcmp(pdata->current->name, "trkpt")) {
209- pdata->shps->trk_pnt = shp;
210- pdata->dbfs->trk_pnt = dbf;
211- } else {
212- pdata->shps->rte_pnt = shp;
213- pdata->dbfs->rte_pnt = dbf;
214- }
215- free(output);
185+void initPathAsPoint(parsedata * pdata) {
186+ SHPHandle shp;
187+ DBFHandle dbf;
188+ char *output = (char *) malloc(
189+ sizeof(char) * (strlen(pdata->prop->output) + 9));
190+ strcpy(output, pdata->prop->output);
191+ if (!strcmp(pdata->current->name, "trkpt")) {
192+ strcat(output, "_trk_pnt");
193+ } else {
194+ strcat(output, "_rte_pnt");
195+ }
196+ if (pdata->prop->is3d) {
197+ shp = SHPCreate(output, SHPT_POINTZ);
198+ } else {
199+ shp = SHPCreate(output, SHPT_POINT);
200+ }
201+ dbf = DBFCreate(output);
202+ addWptField(dbf, pdata->prop->cols);
203+ if (!strcmp(pdata->current->name, "trkpt")) {
204+ pdata->shps->trk_pnt = shp;
205+ pdata->dbfs->trk_pnt = dbf;
206+ } else {
207+ pdata->shps->rte_pnt = shp;
208+ pdata->dbfs->rte_pnt = dbf;
209+ }
210+ free(output);
216211 }
217212
218213 /**
219214 * creates *_[trk|rte]_edg.shp and *_[trk|rte]_edg.dbf file
220215 */
221-void initPathAsEdge(parsedata * pdata)
222-{
223- SHPHandle shp;
224- DBFHandle dbf;
225- char *output =
226- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
227- strcpy(output, pdata->prop->output);
228- if (!strcmp(pdata->current->name, "trkpt")) {
229- strcat(output, "_trk_edg");
230- } else {
231- strcat(output, "_rte_edg");
232- }
233- if (pdata->prop->is3d) {
234- shp = SHPCreate(output, SHPT_ARCZ);
235- } else {
236- shp = SHPCreate(output, SHPT_ARC);
237- }
238- dbf = DBFCreate(output);
239- addPathField(dbf, pdata);
240- if (!strcmp(pdata->current->name, "trkpt")) {
241- pdata->shps->trk_edg = shp;
242- pdata->dbfs->trk_edg = dbf;
243- } else {
244- pdata->shps->rte_edg = shp;
245- pdata->dbfs->rte_edg = dbf;
246- }
247- free(output);
216+void initPathAsEdge(parsedata * pdata) {
217+ SHPHandle shp;
218+ DBFHandle dbf;
219+ char *output = (char *) malloc(
220+ sizeof(char) * (strlen(pdata->prop->output) + 9));
221+ strcpy(output, pdata->prop->output);
222+ if (!strcmp(pdata->current->name, "trkpt")) {
223+ strcat(output, "_trk_edg");
224+ } else {
225+ strcat(output, "_rte_edg");
226+ }
227+ if (pdata->prop->is3d) {
228+ shp = SHPCreate(output, SHPT_ARCZ);
229+ } else {
230+ shp = SHPCreate(output, SHPT_ARC);
231+ }
232+ dbf = DBFCreate(output);
233+ addPathField(dbf, pdata);
234+ if (!strcmp(pdata->current->name, "trkpt")) {
235+ pdata->shps->trk_edg = shp;
236+ pdata->dbfs->trk_edg = dbf;
237+ } else {
238+ pdata->shps->rte_edg = shp;
239+ pdata->dbfs->rte_edg = dbf;
240+ }
241+ free(output);
248242 }
249243
250244 /**
251245 * set edge data and store it
252246 */
253-void setEdge(parsedata * pdata, double _x, double _y, double _z,
254- double length, double interval, double speed)
255-{
256- SHPHandle shp;
257- DBFHandle dbf;
258- SHPObject *shpobj;
259- pathattr *pattr = pdata->pattr;
260- static int iShape = 0;
261- static int isFirstTrkAsEdge = 1;
262- static int isFirstRteAsEdge = 1;
263- double x[2], y[2], z[2];
264- double _length, _interval, _speed;
265- if (!strcmp(pdata->current->name, "trkpt")) {
266- if (isFirstTrkAsEdge) {
267- initPathAsEdge(pdata);
268- isFirstTrkAsEdge = 0;
247+void setEdge(parsedata * pdata, double _x, double _y, double _z, double length,
248+ double interval, double speed) {
249+ SHPHandle shp;
250+ DBFHandle dbf;
251+ SHPObject *shpobj;
252+ pathattr *pattr = pdata->pattr;
253+ static int iShape = 0;
254+ static int isFirstTrkAsEdge = 1;
255+ static int isFirstRteAsEdge = 1;
256+ double x[2], y[2], z[2];
257+ double _length, _interval, _speed;
258+ if (!strcmp(pdata->current->name, "trkpt")) {
259+ if (isFirstTrkAsEdge) {
260+ initPathAsEdge(pdata);
261+ isFirstTrkAsEdge = 0;
262+ }
263+ shp = pdata->shps->trk_edg;
264+ dbf = pdata->dbfs->trk_edg;
265+ } else {
266+ if (isFirstRteAsEdge) {
267+ initPathAsEdge(pdata);
268+ isFirstRteAsEdge = 0;
269+ }
270+ shp = pdata->shps->rte_edg;
271+ dbf = pdata->dbfs->rte_edg;
269272 }
270- shp = pdata->shps->trk_edg;
271- dbf = pdata->dbfs->trk_edg;
272- } else {
273- if (isFirstRteAsEdge) {
274- initPathAsEdge(pdata);
275- isFirstRteAsEdge = 0;
273+ _length = pattr->length;
274+ _interval = pattr->interval;
275+ _speed = pattr->speed;
276+ pattr->length = length;
277+ pattr->interval = interval;
278+ pattr->speed = speed;
279+ x[0] = _x;
280+ y[0] = _y;
281+ z[0] = _z;
282+ x[1] = pdata->attr->lon;
283+ y[1] = pdata->attr->lat;
284+ z[1] = pdata->attr->ele;
285+ if (pdata->prop->is3d) {
286+ shpobj = SHPCreateObject(SHPT_ARCZ, iShape, 0, 0, 0, 2, x, y, z, NULL );
287+ } else {
288+ shpobj = SHPCreateObject(SHPT_ARC, iShape, 0, 0, 0, 2, x, y, NULL,
289+ NULL );
276290 }
277- shp = pdata->shps->rte_edg;
278- dbf = pdata->dbfs->rte_edg;
279- }
280- _length = pattr->length;
281- _interval = pattr->interval;
282- _speed = pattr->speed;
283- pattr->length = length;
284- pattr->interval = interval;
285- pattr->speed = speed;
286- x[0] = _x;
287- y[0] = _y;
288- z[0] = _z;
289- x[1] = pdata->attr->lon;
290- y[1] = pdata->attr->lat;
291- z[1] = pdata->attr->ele;
292- if (pdata->prop->is3d) {
293- shpobj =
294- SHPCreateObject(SHPT_ARCZ, iShape, 0, 0, 0, 2, x, y, z, NULL);
295- } else {
296- shpobj =
297- SHPCreateObject(SHPT_ARC, iShape, 0, 0, 0, 2, x,
298- y, NULL, NULL);
299- }
300- iShape = SHPWriteObject(shp, -1, shpobj);
301- SHPDestroyObject(shpobj);
302- writePathAttribute(dbf, pdata, pattr, iShape);
303- pattr->length = _length;
304- pattr->interval = _interval;
305- pattr->speed = _speed;
291+ iShape = SHPWriteObject(shp, -1, shpobj);
292+ SHPDestroyObject(shpobj);
293+ writePathAttribute(dbf, pdata, pattr, iShape);
294+ pattr->length = _length;
295+ pattr->interval = _interval;
296+ pattr->speed = _speed;
306297 }
307298
308299 /**
309300 * sets interval data between two track points
310301 */
311-void setPathInterval(parsedata * pdata)
312-{
313- pathattr *pattr = pdata->pattr;
314- g2sattr *attr = pdata->attr;
315- g2sprop *prop = pdata->prop;
316- static char _t[TIMELENGTH];
317- double intvl = 0;
318- static double _x, _y, _z;
319- double leng = 0;
320- double spd;
321- if (pattr->count == 1) {
322- strcpy(_t, attr->time);
323- } else {
324- /* time interval */
325- intvl = getTimeInterval(_t, attr->time);
326- pattr->interval = pattr->interval + intvl;
327- strcpy(_t, attr->time);
328- /* length interval */
329- leng = getDistance(_x, _y, attr->lon, attr->lat);
330- pattr->length = pattr->length + leng;
331- /* interval speed */
332- spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
333- /* sets edge data */
334- if (prop->isEdge) {
335- setEdge(pdata, _x, _y, _z, leng, intvl, spd);
302+void setPathInterval(parsedata * pdata) {
303+ pathattr *pattr = pdata->pattr;
304+ g2sattr *attr = pdata->attr;
305+ g2sprop *prop = pdata->prop;
306+ static char _t[TIMELENGTH];
307+ double intvl = 0;
308+ static double _x, _y, _z;
309+ double leng = 0;
310+ double spd;
311+ if (pattr->count == 1) {
312+ strcpy(_t, attr->time);
313+ } else {
314+ /* time interval */
315+ intvl = getTimeInterval(_t, attr->time);
316+ pattr->interval = pattr->interval + intvl;
317+ strcpy(_t, attr->time);
318+ /* length interval */
319+ leng = getDistance(_x, _y, attr->lon, attr->lat);
320+ pattr->length = pattr->length + leng;
321+ /* interval speed */
322+ spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
323+ /* sets edge data */
324+ if (prop->isEdge) {
325+ setEdge(pdata, _x, _y, _z, leng, intvl, spd);
326+ }
336327 }
337- }
338- _x = attr->lon;
339- _y = attr->lat;
340- _z = attr->ele;
328+ _x = attr->lon;
329+ _y = attr->lat;
330+ _z = attr->ele;
341331 }
342332
343333 /**
344334 * sets each track point data in array.
345335 */
346-void setPathData(pathattr * pattr, g2sattr * attr)
347-{
348- const int reallocsize = 100;
349- if (pattr->count == 0) {
350- pattr->point = malloc(sizeof(double) * 3 * reallocsize);
351- }
352- if ((pattr->count % reallocsize) == 0) {
353- pattr->point = realloc(pattr->point,
354- sizeof(double) * 3 * (pattr->count +
355- reallocsize));
356- }
357- pattr->point[pattr->count * 3] = attr->lon;
358- pattr->point[pattr->count * 3 + 1] = attr->lat;
359- pattr->point[pattr->count * 3 + 2] = attr->ele;
360- pattr->count++;
336+void setPathData(pathattr * pattr, g2sattr * attr) {
337+ const int reallocsize = 100;
338+ if (pattr->count == 0) {
339+ pattr->point = malloc(sizeof(double) * 3 * reallocsize);
340+ }
341+ if ((pattr->count % reallocsize) == 0) {
342+ pattr->point = realloc(pattr->point,
343+ sizeof(double) * 3 * (pattr->count + reallocsize));
344+ }
345+ pattr->point[pattr->count * 3] = attr->lon;
346+ pattr->point[pattr->count * 3 + 1] = attr->lat;
347+ pattr->point[pattr->count * 3 + 2] = attr->ele;
348+ pattr->count++;
361349 }
362350
363351 /**
364352 * counts paths that wasn't converted
365353 */
366-void countUnconverted(parsedata * pdata)
367-{
368- g2sstats *stats = pdata->prop->stats;
369- if (!strcmp(pdata->current->name, "trkseg"))
370- stats->trkunconverted++;
371- else
372- stats->rteunconverted++;
354+void countUnconverted(parsedata * pdata) {
355+ g2sstats *stats = pdata->prop->stats;
356+ if (!strcmp(pdata->current->name, "trkseg"))
357+ stats->trkunconverted++;
358+ else
359+ stats->rteunconverted++;
373360 }
374361
375362 /**
376363 * counts paths
377364 */
378-void countPath(parsedata * pdata)
379-{
380- g2sstats *stats = pdata->prop->stats;
381- pathattr *pattr = pdata->pattr;
382- if (!strcmp(pdata->current->name, "trkseg")) {
383- stats->trkcount++;
384- stats->trklength += pattr->length;
385- stats->trkpoints += pattr->count;
386- } else {
387- stats->rtecount++;
388- stats->rtelength += pattr->length;
389- stats->rtepoints += pattr->count;
390- }
365+void countPath(parsedata * pdata) {
366+ g2sstats *stats = pdata->prop->stats;
367+ pathattr *pattr = pdata->pattr;
368+ if (!strcmp(pdata->current->name, "trkseg")) {
369+ stats->trkcount++;
370+ stats->trklength += pattr->length;
371+ stats->trkpoints += pattr->count;
372+ } else {
373+ stats->rtecount++;
374+ stats->rtelength += pattr->length;
375+ stats->rtepoints += pattr->count;
376+ }
391377 }
392378
393-int checkPath(parsedata * pdata)
394-{
395- pathattr *pattr = pdata->pattr;
396- g2sprop *prop = pdata->prop;
397- /* check point count. */
398- if (pattr->count < prop->minpoints) {
399- fprintf
400- (stderr,
401- "gpx2shp:%s:%i track was not converted because of less then %d points. \n",
402- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
403- prop->minpoints);
404- countUnconverted(pdata);
405- return 0;
406- /* check path length */
407- } else if (pattr->length < prop->minlength * prop->length2meter) {
408- fprintf
409- (stderr,
410- "gpx2shp:%s:%i track was not converted because it is shorter than %dm.\n",
411- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
412- prop->minlength);
413- countUnconverted(pdata);
414- return 0;
415- /* check path time */
416- } else if (pattr->interval < prop->mintime * prop->time2sec) {
417- fprintf
418- (stderr,
419- "gpx2shp:%s:%i track was not converted because it is shorter than %d sed.\n",
420- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
421- prop->mintime);
422- countUnconverted(pdata);
423- return 0;
424- /* check path speed */
425- } else if (0 && pattr->speed == .0) {
426- fprintf
427- (stderr,
428- "gpx2shp:%s:%i track was not converted because no move recorded.\n",
429- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
430- countUnconverted(pdata);
431- return 0;
432- }
433- return 1;
379+int checkPath(parsedata * pdata) {
380+ pathattr *pattr = pdata->pattr;
381+ g2sprop *prop = pdata->prop;
382+ /* check point count. */
383+ if (pattr->count < prop->minpoints) {
384+ fprintf(stderr,
385+ "gpx2shp:%s:%i track was not converted because of less then %d points. \n",
386+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
387+ prop->minpoints);
388+ countUnconverted(pdata);
389+ return 0;
390+ /* check path length */
391+ } else if (pattr->length < prop->minlength * prop->length2meter) {
392+ fprintf(stderr,
393+ "gpx2shp:%s:%i track was not converted because it is shorter than %dm.\n",
394+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
395+ prop->minlength);
396+ countUnconverted(pdata);
397+ return 0;
398+ /* check path time */
399+ } else if (pattr->interval < prop->mintime * prop->time2sec) {
400+ fprintf(stderr,
401+ "gpx2shp:%s:%i track was not converted because it is shorter than %d sed.\n",
402+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
403+ prop->mintime);
404+ countUnconverted(pdata);
405+ return 0;
406+ /* check path speed */
407+ } else if (0 && pattr->speed == .0) {
408+ fprintf(stderr,
409+ "gpx2shp:%s:%i track was not converted because no move recorded.\n",
410+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
411+ countUnconverted(pdata);
412+ return 0;
413+ }
414+ return 1;
434415 }
435416
436417 /**
437418 * saves path data into files.
438419 */
439-void setPath(SHPHandle hSHP, DBFHandle hDBF, parsedata * pdata)
440-{
441- SHPObject *shpobj;
442- static int iShape = 0;
443- pathattr *pattr = pdata->pattr;
444- g2sprop *prop = pdata->prop;
445- int isOk = 0;
446- pattr->speed =
447- getSpeed(pattr->length, pattr->interval, prop->speed2meter,
448- prop->speed2sec);
449- if (prop->isFast) {
450- isOk = 1;
451- } else {
452- isOk = checkPath(pdata);
453- }
454- if (isOk) {
455- double x[pattr->count];
456- double y[pattr->count];
457- double z[pattr->count];
458- int i;
459- for (i = 0; i < pattr->count; i++) {
460- x[i] = pattr->point[i * 3];
461- y[i] = pattr->point[i * 3 + 1];
462- z[i] = pattr->point[i * 3 + 2];
463- }
464- if (pdata->prop->is3d) {
465- shpobj =
466- SHPCreateObject(SHPT_ARCZ, iShape, 0, 0, 0, pattr->count,
467- x, y, z, NULL);
420+void setPath(SHPHandle hSHP, DBFHandle hDBF, parsedata * pdata) {
421+ SHPObject *shpobj;
422+ static int iShape = 0;
423+ pathattr *pattr = pdata->pattr;
424+ g2sprop *prop = pdata->prop;
425+ int isOk = 0;
426+ pattr->speed = getSpeed(pattr->length, pattr->interval, prop->speed2meter,
427+ prop->speed2sec);
428+ if (prop->isFast) {
429+ isOk = 1;
468430 } else {
469- shpobj =
470- SHPCreateObject(SHPT_ARC, iShape, 0, 0, 0,
471- pattr->count, x, y, NULL, NULL);
431+ isOk = checkPath(pdata);
472432 }
473- iShape = SHPWriteObject(hSHP, -1, shpobj);
474- SHPDestroyObject(shpobj);
475- countPath(pdata);
476- writePathAttribute(hDBF, pdata, pattr, iShape);
477- }
478- free(pattr->point);
433+ if (isOk) {
434+ double x[pattr->count];
435+ double y[pattr->count];
436+ double z[pattr->count];
437+ int i;
438+ for (i = 0; i < pattr->count; i++) {
439+ x[i] = pattr->point[i * 3];
440+ y[i] = pattr->point[i * 3 + 1];
441+ z[i] = pattr->point[i * 3 + 2];
442+ }
443+ if (pdata->prop->is3d) {
444+ shpobj = SHPCreateObject(SHPT_ARCZ, iShape, 0, 0, 0, pattr->count,
445+ x, y, z, NULL );
446+ } else {
447+ shpobj = SHPCreateObject(SHPT_ARC, iShape, 0, 0, 0, pattr->count, x,
448+ y, NULL, NULL );
449+ }
450+ iShape = SHPWriteObject(hSHP, -1, shpobj);
451+ SHPDestroyObject(shpobj);
452+ countPath(pdata);
453+ writePathAttribute(hDBF, pdata, pattr, iShape);
454+ }
455+ free(pattr->point);
479456 }
--- trunk/gpx2shp/src/geod_for.c (revision 5)
+++ trunk/gpx2shp/src/geod_for.c (revision 6)
@@ -1,6 +1,5 @@
11 #ifndef lint
2-static const char SCCSID[] =
3- "@(#)geod_for.c 4.6 95/09/23 GIE REL";
2+static const char SCCSID[] = "@(#)geod_for.c 4.6 95/09/23 GIE REL";
43 #endif
54 # include "projects.h"
65 # include "geodesic.h"
@@ -7,102 +6,100 @@
76 # define MERI_TOL 1e-9
87 static double th1, costh1, sinth1, sina12, cosa12, M, N, c1, c2, D, P, s1;
98 static int merid, signS;
10-void geod_pre(void)
11-{
12- al12 = adjlon(al12); /* reduce to +- 0-PI */
13- signS = fabs(al12) > HALFPI ? 1 : 0;
14- th1 = ellipse ? atan(onef * tan(phi1)) : phi1;
15- costh1 = cos(th1);
16- sinth1 = sin(th1);
17- if ((merid = fabs(sina12 = sin(al12)) < MERI_TOL)) {
18- sina12 = 0.;
19- cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
20- M = 0.;
21- } else {
22- cosa12 = cos(al12);
23- M = costh1 * sina12;
24- }
25- N = costh1 * cosa12;
26- if (ellipse) {
27- if (merid) {
28- c1 = 0.;
29- c2 = f4;
30- D = 1. - c2;
31- D *= D;
32- P = c2 / D;
9+void geod_pre(void) {
10+ al12 = adjlon(al12); /* reduce to +- 0-PI */
11+ signS = fabs(al12) > HALFPI ? 1 : 0;
12+ th1 = ellipse ? atan(onef * tan(phi1)) : phi1;
13+ costh1 = cos(th1);
14+ sinth1 = sin(th1);
15+ if ((merid = fabs(sina12 = sin(al12)) < MERI_TOL)) {
16+ sina12 = 0.;
17+ cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
18+ M = 0.;
3319 } else {
34- c1 = geod_f * M;
35- c2 = f4 * (1. - M * M);
36- D = (1. - c2) * (1. - c2 - c1 * M);
37- P = (1. + .5 * c1 * M) * c2 / D;
20+ cosa12 = cos(al12);
21+ M = costh1 * sina12;
3822 }
39- }
40- if (merid)
41- s1 = HALFPI - th1;
42- else {
43- s1 = (fabs(M) >= 1.) ? 0. : acos(M);
44- s1 = sinth1 / sin(s1);
45- s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
46- }
23+ N = costh1 * cosa12;
24+ if (ellipse) {
25+ if (merid) {
26+ c1 = 0.;
27+ c2 = f4;
28+ D = 1. - c2;
29+ D *= D;
30+ P = c2 / D;
31+ } else {
32+ c1 = geod_f * M;
33+ c2 = f4 * (1. - M * M);
34+ D = (1. - c2) * (1. - c2 - c1 * M);
35+ P = (1. + .5 * c1 * M) * c2 / D;
36+ }
37+ }
38+ if (merid)
39+ s1 = HALFPI - th1;
40+ else {
41+ s1 = (fabs(M) >= 1.) ? 0. : acos(M);
42+ s1 = sinth1 / sin(s1);
43+ s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
44+ }
4745 }
48-void geod_for(void)
49-{
50- double d, sind, u, V, X, ds, cosds, sinds, ss = 0, de;
46+void geod_for(void) {
47+ double d, sind, u, V, X, ds, cosds, sinds, ss = 0, de;
5148
52- if (ellipse) {
53- d = geod_S / (D * geod_a);
49+ if (ellipse) {
50+ d = geod_S / (D * geod_a);
51+ if (signS)
52+ d = -d;
53+ u = 2. * (s1 - d);
54+ V = cos(u + d);
55+ X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
56+ ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
57+ ss = s1 + s1 - ds;
58+ } else {
59+ ds = geod_S / geod_a;
60+ if (signS)
61+ ds = -ds;
62+ }
63+ cosds = cos(ds);
64+ sinds = sin(ds);
5465 if (signS)
55- d = -d;
56- u = 2. * (s1 - d);
57- V = cos(u + d);
58- X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
59- ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
60- ss = s1 + s1 - ds;
61- } else {
62- ds = geod_S / geod_a;
63- if (signS)
64- ds = -ds;
65- }
66- cosds = cos(ds);
67- sinds = sin(ds);
68- if (signS)
69- sinds = -sinds;
70- al21 = N * cosds - sinth1 * sinds;
71- if (merid) {
72- phi2 = atan(tan(HALFPI + s1 - ds) / onef);
73- if (al21 > 0.) {
74- al21 = PI;
75- if (signS)
76- de = PI;
77- else {
78- phi2 = -phi2;
79- de = 0.;
80- }
66+ sinds = -sinds;
67+ al21 = N * cosds - sinth1 * sinds;
68+ if (merid) {
69+ phi2 = atan(tan(HALFPI + s1 - ds) / onef);
70+ if (al21 > 0.) {
71+ al21 = PI;
72+ if (signS)
73+ de = PI;
74+ else {
75+ phi2 = -phi2;
76+ de = 0.;
77+ }
78+ } else {
79+ al21 = 0.;
80+ if (signS) {
81+ phi2 = -phi2;
82+ de = 0;
83+ } else
84+ de = PI;
85+ }
8186 } else {
82- al21 = 0.;
83- if (signS) {
84- phi2 = -phi2;
85- de = 0;
86- } else
87- de = PI;
87+ al21 = atan(M / al21);
88+ if (al21 > 0)
89+ al21 += PI;
90+ if (al12 < 0.)
91+ al21 -= PI;
92+ al21 = adjlon(al21);
93+ phi2 = atan(
94+ -(sinth1 * cosds + N * sinds) * sin(al21)
95+ / (ellipse ? onef * M : M));
96+ de = atan2(sinds * sina12, (costh1 * cosds - sinth1 * sinds * cosa12));
97+ if (ellipse) {
98+ if (signS)
99+ de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
100+ else
101+ de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
102+ }
88103 }
89- } else {
90- al21 = atan(M / al21);
91- if (al21 > 0)
92- al21 += PI;
93- if (al12 < 0.)
94- al21 -= PI;
95- al21 = adjlon(al21);
96- phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
97- (ellipse ? onef * M : M));
98- de = atan2(sinds * sina12,
99- (costh1 * cosds - sinth1 * sinds * cosa12));
100- if (ellipse) {
101- if (signS)
102- de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
103- else
104- de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
105- }
106- }
107- lam2 = adjlon(lam1 + de);
104+ lam2 = adjlon(lam1 + de);
108105 }
--- trunk/gpx2shp/src/main.c (revision 5)
+++ trunk/gpx2shp/src/main.c (revision 6)
@@ -9,381 +9,355 @@
99 /**
1010 * Shows a version
1111 */
12-void version(void)
13-{
14- fprintf(stdout, "%s %s\n",PROG,PROG_VERSION);
15- fprintf(stdout, "\n");
16- fprintf(stdout, "by Toshihiro Hiraoka\n");
17- fprintf(stdout, " Petter Reinholdtsen\n");
12+void version(void) {
13+ fprintf(stdout, "%s %s\n", PROG, PROG_VERSION);
14+ fprintf(stdout, "\n");
15+ fprintf(stdout, "by Toshihiro Hiraoka\n");
16+ fprintf(stdout, " Petter Reinholdtsen\n");
1817 }
1918
2019 /**
2120 * Shows a usage message
2221 */
23-void usage(char **argv)
24-{
25- fprintf(stdout, "Usage: %s gpxfile [options] [-o output basename]\n",
26- argv[0]);
27- fprintf(stdout,
28- "-o, --output Sets output basename. The default is (source file\n");
29- fprintf(stdout, " name) - (extention name)\n");
30- fprintf
31- (stdout,
32- "-w, --waypoints Converts only waypoints data from a gpx file.\n");
33- fprintf(stdout,
34- "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
35- fprintf(stdout,
36- "-r, --routes Converts only routes data from a gpx file.\n");
37- fprintf(stdout,
38- "-a, --all Converts all types of data from a gpx file.(default)\n");
39- fprintf(stdout,
40- "-e, --as-edge Makes a separated output by each edges.\n");
41- fprintf(stdout,
42- "-p, --as-point Makes a separated output by each points.\n");
43- fprintf(stdout,
44- "-s, --stats Shows simple statistics of the outputs.\n");
45- fprintf(stdout,
46- "-b, --basic-columns Stores only basic data as attribures to \n");
47- fprintf(stdout,
48- " reduce memory and storage usage.\n");
49- fprintf(stdout,
50- " (ele, name, cmt, type, time, fix, sym and number).\n");
51- fprintf(stdout,
52- "-L, --no-length Removes length column from a waypoint or trackpoint\n");
53- fprintf(stdout, " attribute table.\n");
54- fprintf
55- (stdout,
56- "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
57- fprintf(stdout, " attribute table.\n");
58- fprintf
59- (stdout,
60- "-T, --no-time Removes time column from an attribute table.\n");
61- fprintf(stdout,
62- "-g, --gpxline Adds line number of GPX file as attribures.\n");
63- fprintf
64- (stdout,
65- "-f, --fast Make it faster without any checks.\n");
66- fprintf(stdout,
67- "-3, --3d Converts data using 3d format. (It's not compatible\n");
68- fprintf(stdout, " for Arcview 3.x.)\n");
69- fprintf(stdout,
70- " --min-points Sets path minimum points to convert for noise reduction.\n");
71- fprintf(stdout, " Default is 2.\n");
72- fprintf(stdout,
73- " --min-length Sets path minimum length to convert for noise reduction.\n");
74- fprintf(stdout, " Default is 0.\n");
75- fprintf(stdout,
76- " --min-time Sets path minimum time period to convert for noise\n");
77- fprintf(stdout, " reduction.\n");
78- fprintf(stdout, " Default is 0.\n");
79- fprintf(stdout,
80- " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
81- fprintf(stdout, " The default is m.\n");
82- fprintf(stdout,
83- " You can see the unit list from \"geod -lu\" command.\n");
84- fprintf
85- (stdout,
86- " --time-unit Sets time unit. The default is sec.\n");
87- fprintf(stdout,
88- " You can set from day, hour, min and sec.\n");
89- fprintf(stdout,
90- " --speed-length-unit Sets length unit for speed.\n");
91- fprintf(stdout, " The default is km.\n");
92- fprintf(stdout,
93- " You can see the unit list from \"geod -lu\" command.\n");
94- fprintf(stdout,
95- " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
96- fprintf(stdout,
97- " You can set from day, hour, min and sec.\n");
98- fprintf(stdout,
99- " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
100- fprintf(stdout, " UGS84.\n");
101- fprintf
102- (stdout,
103- " You can see the unit list from \"geod -le\" command.\n");
104- fprintf(stdout, "-v, --verbose Gives many messages.\n");
105- fprintf(stdout, " --version Shows version.\n");
106- fprintf(stdout, "-h, --help Shows this list.\n");
22+void usage(char **argv) {
23+ fprintf(stdout, "Usage: %s gpxfile [options] [-o output basename]\n",
24+ argv[0]);
25+ fprintf(stdout,
26+ "-o, --output Sets output basename. The default is (source file\n");
27+ fprintf(stdout, " name) - (extention name)\n");
28+ fprintf(stdout,
29+ "-w, --waypoints Converts only waypoints data from a gpx file.\n");
30+ fprintf(stdout,
31+ "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
32+ fprintf(stdout,
33+ "-r, --routes Converts only routes data from a gpx file.\n");
34+ fprintf(stdout,
35+ "-a, --all Converts all types of data from a gpx file.(default)\n");
36+ fprintf(stdout,
37+ "-e, --as-edge Makes a separated output by each edges.\n");
38+ fprintf(stdout,
39+ "-p, --as-point Makes a separated output by each points.\n");
40+ fprintf(stdout,
41+ "-s, --stats Shows simple statistics of the outputs.\n");
42+ fprintf(stdout,
43+ "-b, --basic-columns Stores only basic data as attribures to \n");
44+ fprintf(stdout,
45+ " reduce memory and storage usage.\n");
46+ fprintf(stdout,
47+ " (ele, name, cmt, type, time, fix, sym and number).\n");
48+ fprintf(stdout,
49+ "-L, --no-length Removes length column from a waypoint or trackpoint\n");
50+ fprintf(stdout, " attribute table.\n");
51+ fprintf(stdout,
52+ "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
53+ fprintf(stdout, " attribute table.\n");
54+ fprintf(stdout,
55+ "-T, --no-time Removes time column from an attribute table.\n");
56+ fprintf(stdout,
57+ "-g, --gpxline Adds line number of GPX file as attribures.\n");
58+ fprintf(stdout,
59+ "-f, --fast Make it faster without any checks.\n");
60+ fprintf(stdout,
61+ "-3, --3d Converts data using 3d format. (It's not compatible\n");
62+ fprintf(stdout, " for Arcview 3.x.)\n");
63+ fprintf(stdout,
64+ " --min-points Sets path minimum points to convert for noise reduction.\n");
65+ fprintf(stdout, " Default is 2.\n");
66+ fprintf(stdout,
67+ " --min-length Sets path minimum length to convert for noise reduction.\n");
68+ fprintf(stdout, " Default is 0.\n");
69+ fprintf(stdout,
70+ " --min-time Sets path minimum time period to convert for noise\n");
71+ fprintf(stdout, " reduction.\n");
72+ fprintf(stdout, " Default is 0.\n");
73+ fprintf(stdout,
74+ " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
75+ fprintf(stdout, " The default is m.\n");
76+ fprintf(stdout,
77+ " You can see the unit list from \"geod -lu\" command.\n");
78+ fprintf(stdout,
79+ " --time-unit Sets time unit. The default is sec.\n");
80+ fprintf(stdout,
81+ " You can set from day, hour, min and sec.\n");
82+ fprintf(stdout, " --speed-length-unit Sets length unit for speed.\n");
83+ fprintf(stdout, " The default is km.\n");
84+ fprintf(stdout,
85+ " You can see the unit list from \"geod -lu\" command.\n");
86+ fprintf(stdout,
87+ " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
88+ fprintf(stdout,
89+ " You can set from day, hour, min and sec.\n");
90+ fprintf(stdout,
91+ " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
92+ fprintf(stdout, " UGS84.\n");
93+ fprintf(stdout,
94+ " You can see the unit list from \"geod -le\" command.\n");
95+ fprintf(stdout, "-v, --verbose Gives many messages.\n");
96+ fprintf(stdout, " --version Shows version.\n");
97+ fprintf(stdout, "-h, --help Shows this list.\n");
10798 }
10899
109100 /**
110101 * Sets default values to the properties when there is no user setting.
111102 */
112-void setDefault(g2sprop * prop)
113-{
114- char *pargv[2];
115- int pargc = 2;
116- char *ellps;
117- /* if there are no options like -p,-w,-e, sets as -a */
118- if (!(prop->parseWpt | prop->parseTrk | prop->parseRte)) {
119- prop->parseWpt = 1;
120- prop->parseTrk = 1;
121- prop->parseRte = 1;
122- }
123- /* if there is no output setting, sets it as [sourcefile name] - ".gpx" */
124- if (prop->output == NULL) {
125- char *dot = strrchr(prop->sourcefile, '.');
126- prop->output =
127- (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
128- if (0 == strcmp(dot, ".gpx")) {
129- int len = dot - prop->sourcefile;
130- strncpy(prop->output, prop->sourcefile, len);
131- prop->output[len] = 0;
132- } else {
133- fprintf(stderr,
134- "The source file doesn't have .gpx extension.\n");
135- exit(ERR_ISNOTGPX);
103+void setDefault(g2sprop * prop) {
104+ char *pargv[2];
105+ int pargc = 2;
106+ char *ellps;
107+ /* if there are no options like -p,-w,-e, sets as -a */
108+ if (!(prop->parseWpt | prop->parseTrk | prop->parseRte)) {
109+ prop->parseWpt = 1;
110+ prop->parseTrk = 1;
111+ prop->parseRte = 1;
136112 }
137- }
138- /* sets ellipsoid "WGS84" */
139- if (prop->ellipsoid == NULL) {
140- prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
141- strcpy(prop->ellipsoid, "WGS84");
142- }
143- /* sets lengthUnit "m" */
144- if (prop->lengthUnit == NULL) {
145- prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
146- strcpy(prop->lengthUnit, "m");
147- }
148- /* sets timeUnit "sec" */
149- if (prop->timeUnit == NULL) {
150- prop->timeUnit = (char *) malloc(sizeof(char) * 4);
151- strcpy(prop->timeUnit, "sec");
152- }
153- /* sets speedLengthUnit "km" */
154- if (prop->speedLengthUnit == NULL) {
155- prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
156- strcpy(prop->speedLengthUnit, "km");
157- }
158- /* sets speedTimeUnit "hour" */
159- if (prop->speedTimeUnit == NULL) {
160- prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
161- strcpy(prop->speedTimeUnit, "hour");
162- }
163- /* sets ellipsoid setting to geod* programs */
164- ellps = malloc(sizeof(char) * (strlen(prop->ellipsoid) + 8));
165- strcpy(ellps, "+ellps=");
166- strcat(ellps, prop->ellipsoid);
167- pargv[0] = ellps;
168- pargv[1] = prop->lengthUnit;
169- checkEllpsUnit(prop->ellipsoid);
170- prop->length2meter = checkLengthUnit(prop->lengthUnit);
171- prop->time2sec = checkTimeUnit(prop->timeUnit);
172- prop->speed2meter = checkLengthUnit(prop->speedLengthUnit);
173- prop->speed2sec = checkTimeUnit(prop->speedTimeUnit);
174- geod_set(pargc, pargv);
175- if (prop->verbose) {
176- printf("source filename:\t%s\n", prop->sourcefile);
177- printf("output file base name:\t%s\n", prop->output);
178- }
179- free(ellps);
113+ /* if there is no output setting, sets it as [sourcefile name] - ".gpx" */
114+ if (prop->output == NULL ) {
115+ char *dot = strrchr(prop->sourcefile, '.');
116+ prop->output = (char *) malloc(
117+ sizeof(char) * strlen(prop->sourcefile) + 1);
118+ if (0 == strcmp(dot, ".gpx")) {
119+ int len = dot - prop->sourcefile;
120+ strncpy(prop->output, prop->sourcefile, len);
121+ prop->output[len] = 0;
122+ } else {
123+ fprintf(stderr, "The source file doesn't have .gpx extension.\n");
124+ exit(ERR_ISNOTGPX);
125+ }
126+ }
127+ /* sets ellipsoid "WGS84" */
128+ if (prop->ellipsoid == NULL ) {
129+ prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
130+ strcpy(prop->ellipsoid, "WGS84");
131+ }
132+ /* sets lengthUnit "m" */
133+ if (prop->lengthUnit == NULL ) {
134+ prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
135+ strcpy(prop->lengthUnit, "m");
136+ }
137+ /* sets timeUnit "sec" */
138+ if (prop->timeUnit == NULL ) {
139+ prop->timeUnit = (char *) malloc(sizeof(char) * 4);
140+ strcpy(prop->timeUnit, "sec");
141+ }
142+ /* sets speedLengthUnit "km" */
143+ if (prop->speedLengthUnit == NULL ) {
144+ prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
145+ strcpy(prop->speedLengthUnit, "km");
146+ }
147+ /* sets speedTimeUnit "hour" */
148+ if (prop->speedTimeUnit == NULL ) {
149+ prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
150+ strcpy(prop->speedTimeUnit, "hour");
151+ }
152+ /* sets ellipsoid setting to geod* programs */
153+ ellps = malloc(sizeof(char) * (strlen(prop->ellipsoid) + 8));
154+ strcpy(ellps, "+ellps=");
155+ strcat(ellps, prop->ellipsoid);
156+ pargv[0] = ellps;
157+ pargv[1] = prop->lengthUnit;
158+ checkEllpsUnit(prop->ellipsoid);
159+ prop->length2meter = checkLengthUnit(prop->lengthUnit);
160+ prop->time2sec = checkTimeUnit(prop->timeUnit);
161+ prop->speed2meter = checkLengthUnit(prop->speedLengthUnit);
162+ prop->speed2sec = checkTimeUnit(prop->speedTimeUnit);
163+ geod_set(pargc, pargv);
164+ if (prop->verbose) {
165+ printf("source filename:\t%s\n", prop->sourcefile);
166+ printf("output file base name:\t%s\n", prop->output);
167+ }
168+ free(ellps);
180169 }
181170
182171 /**
183172 * Set options from command arguments
184173 */
185-void setOptions(int argc, char **argv, g2sprop * prop)
186-{
187- int result;
188- /* option struct for getopt_long */
189- struct option const long_options[] = {
190- {"waypoints", no_argument, 0, 'w'},
191- {"trackpoints", no_argument, 0, 't'},
192- {"routes", no_argument, 0, 'r'},
193- {"output", required_argument, 0, 'o'},
194- {"as-edge", no_argument, 0, 'e'},
195- {"as-point", no_argument, 0, 'p'},
196- {"min-points", required_argument, 0, 'P'},
197- {"min-length", required_argument, 0, 'l'},
198- {"min-time", required_argument, 0, 'm'},
199- {"stats", no_argument, 0, 's'},
200- {"basic-columns", no_argument, 0, 'b'},
201- {"fast", no_argument, 0, 'f'},
202- {"length-unit", required_argument, 0, '4'},
203- {"time-unit", required_argument, 0, '8'},
204- {"length-ellipsoid", required_argument, 0, '7'},
205- {"speed-length-unit", required_argument, 0, '5'},
206- {"speed-time-unit", required_argument, 0, '6'},
207- {"no-speed", no_argument, 0, 'S'},
208- {"no-length", no_argument, 0, 'L'},
209- {"no-time", no_argument, 0, 'T'},
210- {"verbose", no_argument, 0, 'v'},
211- {"gpxline", no_argument, 0, 'g'},
212- {"all", no_argument, 0, 'a'},
213- {"version", no_argument, 0, 'V'},
214- {"help", no_argument, 0, '?'},
215- {0, no_argument, 0, '0'},
216- };
217- if (argc <= 1) {
218- fprintf(stderr, "There is no argument.\n");
219- usage(argv);
220- exit(ERR_NOARGS);
221- }
222- /* set option attributes */
223- while ((result =
224- getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg0",
225- long_options, NULL)) != -1) {
226- switch (result) {
227- case '3': /* 3d output */
228- prop->is3d = 1;
229- break;
230- case 'w': /* converts only waypoint */
231- prop->parseWpt = 1;
232- break;
233- case 't': /* converts only trackpoint */
234- prop->parseTrk = 1;
235- break;
236- case 'r': /* converts only route */
237- prop->parseRte = 1;
238- break;
239- case 'a': /* converts all */
240- prop->parseWpt = 1;
241- prop->parseTrk = 1;
242- prop->parseRte = 1;
243- break;
244- case 'o': /* sets basename of output file */
245- prop->output =
246- (char *) malloc(sizeof(char) * strlen(optarg) + 1);
247- strcpy(prop->output, optarg);
248- break;
249- case 'e': /* make output by each edges */
250- if (prop->isEdge) {
251- fprintf(stderr, "option -e cannot use with -f\n");
252- exit(ERR_OPTIONCONFRICT);
253- }
254- prop->isEdge = 1;
255- break;
256- case 'p': /* make output by each edges */
257- prop->isPoint = 1;
258- break;
259- case 'f': /* make it faster */
260- if (prop->isEdge) {
261- fprintf(stderr, "option -f cannot use with -e\n");
262- exit(ERR_OPTIONCONFRICT);
263- }
264- prop->isFast = 1;
265- prop->cols->desc = 0;
266- prop->cols->src = 0;
267- prop->cols->link = 0;
268- prop->cols->magvar = 0;
269- prop->cols->geoidheight = 0;
270- prop->cols->sat = 0;
271- prop->cols->hdop = 0;
272- prop->cols->vdop = 0;
273- prop->cols->pdop = 0;
274- prop->cols->ageofdgpsdata = 0;
275- prop->cols->dgpsid = 0;
276- prop->cols->length = 0;
277- prop->cols->interval = 0;
278- prop->cols->speed = 0;
279- break;
280- case 'P': /* sets minimun points as a path */
281- prop->minpoints = atoi(optarg);
282- break;
283- case 'l': /* sets minimun length as a path */
284- prop->minlength = atoi(optarg);
285- break;
286- case 'm': /* sets minimun time as a path */
287- prop->mintime = atoi(optarg);
288- break;
289- case 'b': /* use only some columns */
290- prop->cols->desc = 0;
291- prop->cols->src = 0;
292- prop->cols->link = 0;
293- prop->cols->magvar = 0;
294- prop->cols->geoidheight = 0;
295- prop->cols->sat = 0;
296- prop->cols->hdop = 0;
297- prop->cols->vdop = 0;
298- prop->cols->pdop = 0;
299- prop->cols->ageofdgpsdata = 0;
300- prop->cols->dgpsid = 0;
301- prop->cols->length = 0;
302- prop->cols->interval = 0;
303- prop->cols->speed = 0;
304- break;
305- case 'S': /* doesn't make speed column */
306- prop->cols->speed = 0;
307- break;
308- case '4': /* sets length unit */
309- prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
310- strcpy(prop->lengthUnit, optarg);
311- break;
312- case '5': /* sets length unit for calculating speed */
313- prop->speedLengthUnit =
314- malloc(sizeof(char) * (strlen(optarg) + 1));
315- strcpy(prop->speedLengthUnit, optarg);
316- break;
317- case '6': /* sets time unit for calculating speed */
318- prop->speedTimeUnit =
319- malloc(sizeof(char) * (strlen(optarg) + 1));
320- strcpy(prop->speedTimeUnit, optarg);
321- break;
322- case '7': /* sets ellipsoid for calculating length */
323- prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
324- strcpy(prop->ellipsoid, optarg);
325- break;
326- case '8': /* sets time unit */
327- prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
328- strcpy(prop->timeUnit, optarg);
329- break;
330- case 'L': /* doesn't make length column */
331- prop->cols->length = 0;
332- break;
333- case 'T': /* doesn't make time column */
334- prop->cols->interval = 0;
335- break;
336- case 's': /* shows source file stats */
337- prop->needsStats = 1;
338- break;
339- case 'v': /* verbose mode */
340- prop->verbose = 1;
341- break;
342- case 'V': /* shows version */
343- version();
344- exit(EXIT_SUCCESS);
345- break;
346- case 'g': /* adds gpx line number column */
347- prop->cols->gpxline = 1;
348- break;
349- case ':':
350- usage(argv);
351- exit(ERR_WRONGOPTION);
352- break;
353- case '0':
354- usage(argv);
355- exit(ERR_WRONGOPTION);
356- break;
357- default:
358- usage(argv);
359- exit(ERR_WRONGOPTION);
360- break;
174+void setOptions(int argc, char **argv, g2sprop * prop) {
175+ int result;
176+ /* option struct for getopt_long */
177+ struct option const long_options[] = { { "waypoints", no_argument, 0, 'w' },
178+ { "trackpoints", no_argument, 0, 't' }, { "routes", no_argument, 0,
179+ 'r' }, { "output", required_argument, 0, 'o' }, { "as-edge",
180+ no_argument, 0, 'e' }, { "as-point", no_argument, 0, 'p' },
181+ { "min-points", required_argument, 0, 'P' }, { "min-length",
182+ required_argument, 0, 'l' }, { "min-time",
183+ required_argument, 0, 'm' },
184+ { "stats", no_argument, 0, 's' }, { "basic-columns", no_argument, 0,
185+ 'b' }, { "fast", no_argument, 0, 'f' }, { "length-unit",
186+ required_argument, 0, '4' }, { "time-unit",
187+ required_argument, 0, '8' }, { "length-ellipsoid",
188+ required_argument, 0, '7' }, { "speed-length-unit",
189+ required_argument, 0, '5' }, { "speed-time-unit",
190+ required_argument, 0, '6' }, { "no-speed", no_argument, 0,
191+ 'S' }, { "no-length", no_argument, 0, 'L' }, { "no-time",
192+ no_argument, 0, 'T' }, { "verbose", no_argument, 0, 'v' }, {
193+ "gpxline", no_argument, 0, 'g' }, { "all", no_argument, 0,
194+ 'a' }, { "version", no_argument, 0, 'V' }, { "help",
195+ no_argument, 0, '?' }, { 0, no_argument, 0, '0' }, };
196+ if (argc <= 1) {
197+ fprintf(stderr, "There is no argument.\n");
198+ usage(argv);
199+ exit(ERR_NOARGS);
361200 }
362- }
363- /* gets a source file name */
364- if(argv[optind] == NULL) {
365- fprintf(stderr, "There is no gpxfile description.\n");
366- usage(argv);
367- exit(ERR_WRONGOPTION);
368- }
369- prop->sourcefile = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
370- /** @note needs to change here to support
371- * a several files convertion */
372- strcpy(prop->sourcefile, argv[optind]);
373- setDefault(prop);
201+ /* set option attributes */
202+ while ((result = getopt_long(argc, argv,
203+ "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg0", long_options, NULL )) != -1) {
204+ switch (result) {
205+ case '3': /* 3d output */
206+ prop->is3d = 1;
207+ break;
208+ case 'w': /* converts only waypoint */
209+ prop->parseWpt = 1;
210+ break;
211+ case 't': /* converts only trackpoint */
212+ prop->parseTrk = 1;
213+ break;
214+ case 'r': /* converts only route */
215+ prop->parseRte = 1;
216+ break;
217+ case 'a': /* converts all */
218+ prop->parseWpt = 1;
219+ prop->parseTrk = 1;
220+ prop->parseRte = 1;
221+ break;
222+ case 'o': /* sets basename of output file */
223+ prop->output = (char *) malloc(sizeof(char) * strlen(optarg) + 1);
224+ strcpy(prop->output, optarg);
225+ break;
226+ case 'e': /* make output by each edges */
227+ if (prop->isEdge) {
228+ fprintf(stderr, "option -e cannot use with -f\n");
229+ exit(ERR_OPTIONCONFRICT);
230+ }
231+ prop->isEdge = 1;
232+ break;
233+ case 'p': /* make output by each edges */
234+ prop->isPoint = 1;
235+ break;
236+ case 'f': /* make it faster */
237+ if (prop->isEdge) {
238+ fprintf(stderr, "option -f cannot use with -e\n");
239+ exit(ERR_OPTIONCONFRICT);
240+ }
241+ prop->isFast = 1;
242+ prop->cols->desc = 0;
243+ prop->cols->src = 0;
244+ prop->cols->link = 0;
245+ prop->cols->magvar = 0;
246+ prop->cols->geoidheight = 0;
247+ prop->cols->sat = 0;
248+ prop->cols->hdop = 0;
249+ prop->cols->vdop = 0;
250+ prop->cols->pdop = 0;
251+ prop->cols->ageofdgpsdata = 0;
252+ prop->cols->dgpsid = 0;
253+ prop->cols->length = 0;
254+ prop->cols->interval = 0;
255+ prop->cols->speed = 0;
256+ break;
257+ case 'P': /* sets minimun points as a path */
258+ prop->minpoints = atoi(optarg);
259+ break;
260+ case 'l': /* sets minimun length as a path */
261+ prop->minlength = atoi(optarg);
262+ break;
263+ case 'm': /* sets minimun time as a path */
264+ prop->mintime = atoi(optarg);
265+ break;
266+ case 'b': /* use only some columns */
267+ prop->cols->desc = 0;
268+ prop->cols->src = 0;
269+ prop->cols->link = 0;
270+ prop->cols->magvar = 0;
271+ prop->cols->geoidheight = 0;
272+ prop->cols->sat = 0;
273+ prop->cols->hdop = 0;
274+ prop->cols->vdop = 0;
275+ prop->cols->pdop = 0;
276+ prop->cols->ageofdgpsdata = 0;
277+ prop->cols->dgpsid = 0;
278+ prop->cols->length = 0;
279+ prop->cols->interval = 0;
280+ prop->cols->speed = 0;
281+ break;
282+ case 'S': /* doesn't make speed column */
283+ prop->cols->speed = 0;
284+ break;
285+ case '4': /* sets length unit */
286+ prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
287+ strcpy(prop->lengthUnit, optarg);
288+ break;
289+ case '5': /* sets length unit for calculating speed */
290+ prop->speedLengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
291+ strcpy(prop->speedLengthUnit, optarg);
292+ break;
293+ case '6': /* sets time unit for calculating speed */
294+ prop->speedTimeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
295+ strcpy(prop->speedTimeUnit, optarg);
296+ break;
297+ case '7': /* sets ellipsoid for calculating length */
298+ prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
299+ strcpy(prop->ellipsoid, optarg);
300+ break;
301+ case '8': /* sets time unit */
302+ prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
303+ strcpy(prop->timeUnit, optarg);
304+ break;
305+ case 'L': /* doesn't make length column */
306+ prop->cols->length = 0;
307+ break;
308+ case 'T': /* doesn't make time column */
309+ prop->cols->interval = 0;
310+ break;
311+ case 's': /* shows source file stats */
312+ prop->needsStats = 1;
313+ break;
314+ case 'v': /* verbose mode */
315+ prop->verbose = 1;
316+ break;
317+ case 'V': /* shows version */
318+ version();
319+ exit(EXIT_SUCCESS);
320+ break;
321+ case 'g': /* adds gpx line number column */
322+ prop->cols->gpxline = 1;
323+ break;
324+ case ':':
325+ usage(argv);
326+ exit(ERR_WRONGOPTION);
327+ break;
328+ case '0':
329+ usage(argv);
330+ exit(ERR_WRONGOPTION);
331+ break;
332+ default:
333+ usage(argv);
334+ exit(ERR_WRONGOPTION);
335+ break;
336+ }
337+ }
338+ /* gets a source file name */
339+ if (argv[optind] == NULL ) {
340+ fprintf(stderr, "There is no gpxfile description.\n");
341+ usage(argv);
342+ exit(ERR_WRONGOPTION);
343+ }
344+ prop->sourcefile = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
345+ /** @note needs to change here to support
346+ * a several files convertion */
347+ strcpy(prop->sourcefile, argv[optind]);
348+ setDefault(prop);
374349 }
375350
376351 /**
377352 * Main
378353 */
379-int main(int argc, char **argv)
380-{
381- g2sprop *prop;
382- prop = createProp();
383- setOptions(argc, argv, prop);
384- parseMain(prop);
385- if (prop->needsStats)
386- showStats(prop);
387- closeProp(prop);
388- return (0);
354+int main(int argc, char **argv) {
355+ g2sprop *prop;
356+ prop = createProp();
357+ setOptions(argc, argv, prop);
358+ parseMain(prop);
359+ if (prop->needsStats)
360+ showStats(prop);
361+ closeProp(prop);
362+ return (0);
389363 }
--- trunk/gpx2shp/src/setwpt.c (revision 5)
+++ trunk/gpx2shp/src/setwpt.c (revision 6)
@@ -8,179 +8,173 @@
88 /**
99 * save point attributes in *_wpt.dbf or *_pnt.dbf
1010 */
11-void writeWptAttribute(DBFHandle hDBF, parsedata * pdata, int iShape)
12-{
13- g2scolumns *cols = pdata->prop->cols;
14- g2sattr *attr = pdata->attr;
15- int c = 1;
16- if (!DBFWriteIntegerAttribute(hDBF, iShape, 0, iShape)) {
17- failToWriteAttr(iShape, 0);
18- }
19- if (cols->ele) {
20- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->ele))
21- failToWriteAttr(iShape, c);
22- c++;
23- }
24- if (cols->time) {
25- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->time))
26- failToWriteAttr(iShape, c);
27- c++;
28- }
29- if (cols->magvar) {
30- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->magvar))
31- failToWriteAttr(iShape, c);
32- c++;
33- }
34- if (cols->geoidheight) {
35- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->geoidheight))
36- failToWriteAttr(iShape, c);
37- c++;
38- }
39- if (cols->name) {
40- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->name))
41- failToWriteAttr(iShape, c);
42- c++;
43- }
44- if (cols->cmt) {
45- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->cmt))
46- failToWriteAttr(iShape, c);
47- c++;
48- }
49- if (cols->desc) {
50- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->desc))
51- failToWriteAttr(iShape, c);
52- c++;
53- }
54- if (cols->src) {
55- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->src))
56- failToWriteAttr(iShape, c);
57- c++;
58- }
59- if (cols->link) {
60- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->link))
61- failToWriteAttr(iShape, c);
62- c++;
63- }
64- if (cols->sym) {
65- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->sym))
66- failToWriteAttr(iShape, c);
67- c++;
68- }
69- if (cols->type) {
70- if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->type))
71- failToWriteAttr(iShape, c);
72- c++;
73- }
74- if (cols->sat) {
75- if (!DBFWriteIntegerAttribute(hDBF, iShape, c, attr->sat))
76- failToWriteAttr(iShape, c);
77- c++;
78- }
79- if (cols->hdop) {
80- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->hdop))
81- failToWriteAttr(iShape, c);
82- c++;
83- }
84- if (cols->vdop) {
85- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->vdop))
86- failToWriteAttr(iShape, c);
87- c++;
88- }
89- if (cols->ageofdgpsdata) {
90- if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->ageofdgpsdata))
91- failToWriteAttr(iShape, c);
92- c++;
93- }
94- if (cols->dgpsid) {
95- if (!DBFWriteIntegerAttribute(hDBF, iShape, c, attr->dgpsid))
96- failToWriteAttr(iShape, c);
97- }
11+void writeWptAttribute(DBFHandle hDBF, parsedata * pdata, int iShape) {
12+ g2scolumns *cols = pdata->prop->cols;
13+ g2sattr *attr = pdata->attr;
14+ int c = 1;
15+ if (!DBFWriteIntegerAttribute(hDBF, iShape, 0, iShape)) {
16+ failToWriteAttr(iShape, 0);
17+ }
18+ if (cols->ele) {
19+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->ele))
20+ failToWriteAttr(iShape, c);
21+ c++;
22+ }
23+ if (cols->time) {
24+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->time))
25+ failToWriteAttr(iShape, c);
26+ c++;
27+ }
28+ if (cols->magvar) {
29+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->magvar))
30+ failToWriteAttr(iShape, c);
31+ c++;
32+ }
33+ if (cols->geoidheight) {
34+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->geoidheight))
35+ failToWriteAttr(iShape, c);
36+ c++;
37+ }
38+ if (cols->name) {
39+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->name))
40+ failToWriteAttr(iShape, c);
41+ c++;
42+ }
43+ if (cols->cmt) {
44+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->cmt))
45+ failToWriteAttr(iShape, c);
46+ c++;
47+ }
48+ if (cols->desc) {
49+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->desc))
50+ failToWriteAttr(iShape, c);
51+ c++;
52+ }
53+ if (cols->src) {
54+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->src))
55+ failToWriteAttr(iShape, c);
56+ c++;
57+ }
58+ if (cols->link) {
59+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->link))
60+ failToWriteAttr(iShape, c);
61+ c++;
62+ }
63+ if (cols->sym) {
64+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->sym))
65+ failToWriteAttr(iShape, c);
66+ c++;
67+ }
68+ if (cols->type) {
69+ if (!DBFWriteStringAttribute(hDBF, iShape, c, attr->type))
70+ failToWriteAttr(iShape, c);
71+ c++;
72+ }
73+ if (cols->sat) {
74+ if (!DBFWriteIntegerAttribute(hDBF, iShape, c, attr->sat))
75+ failToWriteAttr(iShape, c);
76+ c++;
77+ }
78+ if (cols->hdop) {
79+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->hdop))
80+ failToWriteAttr(iShape, c);
81+ c++;
82+ }
83+ if (cols->vdop) {
84+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->vdop))
85+ failToWriteAttr(iShape, c);
86+ c++;
87+ }
88+ if (cols->ageofdgpsdata) {
89+ if (!DBFWriteDoubleAttribute(hDBF, iShape, c, attr->ageofdgpsdata))
90+ failToWriteAttr(iShape, c);
91+ c++;
92+ }
93+ if (cols->dgpsid) {
94+ if (!DBFWriteIntegerAttribute(hDBF, iShape, c, attr->dgpsid))
95+ failToWriteAttr(iShape, c);
96+ }
9897 }
9998
10099 /**
101100 * save point objects in *_wpt or *_pnt file
102101 */
103-void setWpt(SHPHandle hSHP, DBFHandle hDBF, parsedata * pdata)
104-{
105- int iShape = 1;
106- SHPObject *shpobj;
107- double x[1], y[1], z[1];
108- x[0] = pdata->attr->lon;
109- y[0] = pdata->attr->lat;
110- z[0] = pdata->attr->ele;
111- if (pdata->prop->is3d) {
112- shpobj =
113- SHPCreateObject(SHPT_POINTZ, iShape, 0, 0, 0, 1, x, y, z,
114- NULL);
115- } else {
116- shpobj =
117- SHPCreateObject(SHPT_POINT, iShape, 0, 0, 0, 1, x, y, NULL,
118- NULL);
119- }
120- iShape = SHPWriteObject(hSHP, -1, shpobj);
121- SHPDestroyObject(shpobj);
122- writeWptAttribute(hDBF, pdata, iShape);
123- if (!strcmp(pdata->current->name, "wpt")) {
124- pdata->prop->stats->wptpoints++;
125- }
126- return;
102+void setWpt(SHPHandle hSHP, DBFHandle hDBF, parsedata * pdata) {
103+ int iShape = 1;
104+ SHPObject *shpobj;
105+ double x[1], y[1], z[1];
106+ x[0] = pdata->attr->lon;
107+ y[0] = pdata->attr->lat;
108+ z[0] = pdata->attr->ele;
109+ if (pdata->prop->is3d) {
110+ shpobj = SHPCreateObject(SHPT_POINTZ, iShape, 0, 0, 0, 1, x, y, z,
111+ NULL );
112+ } else {
113+ shpobj = SHPCreateObject(SHPT_POINT, iShape, 0, 0, 0, 1, x, y, NULL,
114+ NULL );
115+ }
116+ iShape = SHPWriteObject(hSHP, -1, shpobj);
117+ SHPDestroyObject(shpobj);
118+ writeWptAttribute(hDBF, pdata, iShape);
119+ if (!strcmp(pdata->current->name, "wpt")) {
120+ pdata->prop->stats->wptpoints++;
121+ }
122+ return;
127123 }
128124
129125 /**
130126 * set attribute column of point data
131127 */
132-void addWptField(DBFHandle hDBF, g2scolumns * cols)
133-{
134- DBFAddField(hDBF, "shapeID", FTInteger, 8, 0);
135- if (cols->ele)
136- DBFAddField(hDBF, "ele", FTDouble, 16, 4);
137- if (cols->time)
138- DBFAddField(hDBF, "time", FTString, TIMELENGTH, 0);
139- if (cols->magvar)
140- DBFAddField(hDBF, "magvar", FTDouble, 16, 4);
141- if (cols->geoidheight)
142- DBFAddField(hDBF, "geoidheight", FTDouble, 16, 4);
143- if (cols->name)
144- DBFAddField(hDBF, "name", FTString, NAMELENGTH, 0);
145- if (cols->cmt)
146- DBFAddField(hDBF, "cmt", FTString, COMMENTLENGTH, 0);
147- if (cols->desc)
148- DBFAddField(hDBF, "desc", FTString, COMMENTLENGTH, 0);
149- if (cols->src)
150- DBFAddField(hDBF, "src", FTString, COMMENTLENGTH, 0);
151- if (cols->link)
152- DBFAddField(hDBF, "link", FTString, FILENAMELENGTH, 0);
153- if (cols->sym)
154- DBFAddField(hDBF, "sym", FTString, NAMELENGTH, 0);
155- if (cols->type)
156- DBFAddField(hDBF, "type", FTString, NAMELENGTH, 0);
157- if (cols->sat)
158- DBFAddField(hDBF, "sat", FTInteger, 8, 0);
159- if (cols->hdop)
160- DBFAddField(hDBF, "hdop", FTDouble, 16, 4);
161- if (cols->vdop)
162- DBFAddField(hDBF, "vdop", FTDouble, 16, 4);
163- if (cols->ageofdgpsdata)
164- DBFAddField(hDBF, "ageofdgpsdata", FTDouble, 16, 4);
165- if (cols->dgpsid)
166- DBFAddField(hDBF, "dgpsid", FTDouble, 16, 4);
128+void addWptField(DBFHandle hDBF, g2scolumns * cols) {
129+ DBFAddField(hDBF, "shapeID", FTInteger, 8, 0);
130+ if (cols->ele)
131+ DBFAddField(hDBF, "ele", FTDouble, 16, 4);
132+ if (cols->time)
133+ DBFAddField(hDBF, "time", FTString, TIMELENGTH, 0);
134+ if (cols->magvar)
135+ DBFAddField(hDBF, "magvar", FTDouble, 16, 4);
136+ if (cols->geoidheight)
137+ DBFAddField(hDBF, "geoidheight", FTDouble, 16, 4);
138+ if (cols->name)
139+ DBFAddField(hDBF, "name", FTString, NAMELENGTH, 0);
140+ if (cols->cmt)
141+ DBFAddField(hDBF, "cmt", FTString, COMMENTLENGTH, 0);
142+ if (cols->desc)
143+ DBFAddField(hDBF, "desc", FTString, COMMENTLENGTH, 0);
144+ if (cols->src)
145+ DBFAddField(hDBF, "src", FTString, COMMENTLENGTH, 0);
146+ if (cols->link)
147+ DBFAddField(hDBF, "link", FTString, FILENAMELENGTH, 0);
148+ if (cols->sym)
149+ DBFAddField(hDBF, "sym", FTString, NAMELENGTH, 0);
150+ if (cols->type)
151+ DBFAddField(hDBF, "type", FTString, NAMELENGTH, 0);
152+ if (cols->sat)
153+ DBFAddField(hDBF, "sat", FTInteger, 8, 0);
154+ if (cols->hdop)
155+ DBFAddField(hDBF, "hdop", FTDouble, 16, 4);
156+ if (cols->vdop)
157+ DBFAddField(hDBF, "vdop", FTDouble, 16, 4);
158+ if (cols->ageofdgpsdata)
159+ DBFAddField(hDBF, "ageofdgpsdata", FTDouble, 16, 4);
160+ if (cols->dgpsid)
161+ DBFAddField(hDBF, "dgpsid", FTDouble, 16, 4);
167162 }
168163
169164 /**
170165 * Creates *_wpt.shp and *_wpt.dbf file
171166 */
172-void initWpt(parsedata * pdata)
173-{
174- char *output_wpt =
175- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 5));
176- strcpy(output_wpt, pdata->prop->output);
177- strcat(output_wpt, "_wpt");
178- if (pdata->prop->is3d) {
179- pdata->shps->wpt = SHPCreate(output_wpt, SHPT_POINTZ);
180- } else {
181- pdata->shps->wpt = SHPCreate(output_wpt, SHPT_POINT);
182- }
183- pdata->dbfs->wpt = DBFCreate(output_wpt);
184- addWptField(pdata->dbfs->wpt, pdata->prop->cols);
185- free(output_wpt);
167+void initWpt(parsedata * pdata) {
168+ char *output_wpt = (char *) malloc(
169+ sizeof(char) * (strlen(pdata->prop->output) + 5));
170+ strcpy(output_wpt, pdata->prop->output);
171+ strcat(output_wpt, "_wpt");
172+ if (pdata->prop->is3d) {
173+ pdata->shps->wpt = SHPCreate(output_wpt, SHPT_POINTZ);
174+ } else {
175+ pdata->shps->wpt = SHPCreate(output_wpt, SHPT_POINT);
176+ }
177+ pdata->dbfs->wpt = DBFCreate(output_wpt);
178+ addWptField(pdata->dbfs->wpt, pdata->prop->cols);
179+ free(output_wpt);
186180 }
--- trunk/gpx2shp/src/geodesic.h (revision 5)
+++ trunk/gpx2shp/src/geodesic.h (revision 6)
@@ -13,12 +13,12 @@
1313 #endif
1414
1515 GEOD_EXTERN struct geodesic {
16- double A;
17- double LAM1, PHI1, ALPHA12;
18- double LAM2, PHI2, ALPHA21;
19- double DIST;
20- double ONEF, FLAT, FLAT2, FLAT4, FLAT64;
21- int ELLIPSE;
16+ double A;
17+ double LAM1, PHI1, ALPHA12;
18+ double LAM2, PHI2, ALPHA21;
19+ double DIST;
20+ double ONEF, FLAT, FLAT2, FLAT4, FLAT64;
21+ int ELLIPSE;
2222 } GEODESIC;
2323
2424 # define geod_a GEODESIC.A
@@ -37,10 +37,9 @@
3737 # define f64 GEODESIC.FLAT64
3838 # define ellipse GEODESIC.ELLIPSE
3939
40-
4140 GEOD_EXTERN int n_alpha, n_S;
4241 GEOD_EXTERN double to_meter, fr_meter, del_alpha;
43-
42+
4443 void geod_set(int, char **);
4544 void geod_for(void);
4645 void geod_pre(void);
--- trunk/gpx2shp/src/geod_set.c (revision 5)
+++ trunk/gpx2shp/src/geod_set.c (revision 6)
@@ -10,86 +10,86 @@
1010 #include "projects.h"
1111 #include "geodesic.h"
1212 #include "emess.h"
13-void geod_set(int argc, char **argv)
14-{
15- paralist *start = 0, *curr = NULL; /* added NULL */
16- double es;
17- char *name;
18- int i;
13+void geod_set(int argc, char **argv) {
14+ paralist *start = 0, *curr = NULL; /* added NULL */
15+ double es;
16+ char *name;
17+ int i;
1918
20-/*
21- * put arguments into internal linked list
22- */
23- if (argc <= 0)
24- emess(1, "no arguments in initialization list");
25- for (i = 0; i < argc; ++i)
26- if (i)
27- curr = curr->next = pj_mkparam(argv[i]);
28- else
29- start = curr = pj_mkparam(argv[i]);
30-/*
31- * set elliptical parameters
32- */
33- if (pj_ell_set(start, &geod_a, &es))
34- emess(1, "ellipse setup failure");
35-/*
36- * set units
37- */
38- if ((name = pj_param(start, "sunits").s)) { /* added parentheses */
39- char *s;
19+ /*
20+ * put arguments into internal linked list
21+ */
22+ if (argc <= 0)
23+ emess(1, "no arguments in initialization list");
24+ for (i = 0; i < argc; ++i)
25+ if (i)
26+ curr = curr->next = pj_mkparam(argv[i]);
27+ else
28+ start = curr = pj_mkparam(argv[i]);
29+ /*
30+ * set elliptical parameters
31+ */
32+ if (pj_ell_set(start, &geod_a, &es))
33+ emess(1, "ellipse setup failure");
34+ /*
35+ * set units
36+ */
37+ if ((name = pj_param(start, "sunits").s)) { /* added parentheses */
38+ char *s;
4039
41- for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
42- if (!s)
43- emess(1, "%s unknown unit conversion id", name);
44- fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
45- } else
46- to_meter = fr_meter = 1.;
47- if ((ellipse = es != 0.)) { /* added parentheses */
48- onef = sqrt(1. - es);
49- geod_f = 1 - onef;
50- f2 = geod_f / 2;
51- f4 = geod_f / 4;
52- f64 = geod_f * geod_f / 64;
53- } else {
54- onef = 1.;
55- geod_f = f2 = f4 = f64 = 0.;
56- }
57-/*
58- * check if line or arc mode
59- */
60- if (pj_param(start, "tlat_1").i) {
61- double del_S;
40+ for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i)
41+ ;
42+ if (!s)
43+ emess(1, "%s unknown unit conversion id", name);
44+ fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
45+ } else
46+ to_meter = fr_meter = 1.;
47+ if ((ellipse = es != 0.)) { /* added parentheses */
48+ onef = sqrt(1. - es);
49+ geod_f = 1 - onef;
50+ f2 = geod_f / 2;
51+ f4 = geod_f / 4;
52+ f64 = geod_f * geod_f / 64;
53+ } else {
54+ onef = 1.;
55+ geod_f = f2 = f4 = f64 = 0.;
56+ }
57+ /*
58+ * check if line or arc mode
59+ */
60+ if (pj_param(start, "tlat_1").i) {
61+ double del_S;
6262 #undef f
63- phi1 = pj_param(start, "rlat_1").f;
64- lam1 = pj_param(start, "rlon_1").f;
65- if (pj_param(start, "tlat_2").i) {
66- phi2 = pj_param(start, "rlat_2").f;
67- lam2 = pj_param(start, "rlon_2").f;
68- geod_inv();
69- geod_pre();
70- } else if ((geod_S = pj_param(start, "dS").f)) { /* added
71- * parentheses
72- */
73- al12 = pj_param(start, "rA").f;
74- geod_pre();
75- geod_for();
76- } else
77- emess(1, "incomplete geodesic/arc info");
78- if ((n_alpha = pj_param(start, "in_A").i) > 0) {
79- if (!(del_alpha = pj_param(start, "rdel_A").f))
80- emess(1, "del azimuth == 0");
81- } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) { /* added
82- * parentheses
83- */
84- n_S = geod_S / del_S + .5;
85- } else if ((n_S = pj_param(start, "in_S").i) <= 0)
86- emess(1, "no interval divisor selected");
87- }
88-/*
89- * free up linked list
90- */
91- for (; start; start = curr) {
92- curr = start->next;
93- pj_dalloc(start);
94- }
63+ phi1 = pj_param(start, "rlat_1").f;
64+ lam1 = pj_param(start, "rlon_1").f;
65+ if (pj_param(start, "tlat_2").i) {
66+ phi2 = pj_param(start, "rlat_2").f;
67+ lam2 = pj_param(start, "rlon_2").f;
68+ geod_inv();
69+ geod_pre();
70+ } else if ((geod_S = pj_param(start, "dS").f)) { /* added
71+ * parentheses
72+ */
73+ al12 = pj_param(start, "rA").f;
74+ geod_pre();
75+ geod_for();
76+ } else
77+ emess(1, "incomplete geodesic/arc info");
78+ if ((n_alpha = pj_param(start, "in_A").i) > 0) {
79+ if (!(del_alpha = pj_param(start, "rdel_A").f))
80+ emess(1, "del azimuth == 0");
81+ } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) { /* added
82+ * parentheses
83+ */
84+ n_S = geod_S / del_S + .5;
85+ } else if ((n_S = pj_param(start, "in_S").i) <= 0)
86+ emess(1, "no interval divisor selected");
87+ }
88+ /*
89+ * free up linked list
90+ */
91+ for (; start; start = curr) {
92+ curr = start->next;
93+ pj_dalloc(start);
94+ }
9595 }
--- trunk/gpx2shp/src/geod_inv.c (revision 5)
+++ trunk/gpx2shp/src/geod_inv.c (revision 6)
@@ -1,73 +1,70 @@
11 #ifndef lint
2-static const char SCCSID[] =
3- "@(#)geod_inv.c 4.5 95/09/23 GIE REL";
2+static const char SCCSID[] = "@(#)geod_inv.c 4.5 95/09/23 GIE REL";
43 #endif
54 # include "projects.h"
65 # include "geodesic.h"
76 # define DTOL 1e-12
8-void geod_inv(void)
9-{
10- double th1,
11- th2,
12- thm,
13- dthm,
14- dlamm,
15- dlam,
16- sindlamm,
17- costhm,
18- sinthm,
19- cosdthm,
20- sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
7+void geod_inv(void) {
8+ double th1, th2, thm, dthm, dlamm, dlam, sindlamm, costhm, sinthm, cosdthm,
9+ sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
2110
22- if (ellipse) {
23- th1 = atan(onef * tan(phi1));
24- th2 = atan(onef * tan(phi2));
25- } else {
26- th1 = phi1;
27- th2 = phi2;
28- }
29- thm = .5 * (th1 + th2);
30- dthm = .5 * (th2 - th1);
31- dlamm = .5 * (dlam = adjlon(lam2 - lam1));
32- if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
33- al12 = al21 = geod_S = 0.;
34- return;
35- }
36- sindlamm = sin(dlamm);
37- costhm = cos(thm);
38- sinthm = sin(thm);
39- cosdthm = cos(dthm);
40- sindthm = sin(dthm);
41- L = sindthm * sindthm + (cosdthm * cosdthm - sinthm * sinthm)
42- * sindlamm * sindlamm;
43- d = acos(cosd = 1 - L - L);
44- if (ellipse) {
45- E = cosd + cosd;
46- sind = sin(d);
47- Y = sinthm * cosdthm;
48- Y *= (Y + Y) / (1. - L);
49- T = sindthm * costhm;
50- T *= (T + T) / L;
51- X = Y + T;
52- Y -= T;
53- T = d / sind;
54- D = 4. * T * T;
55- A = D * E;
56- B = D + D;
57- geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
58- f64 * (X * (A + (T - .5 * (A - E)) * X) -
59- Y * (B + E * Y) + D * X * Y));
60- tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
61- (f2 * T + f64 * (32. * T - (20. * T - A)
62- * X - (B +
63- 4.) * Y)) *
64- tan(dlam)));
65- } else {
66- geod_S = geod_a * d;
67- tandlammp = tan(dlamm);
68- }
69- u = atan2(sindthm, (tandlammp * costhm));
70- v = atan2(cosdthm, (tandlammp * sinthm));
71- al12 = adjlon(TWOPI + v - u);
72- al21 = adjlon(TWOPI - v - u);
11+ if (ellipse) {
12+ th1 = atan(onef * tan(phi1));
13+ th2 = atan(onef * tan(phi2));
14+ } else {
15+ th1 = phi1;
16+ th2 = phi2;
17+ }
18+ thm = .5 * (th1 + th2);
19+ dthm = .5 * (th2 - th1);
20+ dlamm = .5 * (dlam = adjlon(lam2 - lam1));
21+ if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
22+ al12 = al21 = geod_S = 0.;
23+ return;
24+ }
25+ sindlamm = sin(dlamm);
26+ costhm = cos(thm);
27+ sinthm = sin(thm);
28+ cosdthm = cos(dthm);
29+ sindthm = sin(dthm);
30+ L = sindthm * sindthm
31+ + (cosdthm * cosdthm - sinthm * sinthm) * sindlamm * sindlamm;
32+ d = acos(cosd = 1 - L - L);
33+ if (ellipse) {
34+ E = cosd + cosd;
35+ sind = sin(d);
36+ Y = sinthm * cosdthm;
37+ Y *= (Y + Y) / (1. - L);
38+ T = sindthm * costhm;
39+ T *= (T + T) / L;
40+ X = Y + T;
41+ Y -= T;
42+ T = d / sind;
43+ D = 4. * T * T;
44+ A = D * E;
45+ B = D + D;
46+ geod_S = geod_a * sind
47+ * (T - f4 * (T * X - Y)
48+ + f64
49+ * (X * (A + (T - .5 * (A - E)) * X)
50+ - Y * (B + E * Y) + D * X * Y));
51+ tandlammp = tan(
52+ .5
53+ * (dlam
54+ - .25 * (Y + Y - E * (4. - X))
55+ * (f2 * T
56+ + f64
57+ * (32. * T
58+ - (20. * T - A)
59+ * X
60+ - (B + 4.) * Y))
61+ * tan(dlam)));
62+ } else {
63+ geod_S = geod_a * d;
64+ tandlammp = tan(dlamm);
65+ }
66+ u = atan2(sindthm, (tandlammp * costhm));
67+ v = atan2(cosdthm, (tandlammp * sinthm));
68+ al12 = adjlon(TWOPI + v - u);
69+ al21 = adjlon(TWOPI - v - u);
7370 }
--- trunk/gpx2shp/src/elementControl.c (revision 5)
+++ trunk/gpx2shp/src/elementControl.c (revision 6)
@@ -1,7 +1,7 @@
11 #include "gpx2shp.h"
22
33 void startElementControl(parsedata * pdata, const char *element,
4- const char **attr);
4+ const char **attr);
55 void endElementControl(parsedata * pdata, const char *element);
66
77 /*
@@ -8,218 +8,215 @@
88 * This method controls tag start event.
99 * It corrects attributes.
1010 */
11-void
12-startElementControl(parsedata * pdata, const char *element,
13- const char **attr)
14-{
15- int i;
16- static int isFirstTrk = 1;
17- static int isFirstRte = 1;
18- static int isFirstPathpt = 1;
19- for (i = 0; attr[i]; i += 2) {
20- if (!strcmp(attr[i], "lon")) {
21- pdata->attr->lon = atof(attr[i + 1]);
11+void startElementControl(parsedata * pdata, const char *element,
12+ const char **attr) {
13+ int i;
14+ static int isFirstTrk = 1;
15+ static int isFirstRte = 1;
16+ static int isFirstPathpt = 1;
17+ for (i = 0; attr[i]; i += 2) {
18+ if (!strcmp(attr[i], "lon")) {
19+ pdata->attr->lon = atof(attr[i + 1]);
20+ }
21+ if (!strcmp(attr[i], "lat")) {
22+ pdata->attr->lat = atof(attr[i + 1]);
23+ }
24+ if (!strcmp(attr[i], "minlon")) {
25+ pdata->attr->minlon = atof(attr[i + 1]);
26+ }
27+ if (!strcmp(attr[i], "minlat")) {
28+ pdata->attr->minlat = atof(attr[i + 1]);
29+ }
30+ if (!strcmp(attr[i], "maxlon")) {
31+ pdata->attr->maxlon = atof(attr[i + 1]);
32+ }
33+ if (!strcmp(attr[i], "maxlat")) {
34+ pdata->attr->maxlat = atof(attr[i + 1]);
35+ }
36+ if (!strcmp(attr[i], "author")) {
37+ strcpy(pdata->attr->author, attr[i + 1]);
38+ }
2239 }
23- if (!strcmp(attr[i], "lat")) {
24- pdata->attr->lat = atof(attr[i + 1]);
40+ if (pdata->prop->parseTrk) {
41+ if (!strcmp(element, "trk")) {
42+ if (isFirstTrk) {
43+ initPath(pdata);
44+ isFirstTrk = 0;
45+ }
46+ }
47+ if (!strcmp(element, "trkseg")) {
48+ isFirstPathpt = 1;
49+ }
50+ if (!strcmp(element, "trkpt")) {
51+ if (isFirstPathpt) {
52+ initPathAttr(pdata->pattr, pdata->attr);
53+ isFirstPathpt = 0;
54+ }
55+ }
2556 }
26- if (!strcmp(attr[i], "minlon")) {
27- pdata->attr->minlon = atof(attr[i + 1]);
57+ if (pdata->prop->parseRte) {
58+ if (!strcmp(element, "rte")) {
59+ if (isFirstRte) {
60+ initPath(pdata);
61+ isFirstRte = 0;
62+ isFirstPathpt = 1;
63+ }
64+ }
65+ if (!strcmp(element, "rtept")) {
66+ if (isFirstPathpt) {
67+ initPathAttr(pdata->pattr, pdata->attr);
68+ isFirstPathpt = 0;
69+ }
70+ }
2871 }
29- if (!strcmp(attr[i], "minlat")) {
30- pdata->attr->minlat = atof(attr[i + 1]);
72+}
73+
74+/**
75+ * This method is kicked by tag end event.
76+ * It corrects char elements when the element tag has some data,
77+ * then start to convert when tag is top level tag like <wpt>.
78+ */
79+void endElementControl(parsedata * pdata, const char *element) {
80+ static int isFirstWpt = 1;
81+ static int isFirstTrkAsPoint = 1;
82+ static int isFirstRteAsPoint = 1;
83+ /* common elements */
84+ if (!strcmp(element, "name")) {
85+ strcpy(pdata->attr->name, pdata->databuf);
3186 }
32- if (!strcmp(attr[i], "maxlon")) {
33- pdata->attr->maxlon = atof(attr[i + 1]);
87+ if (!strcmp(element, "cmt")) {
88+ strcpy(pdata->attr->cmt, pdata->databuf);
3489 }
35- if (!strcmp(attr[i], "maxlat")) {
36- pdata->attr->maxlat = atof(attr[i + 1]);
90+ if (!strcmp(element, "desc")) {
91+ strcpy(pdata->attr->desc, pdata->databuf);
3792 }
38- if (!strcmp(attr[i], "author")) {
39- strcpy(pdata->attr->author, attr[i + 1]);
93+ if (!strcmp(element, "src")) {
94+ strcpy(pdata->attr->src, pdata->databuf);
4095 }
41- }
42- if (pdata->prop->parseTrk) {
43- if (!strcmp(element, "trk")) {
44- if (isFirstTrk) {
45- initPath(pdata);
46- isFirstTrk = 0;
47- }
96+ if (!strcmp(element, "link")) {
97+ strcpy(pdata->attr->link, pdata->databuf);
4898 }
49- if (!strcmp(element, "trkseg")) {
50- isFirstPathpt = 1;
99+ if (!strcmp(element, "type")) {
100+ strcpy(pdata->attr->type, pdata->databuf);
51101 }
52- if (!strcmp(element, "trkpt")) {
53- if (isFirstPathpt) {
54- initPathAttr(pdata->pattr, pdata->attr);
55- isFirstPathpt = 0;
56- }
102+ /* waypoint and metadata elements */
103+ if (!strcmp(element, "time")) {
104+ strcpy(pdata->attr->time, pdata->databuf);
57105 }
58- }
59- if (pdata->prop->parseRte) {
60- if (!strcmp(element, "rte")) {
61- if (isFirstRte) {
62- initPath(pdata);
63- isFirstRte = 0;
64- isFirstPathpt = 1;
65- }
106+ /* route and track point elements */
107+ if (!strcmp(element, "number")) {
108+ pdata->attr->number = atoi(pdata->databuf);
66109 }
67- if (!strcmp(element, "rtept")) {
68- if (isFirstPathpt) {
69- initPathAttr(pdata->pattr, pdata->attr);
70- isFirstPathpt = 0;
71- }
110+ /* waypoint elements */
111+ if (!strcmp(element, "ele")) {
112+ pdata->attr->ele = atof(pdata->databuf);
72113 }
73- }
74-}
75-
76-/**
77- * This method is kicked by tag end event.
78- * It corrects char elements when the element tag has some data,
79- * then start to convert when tag is top level tag like <wpt>.
80- */
81-void endElementControl(parsedata * pdata, const char *element)
82-{
83- static int isFirstWpt = 1;
84- static int isFirstTrkAsPoint = 1;
85- static int isFirstRteAsPoint = 1;
86- /* common elements */
87- if (!strcmp(element, "name")) {
88- strcpy(pdata->attr->name, pdata->databuf);
89- }
90- if (!strcmp(element, "cmt")) {
91- strcpy(pdata->attr->cmt, pdata->databuf);
92- }
93- if (!strcmp(element, "desc")) {
94- strcpy(pdata->attr->desc, pdata->databuf);
95- }
96- if (!strcmp(element, "src")) {
97- strcpy(pdata->attr->src, pdata->databuf);
98- }
99- if (!strcmp(element, "link")) {
100- strcpy(pdata->attr->link, pdata->databuf);
101- }
102- if (!strcmp(element, "type")) {
103- strcpy(pdata->attr->type, pdata->databuf);
104- }
105- /* waypoint and metadata elements */
106- if (!strcmp(element, "time")) {
107- strcpy(pdata->attr->time, pdata->databuf);
108- }
109- /* route and track point elements */
110- if (!strcmp(element, "number")) {
111- pdata->attr->number = atoi(pdata->databuf);
112- }
113- /* waypoint elements */
114- if (!strcmp(element, "ele")) {
115- pdata->attr->ele = atof(pdata->databuf);
116- }
117- if (!strcmp(element, "magvar")) {
118- pdata->attr->magvar = atof(pdata->databuf);
119- }
120- if (!strcmp(element, "geoidheight")) {
121- pdata->attr->geoidheight = atof(pdata->databuf);
122- }
123- if (!strcmp(element, "sym")) {
124- strcpy(pdata->attr->sym, pdata->databuf);
125- }
126- if (!strcmp(element, "fix")) {
127- strcpy(pdata->attr->fix, pdata->databuf);
128- }
129- if (!strcmp(element, "sat")) {
130- pdata->attr->sat = atoi(pdata->databuf);
131- }
132- if (!strcmp(element, "hdop")) {
133- pdata->attr->hdop = atof(pdata->databuf);
134- }
135- if (!strcmp(element, "vdop")) {
136- pdata->attr->vdop = atof(pdata->databuf);
137- }
138- if (!strcmp(element, "pdop")) {
139- pdata->attr->pdop = atof(pdata->databuf);
140- }
141- if (!strcmp(element, "ageofdgpsdata")) {
142- pdata->attr->ageofdgpsdata = atof(pdata->databuf);
143- }
144- /* metadata elements */
145- if (!strcmp(element, "author")) {
146- strcpy(pdata->attr->author, pdata->databuf);
147- }
148- if (!strcmp(element, "keywords")) {
149- strcpy(pdata->attr->keywords, pdata->databuf);
150- }
151- if (!strcmp(element, "copyright")) {
152- strcpy(pdata->attr->copyright, pdata->databuf);
153- }
154- if (!strcmp(element, "year")) {
155- pdata->attr->year = atoi(pdata->databuf);
156- }
157- if (!strcmp(element, "license")) {
158- strcpy(pdata->attr->license, pdata->databuf);
159- }
160- if (!strcmp(element, "bounds")) {
161- /* none */
162- }
163- /* top elements */
164- /* set waypoint data */
165- if (!strcmp(element, "wpt")) {
166- if (pdata->prop->parseWpt) {
167- if (isFirstWpt) {
168- initWpt(pdata);
169- isFirstWpt = 0;
170- }
171- setWpt(pdata->shps->wpt, pdata->dbfs->wpt, pdata);
172- wipeAttr(pdata->attr);
114+ if (!strcmp(element, "magvar")) {
115+ pdata->attr->magvar = atof(pdata->databuf);
173116 }
174- }
175- /* set trackpoint data */
176- if (!strcmp(element, "trkpt")) {
177- if (pdata->prop->parseTrk) {
178- setPathData(pdata->pattr, pdata->attr);
179- if (!pdata->prop->isFast)
180- setPathInterval(pdata);
117+ if (!strcmp(element, "geoidheight")) {
118+ pdata->attr->geoidheight = atof(pdata->databuf);
181119 }
182- /* set trackpoint data as point */
183- if (pdata->prop->isPoint) {
184- if (isFirstTrkAsPoint) {
185- initPathAsPoint(pdata);
186- isFirstTrkAsPoint = 0;
187- }
188- setWpt(pdata->shps->trk_pnt, pdata->dbfs->trk_pnt, pdata);
120+ if (!strcmp(element, "sym")) {
121+ strcpy(pdata->attr->sym, pdata->databuf);
189122 }
190- wipeAttr(pdata->attr);
191- }
192- /* write trackpoint */
193- if (!strcmp(element, "trkseg")) {
194- if (pdata->prop->parseTrk) {
195- setPath(pdata->shps->trk, pdata->dbfs->trk, pdata);
123+ if (!strcmp(element, "fix")) {
124+ strcpy(pdata->attr->fix, pdata->databuf);
196125 }
197- }
198- /* set route data */
199- if (!strcmp(element, "rtept")) {
200- if (pdata->prop->parseRte) {
201- setPathData(pdata->pattr, pdata->attr);
202- if (!pdata->prop->isFast)
203- setPathInterval(pdata);
126+ if (!strcmp(element, "sat")) {
127+ pdata->attr->sat = atoi(pdata->databuf);
204128 }
205- /* set route data as point */
206- if (pdata->prop->isPoint) {
207- if (isFirstRteAsPoint) {
208- initPathAsPoint(pdata);
209- isFirstRteAsPoint = 0;
210- }
211- setWpt(pdata->shps->rte_pnt, pdata->dbfs->rte_pnt, pdata);
129+ if (!strcmp(element, "hdop")) {
130+ pdata->attr->hdop = atof(pdata->databuf);
212131 }
213- wipeAttr(pdata->attr);
214- }
215- /* write route */
216- if (!strcmp(element, "rte")) {
217- if (pdata->prop->parseRte) {
218- setPath(pdata->shps->rte, pdata->dbfs->rte, pdata);
132+ if (!strcmp(element, "vdop")) {
133+ pdata->attr->vdop = atof(pdata->databuf);
219134 }
220- }
221- if (!strcmp(element, "metadata")) {
222- setMetadata(pdata);
223- wipeAttr(pdata->attr);
224- }
135+ if (!strcmp(element, "pdop")) {
136+ pdata->attr->pdop = atof(pdata->databuf);
137+ }
138+ if (!strcmp(element, "ageofdgpsdata")) {
139+ pdata->attr->ageofdgpsdata = atof(pdata->databuf);
140+ }
141+ /* metadata elements */
142+ if (!strcmp(element, "author")) {
143+ strcpy(pdata->attr->author, pdata->databuf);
144+ }
145+ if (!strcmp(element, "keywords")) {
146+ strcpy(pdata->attr->keywords, pdata->databuf);
147+ }
148+ if (!strcmp(element, "copyright")) {
149+ strcpy(pdata->attr->copyright, pdata->databuf);
150+ }
151+ if (!strcmp(element, "year")) {
152+ pdata->attr->year = atoi(pdata->databuf);
153+ }
154+ if (!strcmp(element, "license")) {
155+ strcpy(pdata->attr->license, pdata->databuf);
156+ }
157+ if (!strcmp(element, "bounds")) {
158+ /* none */
159+ }
160+ /* top elements */
161+ /* set waypoint data */
162+ if (!strcmp(element, "wpt")) {
163+ if (pdata->prop->parseWpt) {
164+ if (isFirstWpt) {
165+ initWpt(pdata);
166+ isFirstWpt = 0;
167+ }
168+ setWpt(pdata->shps->wpt, pdata->dbfs->wpt, pdata);
169+ wipeAttr(pdata->attr);
170+ }
171+ }
172+ /* set trackpoint data */
173+ if (!strcmp(element, "trkpt")) {
174+ if (pdata->prop->parseTrk) {
175+ setPathData(pdata->pattr, pdata->attr);
176+ if (!pdata->prop->isFast)
177+ setPathInterval(pdata);
178+ }
179+ /* set trackpoint data as point */
180+ if (pdata->prop->isPoint) {
181+ if (isFirstTrkAsPoint) {
182+ initPathAsPoint(pdata);
183+ isFirstTrkAsPoint = 0;
184+ }
185+ setWpt(pdata->shps->trk_pnt, pdata->dbfs->trk_pnt, pdata);
186+ }
187+ wipeAttr(pdata->attr);
188+ }
189+ /* write trackpoint */
190+ if (!strcmp(element, "trkseg")) {
191+ if (pdata->prop->parseTrk) {
192+ setPath(pdata->shps->trk, pdata->dbfs->trk, pdata);
193+ }
194+ }
195+ /* set route data */
196+ if (!strcmp(element, "rtept")) {
197+ if (pdata->prop->parseRte) {
198+ setPathData(pdata->pattr, pdata->attr);
199+ if (!pdata->prop->isFast)
200+ setPathInterval(pdata);
201+ }
202+ /* set route data as point */
203+ if (pdata->prop->isPoint) {
204+ if (isFirstRteAsPoint) {
205+ initPathAsPoint(pdata);
206+ isFirstRteAsPoint = 0;
207+ }
208+ setWpt(pdata->shps->rte_pnt, pdata->dbfs->rte_pnt, pdata);
209+ }
210+ wipeAttr(pdata->attr);
211+ }
212+ /* write route */
213+ if (!strcmp(element, "rte")) {
214+ if (pdata->prop->parseRte) {
215+ setPath(pdata->shps->rte, pdata->dbfs->rte, pdata);
216+ }
217+ }
218+ if (!strcmp(element, "metadata")) {
219+ setMetadata(pdata);
220+ wipeAttr(pdata->attr);
221+ }
225222 }
--- trunk/gpx2shp/src/misc.c (revision 5)
+++ trunk/gpx2shp/src/misc.c (revision 6)
@@ -18,326 +18,306 @@
1818 /**
1919 * message when fail to write attribute
2020 */
21-void failToWriteAttrRep(int iShape, int col, char *file, int line)
22-{
23- printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
24- line, iShape, col);
21+void failToWriteAttrRep(int iShape, int col, char *file, int line) {
22+ printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
23+ line, iShape, col);
2524 }
2625
2726 /**
2827 * shows short statistics
2928 */
30-void showStats(g2sprop * prop)
31-{
32- g2sstats *stats = prop->stats;
33- double ratio;
34- if (prop->needsStats) {
35- if (prop->parseTrk) {
36- if (stats->trkunconverted != 0) {
37- ratio =
38- (double) stats->trkunconverted / (stats->trkcount +
39- stats->
40- trkunconverted) *
41- 100;
42- } else {
43- ratio = 0;
44- }
45- printf("Track Points:\n");
46- printf("\ttrack count:\t%i\n", stats->trkcount);
47- printf("\tpoint count:\t%i\n", stats->trkpoints);
48- if (!prop->isFast) {
49- printf("\ttotal length:\t%f\n", stats->trklength);
50- printf("\tunconverted:\t%i(%5.2f%%)\n",
51- stats->trkunconverted, ratio);
52- }
29+void showStats(g2sprop * prop) {
30+ g2sstats *stats = prop->stats;
31+ double ratio;
32+ if (prop->needsStats) {
33+ if (prop->parseTrk) {
34+ if (stats->trkunconverted != 0) {
35+ ratio = (double) stats->trkunconverted
36+ / (stats->trkcount + stats->trkunconverted) * 100;
37+ } else {
38+ ratio = 0;
39+ }
40+ printf("Track Points:\n");
41+ printf("\ttrack count:\t%i\n", stats->trkcount);
42+ printf("\tpoint count:\t%i\n", stats->trkpoints);
43+ if (!prop->isFast) {
44+ printf("\ttotal length:\t%f\n", stats->trklength);
45+ printf("\tunconverted:\t%i(%5.2f%%)\n", stats->trkunconverted,
46+ ratio);
47+ }
48+ }
49+ if (prop->parseRte) {
50+ if (stats->rteunconverted != 0) {
51+ ratio = (double) stats->rteunconverted
52+ / (stats->rtecount + stats->rteunconverted) * 100;
53+ } else {
54+ ratio = 0;
55+ }
56+ printf("Routes:\n");
57+ printf("\troute count:\t%i\n", stats->rtecount);
58+ printf("\tpoint count:\t%i\n", stats->rtepoints);
59+ if (!prop->isFast) {
60+ printf("\ttotal length:\t%f\n", stats->rtelength);
61+ printf("\tunconverted:\t%i(%5.2f%%)\n", stats->rteunconverted,
62+ ratio);
63+ }
64+ }
65+ if (prop->parseWpt) {
66+ printf("Waypoints:\n");
67+ printf("\tpoint count:\t%i\n", stats->wptpoints);
68+ }
5369 }
54- if (prop->parseRte) {
55- if (stats->rteunconverted != 0) {
56- ratio =
57- (double) stats->rteunconverted / (stats->rtecount +
58- stats->
59- rteunconverted) *
60- 100;
61- } else {
62- ratio = 0;
63- }
64- printf("Routes:\n");
65- printf("\troute count:\t%i\n", stats->rtecount);
66- printf("\tpoint count:\t%i\n", stats->rtepoints);
67- if (!prop->isFast) {
68- printf("\ttotal length:\t%f\n", stats->rtelength);
69- printf("\tunconverted:\t%i(%5.2f%%)\n",
70- stats->rteunconverted, ratio);
71- }
72- }
73- if (prop->parseWpt) {
74- printf("Waypoints:\n");
75- printf("\tpoint count:\t%i\n", stats->wptpoints);
76- }
77- }
7870 }
7971
8072 /**
8173 * clears a path attribute structure
8274 */
83-void wipePathAttr(pathattr * pattr)
84-{
85- pattr->name[0] = '\0';
86- pattr->cmt[0] = '\0';
87- pattr->desc[0] = '\0';
88- pattr->src[0] = '\0';
89- pattr->link[0] = '\0';
90- pattr->number = 0;
91- pattr->type[0] = '\0';
92- pattr->length = 0;
93- pattr->interval = 0;
94- pattr->speed = 0;
95- //pattr->point = NULL;
96- pattr->count = 0;
75+void wipePathAttr(pathattr * pattr) {
76+ pattr->name[0] = '\0';
77+ pattr->cmt[0] = '\0';
78+ pattr->desc[0] = '\0';
79+ pattr->src[0] = '\0';
80+ pattr->link[0] = '\0';
81+ pattr->number = 0;
82+ pattr->type[0] = '\0';
83+ pattr->length = 0;
84+ pattr->interval = 0;
85+ pattr->speed = 0;
86+ //pattr->point = NULL;
87+ pattr->count = 0;
9788 }
9889
9990 /**
10091 * creates a new path attribute
10192 */
102-pathattr *createPathAttr(void)
103-{
104- pathattr *pattr;
105- pattr = (pathattr *) malloc(sizeof(pathattr));
106- wipePathAttr(pattr);
107- return pattr;
93+pathattr *createPathAttr(void) {
94+ pathattr *pattr;
95+ pattr = (pathattr *) malloc(sizeof(pathattr));
96+ wipePathAttr(pattr);
97+ return pattr;
10898 }
10999
110100 /**
111101 * clears a element attribute structure
112102 */
113-void wipeAttr(g2sattr * attr)
114-{
115- attr->lon = 0;
116- attr->lat = 0;
117- attr->minlon = 0;
118- attr->minlat = 0;
119- attr->maxlon = 0;
120- attr->maxlat = 0;
121- attr->name[0] = '\0';
122- attr->cmt[0] = '\0';
123- attr->desc[0] = '\0';
124- attr->src[0] = '\0';
125- attr->link[0] = '\0';
126- attr->type[0] = '\0';
127- attr->time[0] = '\0';
128- attr->number = 0;
129- attr->ele = 0;
130- attr->magvar = 0;
131- attr->geoidheight = 0;
132- attr->sym[0] = '\0';
133- attr->fix[0] = '\0';
134- attr->sat = 0;
135- attr->hdop = 0;
136- attr->vdop = 0;
137- attr->pdop = 0;
138- attr->ageofdgpsdata = 0;
139- attr->dgpsid = 0;
140- attr->author[0] = '\0';
141- attr->keywords[0] = '\0';
142- attr->copyright[0] = '\0';
143- attr->year = 0;
144- attr->license[0] = '\0';
145- attr->minlat = 0;
146- attr->minlon = 0;
147- attr->maxlat = 0;
148- attr->maxlon = 0;
103+void wipeAttr(g2sattr * attr) {
104+ attr->lon = 0;
105+ attr->lat = 0;
106+ attr->minlon = 0;
107+ attr->minlat = 0;
108+ attr->maxlon = 0;
109+ attr->maxlat = 0;
110+ attr->name[0] = '\0';
111+ attr->cmt[0] = '\0';
112+ attr->desc[0] = '\0';
113+ attr->src[0] = '\0';
114+ attr->link[0] = '\0';
115+ attr->type[0] = '\0';
116+ attr->time[0] = '\0';
117+ attr->number = 0;
118+ attr->ele = 0;
119+ attr->magvar = 0;
120+ attr->geoidheight = 0;
121+ attr->sym[0] = '\0';
122+ attr->fix[0] = '\0';
123+ attr->sat = 0;
124+ attr->hdop = 0;
125+ attr->vdop = 0;
126+ attr->pdop = 0;
127+ attr->ageofdgpsdata = 0;
128+ attr->dgpsid = 0;
129+ attr->author[0] = '\0';
130+ attr->keywords[0] = '\0';
131+ attr->copyright[0] = '\0';
132+ attr->year = 0;
133+ attr->license[0] = '\0';
134+ attr->minlat = 0;
135+ attr->minlon = 0;
136+ attr->maxlat = 0;
137+ attr->maxlon = 0;
149138 }
150139
151140 /**
152141 * sets default values to a column properties.
153142 */
154-void setColsDefault(g2scolumns * cols)
155-{
156- cols->name = 1;
157- cols->cmt = 1;
158- cols->desc = 1;
159- cols->src = 1;
160- cols->link = 1;
161- cols->type = 1;
162- cols->time = 1;
163- cols->number = 1;
164- cols->ele = 1;
165- cols->magvar = 1;
166- cols->geoidheight = 1;
167- cols->sym = 1;
168- cols->fix = 1;
169- cols->sat = 1;
170- cols->hdop = 1;
171- cols->vdop = 1;
172- cols->pdop = 1;
173- cols->ageofdgpsdata = 1;
174- cols->dgpsid = 1;
175- cols->length = 1;
176- cols->interval = 1;
177- cols->speed = 1;
178- cols->points = 1;
179- cols->gpxline = 0;
143+void setColsDefault(g2scolumns * cols) {
144+ cols->name = 1;
145+ cols->cmt = 1;
146+ cols->desc = 1;
147+ cols->src = 1;
148+ cols->link = 1;
149+ cols->type = 1;
150+ cols->time = 1;
151+ cols->number = 1;
152+ cols->ele = 1;
153+ cols->magvar = 1;
154+ cols->geoidheight = 1;
155+ cols->sym = 1;
156+ cols->fix = 1;
157+ cols->sat = 1;
158+ cols->hdop = 1;
159+ cols->vdop = 1;
160+ cols->pdop = 1;
161+ cols->ageofdgpsdata = 1;
162+ cols->dgpsid = 1;
163+ cols->length = 1;
164+ cols->interval = 1;
165+ cols->speed = 1;
166+ cols->points = 1;
167+ cols->gpxline = 0;
180168 }
181169
182170 /**
183171 * creates a column structure
184172 */
185-g2scolumns *createCols(void)
186-{
187- g2scolumns *cols;
188- cols = (g2scolumns *) malloc(sizeof(g2scolumns));
189- setColsDefault(cols);
190- return cols;
173+g2scolumns *createCols(void) {
174+ g2scolumns *cols;
175+ cols = (g2scolumns *) malloc(sizeof(g2scolumns));
176+ setColsDefault(cols);
177+ return cols;
191178 }
192179
193180 /**
194181 * creates a element attribute structure.
195182 */
196-g2sattr *createAttr(void)
197-{
198- g2sattr *attr;
199- attr = (g2sattr *) malloc(sizeof(g2sattr));
200- wipeAttr(attr);
201- return attr;
183+g2sattr *createAttr(void) {
184+ g2sattr *attr;
185+ attr = (g2sattr *) malloc(sizeof(g2sattr));
186+ wipeAttr(attr);
187+ return attr;
202188 }
203189
204190 /**
205191 * creates a properties structure for gpx2shp
206192 */
207-g2sprop *createProp(void)
208-{
209- g2sprop *prop;
210- g2sstats *stats;
211- g2scolumns *cols;
212- prop = malloc(sizeof(g2sprop));
213- stats = malloc(sizeof(g2sstats));
214- cols = createCols();
215- prop->stats = stats;
216- prop->parseWpt = 0;
217- prop->parseTrk = 0;
218- prop->parseRte = 0;
219- prop->minpoints = 2;
220- prop->minlength = 0;
221- prop->mintime = 0;
222- prop->is3d = 0;
223- prop->isEdge = 0;
224- prop->isPoint = 0;
225- prop->isFast = 0;
226- prop->needsStats = 0;
227- prop->verbose = 0;
228- prop->output = NULL;
229- prop->ellipsoid = NULL;
230- prop->lengthUnit = NULL;
231- prop->speedLengthUnit = NULL;
232- prop->speedTimeUnit = NULL;
233- prop->timeUnit = NULL;
234- prop->stats->trkcount = 0;
235- prop->stats->trkpoints = 0;
236- prop->stats->trklength = 0;
237- prop->stats->trkunconverted = 0;
238- prop->stats->rtecount = 0;
239- prop->stats->rtepoints = 0;
240- prop->stats->rtelength = 0;
241- prop->stats->rteunconverted = 0;
242- prop->stats->wptpoints = 0;
243- prop->cols = cols;
244- return prop;
193+g2sprop *createProp(void) {
194+ g2sprop *prop;
195+ g2sstats *stats;
196+ g2scolumns *cols;
197+ prop = malloc(sizeof(g2sprop));
198+ stats = malloc(sizeof(g2sstats));
199+ cols = createCols();
200+ prop->stats = stats;
201+ prop->parseWpt = 0;
202+ prop->parseTrk = 0;
203+ prop->parseRte = 0;
204+ prop->minpoints = 2;
205+ prop->minlength = 0;
206+ prop->mintime = 0;
207+ prop->is3d = 0;
208+ prop->isEdge = 0;
209+ prop->isPoint = 0;
210+ prop->isFast = 0;
211+ prop->needsStats = 0;
212+ prop->verbose = 0;
213+ prop->output = NULL;
214+ prop->ellipsoid = NULL;
215+ prop->lengthUnit = NULL;
216+ prop->speedLengthUnit = NULL;
217+ prop->speedTimeUnit = NULL;
218+ prop->timeUnit = NULL;
219+ prop->stats->trkcount = 0;
220+ prop->stats->trkpoints = 0;
221+ prop->stats->trklength = 0;
222+ prop->stats->trkunconverted = 0;
223+ prop->stats->rtecount = 0;
224+ prop->stats->rtepoints = 0;
225+ prop->stats->rtelength = 0;
226+ prop->stats->rteunconverted = 0;
227+ prop->stats->wptpoints = 0;
228+ prop->cols = cols;
229+ return prop;
245230 }
246231
247232 /**
248233 * close and free a propertires structure
249234 */
250-void closeProp(g2sprop * prop)
251-{
252- free(prop->stats);
253- free(prop->sourcefile);
254- free(prop->ellipsoid);
255- free(prop->timeUnit);
256- free(prop->speedLengthUnit);
257- free(prop->speedTimeUnit);
258- free(prop->lengthUnit);
259- free(prop->output);
260- free(prop->cols);
261- free(prop);
235+void closeProp(g2sprop * prop) {
236+ free(prop->stats);
237+ free(prop->sourcefile);
238+ free(prop->ellipsoid);
239+ free(prop->timeUnit);
240+ free(prop->speedLengthUnit);
241+ free(prop->speedTimeUnit);
242+ free(prop->lengthUnit);
243+ free(prop->output);
244+ free(prop->cols);
245+ free(prop);
262246 }
263247
264248 /**
265249 * creates a shapehandles structure
266250 */
267-shphandles *createShps(void)
268-{
269- shphandles *shps;
270- shps = malloc(sizeof(shphandles));
271- shps->trk = NULL;
272- shps->wpt = NULL;
273- shps->rte = NULL;
274- shps->trk_edg = NULL;
275- shps->rte_edg = NULL;
276- shps->trk_pnt = NULL;
277- shps->rte_pnt = NULL;
278- return shps;
251+shphandles *createShps(void) {
252+ shphandles *shps;
253+ shps = malloc(sizeof(shphandles));
254+ shps->trk = NULL;
255+ shps->wpt = NULL;
256+ shps->rte = NULL;
257+ shps->trk_edg = NULL;
258+ shps->rte_edg = NULL;
259+ shps->trk_pnt = NULL;
260+ shps->rte_pnt = NULL;
261+ return shps;
279262 }
280263
281264 /**
282265 * creates a dbfhandles structure
283266 */
284-dbfhandles *createDbfs(void)
285-{
286- dbfhandles *dbfs;
287- dbfs = malloc(sizeof(dbfhandles));
288- dbfs->trk = NULL;
289- dbfs->wpt = NULL;
290- dbfs->rte = NULL;
291- dbfs->trk_edg = NULL;
292- dbfs->rte_edg = NULL;
293- dbfs->trk_pnt = NULL;
294- dbfs->rte_pnt = NULL;
295- return dbfs;
267+dbfhandles *createDbfs(void) {
268+ dbfhandles *dbfs;
269+ dbfs = malloc(sizeof(dbfhandles));
270+ dbfs->trk = NULL;
271+ dbfs->wpt = NULL;
272+ dbfs->rte = NULL;
273+ dbfs->trk_edg = NULL;
274+ dbfs->rte_edg = NULL;
275+ dbfs->trk_pnt = NULL;
276+ dbfs->rte_pnt = NULL;
277+ return dbfs;
296278 }
297279
298280 /**
299281 * creates a parse structure
300282 */
301-parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
302-{
303- parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
304- shphandles *shps = createShps();
305- dbfhandles *dbfs = createDbfs();
306- pathattr *pattr = createPathAttr();
307- g2sattr *attr = createAttr();
308- parent *p = (parent *) malloc(sizeof(parent));
309- parent *c = (parent *) malloc(sizeof(parent));
310- p->name = NULL;
311- p->parentptr = NULL;
312- c->name = "root";
313- c->parentptr = p;
314- pdata->depth = 0;
315- pdata->databuf = malloc(sizeof(char) * DATABUFSIZE);
316- pdata->bufptr = NULL;
317- pdata->failed = 0;
318- pdata->failedid = 0;
319- pdata->parser = parser;
320- pdata->parent = p;
321- pdata->current = c;
322- pdata->shps = shps;
323- pdata->dbfs = dbfs;
324- pdata->prop = prop;
325- pdata->pattr = pattr;
326- pdata->attr = attr;
327- return pdata;
283+parsedata *createParsedata(XML_Parser parser, g2sprop * prop) {
284+ parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
285+ shphandles *shps = createShps();
286+ dbfhandles *dbfs = createDbfs();
287+ pathattr *pattr = createPathAttr();
288+ g2sattr *attr = createAttr();
289+ parent *p = (parent *) malloc(sizeof(parent));
290+ parent *c = (parent *) malloc(sizeof(parent));
291+ p->name = NULL;
292+ p->parentptr = NULL;
293+ c->name = "root";
294+ c->parentptr = p;
295+ pdata->depth = 0;
296+ pdata->databuf = malloc(sizeof(char) * DATABUFSIZE);
297+ pdata->bufptr = NULL;
298+ pdata->failed = 0;
299+ pdata->failedid = 0;
300+ pdata->parser = parser;
301+ pdata->parent = p;
302+ pdata->current = c;
303+ pdata->shps = shps;
304+ pdata->dbfs = dbfs;
305+ pdata->prop = prop;
306+ pdata->pattr = pattr;
307+ pdata->attr = attr;
308+ return pdata;
328309 }
329310
330311 /*
331312 * close and free resoures
332313 */
333-void closeParsedata(parsedata * pdata)
334-{
335- free(pdata->shps);
336- free(pdata->dbfs);
337- free(pdata->parent);
338- free(pdata->current);
339- free(pdata->databuf);
340- free(pdata->attr);
341- free(pdata->pattr);
342- free(pdata);
314+void closeParsedata(parsedata * pdata) {
315+ free(pdata->shps);
316+ free(pdata->dbfs);
317+ free(pdata->parent);
318+ free(pdata->current);
319+ free(pdata->databuf);
320+ free(pdata->attr);
321+ free(pdata->pattr);
322+ free(pdata);
343323 }
--- trunk/gpx2shp/src/parser.c (revision 5)
+++ trunk/gpx2shp/src/parser.c (revision 6)
@@ -8,109 +8,104 @@
88 /**
99 * a handler to parse charctor data on expat
1010 */
11-void charHandle(void *userdata, const XML_Char * data, int length)
12-{
13- static int bufsize = DATABUFSIZE;
14- parsedata *pdata = (parsedata *) userdata;
15- if (bufsize < length) {
16- pdata->databuf =
17- realloc(pdata->databuf, sizeof(char) * (length + 1));
18- bufsize = length;
19- }
20- strncpy(pdata->databuf, data, length);
21- pdata->bufptr = pdata->databuf;
22- pdata->bufptr += length;
23- *pdata->bufptr = '\0';
11+void charHandle(void *userdata, const XML_Char * data, int length) {
12+ static int bufsize = DATABUFSIZE;
13+ parsedata *pdata = (parsedata *) userdata;
14+ if (bufsize < length) {
15+ pdata->databuf = realloc(pdata->databuf, sizeof(char) * (length + 1));
16+ bufsize = length;
17+ }
18+ strncpy(pdata->databuf, data, length);
19+ pdata->bufptr = pdata->databuf;
20+ pdata->bufptr += length;
21+ *pdata->bufptr = '\0';
2422 }
2523
2624 /**
2725 * a handler when a element starts
2826 */
29-void startElement(void *userdata, const char *element, const char **attr)
30-{
31- parsedata *pdata = (parsedata *) userdata;
32- pdata->parent = pdata->current;
33- pdata->current = malloc(sizeof(parent));
34- pdata->current->name = malloc(sizeof(char) * (strlen(element) + 1));
35- strcpy(pdata->current->name, element);
36- pdata->current->parentptr = pdata->parent;
37- startElementControl(pdata, element, attr);
38- if (pdata->prop->verbose) {
39- int i;
40- for (i = 0; i < pdata->depth; i++)
41- printf(" ");
42- printf("<%s>: %s", element, pdata->parent->name);
43- for (i = 0; attr[i]; i += 2) {
44- printf(" %s='%s'", attr[i], attr[i + 1]);
27+void startElement(void *userdata, const char *element, const char **attr) {
28+ parsedata *pdata = (parsedata *) userdata;
29+ pdata->parent = pdata->current;
30+ pdata->current = malloc(sizeof(parent));
31+ pdata->current->name = malloc(sizeof(char) * (strlen(element) + 1));
32+ strcpy(pdata->current->name, element);
33+ pdata->current->parentptr = pdata->parent;
34+ startElementControl(pdata, element, attr);
35+ if (pdata->prop->verbose) {
36+ int i;
37+ for (i = 0; i < pdata->depth; i++)
38+ printf(" ");
39+ printf("<%s>: %s", element, pdata->parent->name);
40+ for (i = 0; attr[i]; i += 2) {
41+ printf(" %s='%s'", attr[i], attr[i + 1]);
42+ }
43+ printf("\n");
4544 }
46- printf("\n");
47- }
48- pdata->depth++;
45+ pdata->depth++;
4946 }
5047
5148 /**
5249 * a handler when a element ends
5350 */
54-void endElement(void *userdata, const char *element)
55-{
56- parsedata *pdata = (parsedata *) userdata;
57- endElementControl(pdata, element);
58- if (pdata->prop->verbose) {
59- int i;
60- if (!strcmp(element, "name")) {
61- printf("%s\n", pdata->databuf);
51+void endElement(void *userdata, const char *element) {
52+ parsedata *pdata = (parsedata *) userdata;
53+ endElementControl(pdata, element);
54+ if (pdata->prop->verbose) {
55+ int i;
56+ if (!strcmp(element, "name")) {
57+ printf("%s\n", pdata->databuf);
58+ }
59+ for (i = 0; i < pdata->depth; i++)
60+ printf(" ");
61+ printf("</%s>\n", pdata->current->name);
6262 }
63- for (i = 0; i < pdata->depth; i++)
64- printf(" ");
65- printf("</%s>\n", pdata->current->name);
66- }
67- free(pdata->current->name);
68- free(pdata->current);
69- pdata->current = pdata->parent;
70- pdata->parent = pdata->parent->parentptr;
71- pdata->depth--;
63+ free(pdata->current->name);
64+ free(pdata->current);
65+ pdata->current = pdata->parent;
66+ pdata->parent = pdata->parent->parentptr;
67+ pdata->depth--;
7268 }
7369
74-void parseMain(g2sprop * prop)
75-{
76- FILE *fp;
77- char buff[BUFFSIZE];
78- XML_Parser parser;
79- parsedata *pdata;
80- fp = fopen(prop->sourcefile, "r");
81- if (fp == NULL) {
82- fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
83- exit(ERR_CANNOTOPEN);
84- }
85- parser = XML_ParserCreate(NULL);
86- if (!parser) {
87- fprintf(stderr, "Couldn't allocate memory for parser\n");
88- exit(ERR_OUTOFMEMORY);
89- }
90- pdata = createParsedata(parser, prop);
91- XML_SetUserData(parser, pdata);
92- XML_SetElementHandler(parser, startElement, endElement);
93- XML_SetCharacterDataHandler(parser, charHandle);
94- for (;;) {
95- int done;
96- int len;
97- fgets(buff, BUFFSIZE, fp);
98- len = (int) strlen(buff);
99- if (ferror(fp)) {
100- fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
101- exit(ERR_READERROR);
70+void parseMain(g2sprop * prop) {
71+ FILE *fp;
72+ char buff[BUFFSIZE];
73+ XML_Parser parser;
74+ parsedata *pdata;
75+ fp = fopen(prop->sourcefile, "r");
76+ if (fp == NULL ) {
77+ fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
78+ exit(ERR_CANNOTOPEN);
10279 }
103- done = feof(fp);
104- if (done)
105- break;
106- if (!XML_Parse(parser, buff, len, done)) {
107- fprintf(stderr, "Parse error at line %d:\n%s\n",
108- XML_GetCurrentLineNumber(parser),
109- XML_ErrorString(XML_GetErrorCode(parser)));
110- exit(ERR_PARSEERROR);
80+ parser = XML_ParserCreate(NULL );
81+ if (!parser) {
82+ fprintf(stderr, "Couldn't allocate memory for parser\n");
83+ exit(ERR_OUTOFMEMORY);
11184 }
112- }
113- closeShpFiles(pdata->shps);
114- closeDbfFiles(pdata->dbfs);
115- closeParsedata(pdata);
85+ pdata = createParsedata(parser, prop);
86+ XML_SetUserData(parser, pdata);
87+ XML_SetElementHandler(parser, startElement, endElement);
88+ XML_SetCharacterDataHandler(parser, charHandle);
89+ for (;;) {
90+ int done;
91+ int len;
92+ fgets(buff, BUFFSIZE, fp);
93+ len = (int) strlen(buff);
94+ if (ferror(fp)) {
95+ fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
96+ exit(ERR_READERROR);
97+ }
98+ done = feof(fp);
99+ if (done)
100+ break;
101+ if (!XML_Parse(parser, buff, len, done)) {
102+ fprintf(stderr, "Parse error at line %d:\n%s\n",
103+ XML_GetCurrentLineNumber(parser),
104+ XML_ErrorString(XML_GetErrorCode(parser)));
105+ exit(ERR_PARSEERROR);
106+ }
107+ }
108+ closeShpFiles(pdata->shps);
109+ closeDbfFiles(pdata->dbfs);
110+ closeParsedata(pdata);
116111 }
Show on old repository browser