forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discard.cc
270 lines (238 loc) · 6.09 KB
/
discard.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
Discard points based on high Degree of Precision (DOP) values.
Copyright (C) 2005-2014 Robert Lipe, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
#include "defs.h"
#include "filterdefs.h"
#include <stdlib.h>
// Can't use QRegularExpression because Linux won't get Qt 5 for years.
#include <QtCore/QRegExp>
#include <stdlib.h>
#include <stdio.h>
#if FILTERS_ENABLED
static char* hdopopt = NULL;
static char* vdopopt = NULL;
static char* andopt = NULL;
static char* satopt = NULL;
static char* fixnoneopt = NULL;
static char* fixunknownopt = NULL;
static char* eleminopt = NULL;
static char* elemaxopt = NULL;
static char* nameopt = NULL;
static QRegExp name_regex;
static char* descopt = NULL;
static QRegExp desc_regex;
static char* cmtopt = NULL;
static QRegExp cmt_regex;
static char* iconopt = NULL;
static QRegExp icon_regex;
static double hdopf;
static double vdopf;
static int satpf;
static int eleminpf;
static int elemaxpf;
static gpsdata_type what;
static route_head* head;
static
arglist_t fix_args[] = {
{
"hdop", &hdopopt, "Suppress points with higher hdop",
"-1.0", ARGTYPE_BEGIN_REQ | ARGTYPE_FLOAT, ARG_NOMINMAX
},
{
"vdop", &vdopopt, "Suppress points with higher vdop",
"-1.0", ARGTYPE_END_REQ | ARGTYPE_FLOAT, ARG_NOMINMAX
},
{
"hdopandvdop", &andopt, "Link hdop and vdop supression with AND",
NULL, ARGTYPE_BOOL, ARG_NOMINMAX
},
{
"sat", &satopt, "Minimium sats to keep points",
"-1.0", ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
},
{
"fixnone", &fixnoneopt, "Suppress points without fix",
NULL, ARGTYPE_BOOL, ARG_NOMINMAX
},
{
"fixunknown", &fixunknownopt, "Suppress points with unknown fix",
NULL, ARGTYPE_BOOL, ARG_NOMINMAX
},
{
"elemin", &eleminopt, "Suppress points below given elevation in meters",
NULL, ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
},
{
"elemax", &elemaxopt, "Suppress points above given elevation in meters",
NULL, ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
},
{
"matchname", &nameopt,
"Suppress points where name matches given name", NULL, ARGTYPE_STRING,
ARG_NOMINMAX, NULL
},
{
"matchdesc", &descopt,
"Suppress points where description matches given name", NULL, ARGTYPE_STRING,
ARG_NOMINMAX, NULL
},
{
"matchcmt", &cmtopt,
"Suppress points where comment matches given name", NULL, ARGTYPE_STRING,
ARG_NOMINMAX, NULL
},
{
"matchicon", &iconopt,
"Suppress points where type matches given name", NULL, ARGTYPE_STRING,
ARG_NOMINMAX, NULL
},
ARG_TERMINATOR
};
/*
* Decide whether to keep or toss this point.
*/
static void
fix_process_wpt(const Waypoint* wpt)
{
int del = 0;
int delh = 0;
int delv = 0;
Waypoint* waypointp = (Waypoint*) wpt;
if ((hdopf >= 0.0) && (waypointp->hdop > hdopf)) {
delh = 1;
}
if ((vdopf >= 0.0) && (waypointp->vdop > vdopf)) {
delv = 1;
}
if (andopt) {
del = delh && delv;
} else {
del = delh || delv;
}
if ((satpf >= 0) && (waypointp->sat < satpf)) {
del = 1;
}
if ((fixnoneopt) && (waypointp->fix == fix_none)) {
del = 1;
}
if ((fixunknownopt) && (waypointp->fix == fix_unknown)) {
del = 1;
}
if ((eleminopt) && (waypointp->altitude < eleminpf)) {
del = 1;
}
if ((elemaxopt) && (waypointp->altitude > elemaxpf)) {
del = 1;
}
if (nameopt && name_regex.indexIn(waypointp->shortname) >= 0) {
del = 1;
}
if (descopt && desc_regex.indexIn(waypointp->description) >= 0) {
del = 1;
}
if (cmtopt && cmt_regex.indexIn(waypointp->notes) >= 0) {
del = 1;
}
if (iconopt && icon_regex.indexIn(waypointp->icon_descr) >= 0) {
del = 1;
}
if (del) {
switch (what) {
case wptdata:
waypt_del(waypointp);
break;
case trkdata:
track_del_wpt(head, waypointp);
break;
case rtedata:
route_del_wpt(head, waypointp);
break;
default:
return;
}
delete waypointp;
}
}
static void
fix_process_head(const route_head* trk)
{
head = (route_head*)trk;
}
static void
fix_process(void)
{
// Filter waypoints.
what = wptdata;
waypt_disp_all(fix_process_wpt);
// Filter tracks
what = trkdata;
track_disp_all(fix_process_head, NULL, fix_process_wpt);
// And routes
what = rtedata;
route_disp_all(fix_process_head, NULL, fix_process_wpt);
}
static void
fix_init(const char* args)
{
if (hdopopt) {
hdopf = atof(hdopopt);
} else {
hdopf = -1.0;
}
if (vdopopt) {
vdopf = atof(vdopopt);
} else {
vdopf = -1.0;
}
if (satopt) {
satpf = atoi(satopt);
} else {
satpf = -1;
}
if (eleminopt) {
eleminpf = atoi(eleminopt);
}
if (elemaxopt) {
elemaxpf = atoi(elemaxopt);
}
if (nameopt) {
name_regex.setCaseSensitivity(Qt::CaseInsensitive);
name_regex.setPatternSyntax(QRegExp::WildcardUnix);
name_regex.setPattern(nameopt);
}
if (descopt) {
desc_regex.setCaseSensitivity(Qt::CaseInsensitive);
desc_regex.setPatternSyntax(QRegExp::WildcardUnix);
desc_regex.setPattern(descopt);
}
if (cmtopt) {
cmt_regex.setCaseSensitivity(Qt::CaseInsensitive);
cmt_regex.setPatternSyntax(QRegExp::WildcardUnix);
cmt_regex.setPattern(cmtopt);
}
if (iconopt) {
icon_regex.setCaseSensitivity(Qt::CaseInsensitive);
icon_regex.setPatternSyntax(QRegExp::WildcardUnix);
icon_regex.setPattern(iconopt);
}
}
filter_vecs_t discard_vecs = {
fix_init,
fix_process,
NULL,
NULL,
fix_args
};
#endif