]>
Commit | Line | Data |
---|---|---|
40a8d1c2 EB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
a482007a | 4 | * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net> |
17acdaec | 5 | * Copyright (C) 2014-2015, Rob Norris <rw_norris@hotmail.com> |
40a8d1c2 EB |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | * | |
0e94c83d | 21 | * See: http://www.gpsbabel.org/htmldoc-development/Data_Filters.html |
40a8d1c2 | 22 | */ |
4c77d5e0 | 23 | #ifdef HAVE_CONFIG_H |
40a8d1c2 | 24 | #include "config.h" |
4c77d5e0 | 25 | #endif |
40a8d1c2 | 26 | #include <string.h> |
4c77d5e0 | 27 | #include <glib/gi18n.h> |
40a8d1c2 EB |
28 | |
29 | #include "viking.h" | |
30 | #include "babel.h" | |
31 | #include "gpx.h" | |
32 | #include "acquire.h" | |
33 | ||
0e94c83d | 34 | /************************************ Simplify (Count) *****************************/ |
40a8d1c2 | 35 | |
40a8d1c2 EB |
36 | /* spin button scales */ |
37 | VikLayerParamScale simplify_params_scales[] = { | |
38 | {1, 10000, 10, 0}, | |
39 | }; | |
40 | ||
41 | VikLayerParam bfilter_simplify_params[] = { | |
63959706 | 42 | { VIK_LAYER_NUM_TYPES, "numberofpoints", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Max number of points:"), VIK_LAYER_WIDGET_SPINBUTTON, simplify_params_scales, NULL, NULL, NULL, NULL, NULL }, |
40a8d1c2 EB |
43 | }; |
44 | ||
45 | VikLayerParamData bfilter_simplify_params_defaults[] = { | |
0f89a3a3 RN |
46 | /* Annoyingly 'C' cannot initialize unions properly */ |
47 | /* It's dependent on the standard used or the compiler support... */ | |
48 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ | |
2fcb1893 | 49 | { .u = 100 }, |
0f89a3a3 | 50 | #else |
40a8d1c2 | 51 | { 100 }, |
0f89a3a3 | 52 | #endif |
40a8d1c2 EB |
53 | }; |
54 | ||
17acdaec RN |
55 | static void datasource_bfilter_simplify_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) |
56 | { | |
3adb6827 RN |
57 | po->babelargs = g_strdup ( "-i gpx" ); |
58 | po->filename = g_strdup ( input_filename ); | |
59 | po->babel_filters = g_strdup_printf ( "-x simplify,count=%d", paramdatas[0].u ); | |
17acdaec RN |
60 | } |
61 | ||
40a8d1c2 | 62 | VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { |
7306a492 | 63 | N_("Simplify All Tracks..."), |
4c77d5e0 | 64 | N_("Simplified Tracks"), |
40a8d1c2 EB |
65 | VIK_DATASOURCE_CREATENEWLAYER, |
66 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
d2525524 | 67 | TRUE, |
40a8d1c2 | 68 | FALSE, /* keep dialog open after success */ |
b2aa700f | 69 | TRUE, |
40a8d1c2 | 70 | NULL, NULL, NULL, |
17acdaec RN |
71 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_simplify_get_process_options, |
72 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
40a8d1c2 | 73 | NULL, NULL, NULL, |
2b756ea0 | 74 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
75 | |
76 | bfilter_simplify_params, | |
77 | sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]), | |
78 | bfilter_simplify_params_defaults, | |
79 | NULL, | |
80 | 0 | |
81 | }; | |
82 | ||
0e94c83d RN |
83 | /**************************** Compress (Simplify by Error Factor Method) *****************************/ |
84 | ||
0e94c83d RN |
85 | static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} }; |
86 | ||
87 | VikLayerParam bfilter_compress_params[] = { | |
88 | //{ VIK_LAYER_NUM_TYPES, "compressmethod", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Simplify Method:"), VIK_LAYER_WIDGET_COMBOBOX, compress_method, NULL, NULL, NULL, NULL, NULL }, | |
89 | { VIK_LAYER_NUM_TYPES, "compressfactor", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Error Factor:"), VIK_LAYER_WIDGET_SPINBUTTON, compress_spin_scales, NULL, | |
90 | N_("Specifies the maximum allowable error that may be introduced by removing a single point by the crosstrack method. See the manual or GPSBabel Simplify Filter documentation for more detail."), NULL, NULL, NULL }, | |
91 | }; | |
92 | ||
93 | VikLayerParamData bfilter_compress_params_defaults[] = { | |
94 | /* Annoyingly 'C' cannot initialize unions properly */ | |
95 | /* It's dependent on the standard used or the compiler support... */ | |
96 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ | |
97 | { .d = 0.001 }, | |
98 | #else | |
99 | { 0.001 }, | |
100 | #endif | |
101 | }; | |
102 | ||
17acdaec RN |
103 | /** |
104 | * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html | |
105 | */ | |
106 | static void datasource_bfilter_compress_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) | |
107 | { | |
108 | gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' '; | |
109 | // I toyed with making the length,crosstrack or relative methods selectable | |
110 | // However several things: | |
111 | // - mainly that typical values to use for the error relate to method being used - so hard to explain and then give a default sensible value in the UI | |
112 | // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM | |
113 | // - options make this more complicated to use - is even that useful to be allowed to change the error value? | |
114 | // NB units not applicable if relative method used - defaults to Miles when not specified | |
3adb6827 RN |
115 | po->babelargs = g_strdup ( "-i gpx" ); |
116 | po->filename = g_strdup ( input_filename ); | |
117 | po->babel_filters = g_strdup_printf ( "-x simplify,crosstrack,error=%-.5f%c", paramdatas[0].d, units ); | |
17acdaec RN |
118 | } |
119 | ||
0e94c83d RN |
120 | /** |
121 | * Allow 'compressing' tracks/routes using the Simplify by Error Factor method | |
122 | */ | |
123 | VikDataSourceInterface vik_datasource_bfilter_compress_interface = { | |
124 | N_("Compress Tracks..."), | |
125 | N_("Compressed Tracks"), | |
126 | VIK_DATASOURCE_CREATENEWLAYER, | |
127 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
128 | TRUE, | |
129 | FALSE, // Close the dialog after successful operation | |
130 | TRUE, | |
131 | NULL, NULL, NULL, | |
17acdaec RN |
132 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_compress_get_process_options, |
133 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
0e94c83d RN |
134 | NULL, NULL, NULL, |
135 | (VikDataSourceOffFunc) NULL, | |
136 | ||
137 | bfilter_compress_params, | |
138 | sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]), | |
139 | bfilter_compress_params_defaults, | |
140 | NULL, | |
141 | 0 | |
142 | }; | |
143 | ||
40a8d1c2 EB |
144 | /************************************ Duplicate Location ***********************************/ |
145 | ||
17acdaec RN |
146 | static void datasource_bfilter_dup_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) |
147 | { | |
3adb6827 RN |
148 | po->babelargs = g_strdup ( "-i gpx" ); |
149 | po->filename = g_strdup ( input_filename ); | |
150 | po->babel_filters = g_strdup ( "-x duplicate,location" ); | |
17acdaec | 151 | } |
40a8d1c2 EB |
152 | |
153 | VikDataSourceInterface vik_datasource_bfilter_dup_interface = { | |
4c77d5e0 GB |
154 | N_("Remove Duplicate Waypoints"), |
155 | N_("Remove Duplicate Waypoints"), | |
40a8d1c2 EB |
156 | VIK_DATASOURCE_CREATENEWLAYER, |
157 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
d2525524 | 158 | TRUE, |
40a8d1c2 | 159 | FALSE, /* keep dialog open after success */ |
b2aa700f | 160 | TRUE, |
40a8d1c2 | 161 | NULL, NULL, NULL, |
17acdaec RN |
162 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_dup_get_process_options, |
163 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
40a8d1c2 | 164 | NULL, NULL, NULL, |
2b756ea0 | 165 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
166 | |
167 | NULL, 0, NULL, NULL, 0 | |
168 | }; | |
169 | ||
170 | ||
f74395cc RN |
171 | /************************************ Swap Lat<->Lon ***********************************/ |
172 | ||
173 | VikLayerParamData bfilter_manual_params_defaults[] = { | |
174 | { .s = NULL }, | |
175 | }; | |
176 | ||
177 | VikLayerParam bfilter_manual_params[] = { | |
178 | { VIK_LAYER_NUM_TYPES, "manual", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Manual filter:"), VIK_LAYER_WIDGET_ENTRY, NULL, NULL, | |
179 | N_("Manual filter command: e.g. 'swap'."), NULL, NULL, NULL }, | |
180 | }; | |
181 | ||
182 | static void datasource_bfilter_manual_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 ) | |
183 | { | |
184 | po->babelargs = g_strdup ( "-i gpx" ); | |
185 | po->filename = g_strdup ( input_filename ); | |
186 | po->babel_filters = g_strconcat ( "-x ", paramdatas[0].s, NULL ); | |
187 | } | |
188 | ||
189 | VikDataSourceInterface vik_datasource_bfilter_manual_interface = { | |
190 | N_("Manual filter"), | |
191 | N_("Manual filter"), | |
192 | VIK_DATASOURCE_CREATENEWLAYER, | |
193 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
194 | TRUE, | |
195 | FALSE, /* keep dialog open after success */ | |
196 | TRUE, | |
197 | NULL, NULL, NULL, | |
198 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_manual_get_process_options, | |
199 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
200 | NULL, NULL, NULL, | |
201 | (VikDataSourceOffFunc) NULL, | |
202 | ||
203 | bfilter_manual_params, | |
204 | sizeof(bfilter_manual_params)/sizeof(bfilter_manual_params[0]), | |
205 | bfilter_manual_params_defaults, | |
206 | NULL, | |
207 | 0 | |
208 | }; | |
209 | ||
40a8d1c2 EB |
210 | /************************************ Polygon ***********************************/ |
211 | ||
17acdaec RN |
212 | static void datasource_bfilter_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename ) |
213 | { | |
214 | po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,file=- -o gpx -F -", input_track_filename, input_filename ); | |
215 | } | |
40a8d1c2 | 216 | /* TODO: shell_escape stuff */ |
40a8d1c2 EB |
217 | |
218 | VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { | |
4c77d5e0 | 219 | N_("Waypoints Inside This"), |
8a7788c9 | 220 | N_("Polygonized Layer"), |
40a8d1c2 EB |
221 | VIK_DATASOURCE_CREATENEWLAYER, |
222 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, | |
d2525524 | 223 | TRUE, |
40a8d1c2 | 224 | FALSE, /* keep dialog open after success */ |
b2aa700f | 225 | TRUE, |
40a8d1c2 | 226 | NULL, NULL, NULL, |
17acdaec RN |
227 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_polygon_get_process_options, |
228 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
40a8d1c2 | 229 | NULL, NULL, NULL, |
2b756ea0 | 230 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
231 | |
232 | NULL, | |
233 | 0, | |
234 | NULL, | |
235 | NULL, | |
236 | 0 | |
237 | }; | |
238 | ||
17acdaec | 239 | /************************************ Exclude Polygon ***********************************/ |
40a8d1c2 | 240 | |
17acdaec | 241 | static void datasource_bfilter_exclude_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename ) |
40a8d1c2 | 242 | { |
17acdaec | 243 | po->shell_command = g_strdup_printf ( "gpsbabel -i gpx -f %s -o arc -F - | gpsbabel -i gpx -f %s -x polygon,exclude,file=- -o gpx -F -", input_track_filename, input_filename ); |
40a8d1c2 | 244 | } |
40a8d1c2 | 245 | /* TODO: shell_escape stuff */ |
40a8d1c2 EB |
246 | |
247 | VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { | |
4c77d5e0 GB |
248 | N_("Waypoints Outside This"), |
249 | N_("Polygonzied Layer"), | |
40a8d1c2 EB |
250 | VIK_DATASOURCE_CREATENEWLAYER, |
251 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, | |
d2525524 | 252 | TRUE, |
40a8d1c2 | 253 | FALSE, /* keep dialog open after success */ |
b2aa700f | 254 | TRUE, |
40a8d1c2 | 255 | NULL, NULL, NULL, |
17acdaec RN |
256 | (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_exclude_polygon_get_process_options, |
257 | (VikDataSourceProcessFunc) a_babel_convert_from, | |
40a8d1c2 | 258 | NULL, NULL, NULL, |
2b756ea0 | 259 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
260 | |
261 | NULL, | |
262 | 0, | |
263 | NULL, | |
264 | NULL, | |
265 | 0 | |
266 | }; |