]>
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> |
0e94c83d | 5 | * Copyright (C) 2014, 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 | |
ed691ed1 | 36 | static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); |
40a8d1c2 EB |
37 | |
38 | /* TODO: shell_escape stuff */ | |
39 | /* TODO: name is useless for filters */ | |
40 | ||
41 | /* spin button scales */ | |
42 | VikLayerParamScale simplify_params_scales[] = { | |
43 | {1, 10000, 10, 0}, | |
44 | }; | |
45 | ||
46 | VikLayerParam bfilter_simplify_params[] = { | |
63959706 | 47 | { 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 |
48 | }; |
49 | ||
50 | VikLayerParamData bfilter_simplify_params_defaults[] = { | |
0f89a3a3 RN |
51 | /* Annoyingly 'C' cannot initialize unions properly */ |
52 | /* It's dependent on the standard used or the compiler support... */ | |
53 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ | |
54 | { .i = 100 }, | |
55 | #else | |
40a8d1c2 | 56 | { 100 }, |
0f89a3a3 | 57 | #endif |
40a8d1c2 EB |
58 | }; |
59 | ||
60 | VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { | |
7306a492 | 61 | N_("Simplify All Tracks..."), |
4c77d5e0 | 62 | N_("Simplified Tracks"), |
40a8d1c2 EB |
63 | VIK_DATASOURCE_CREATENEWLAYER, |
64 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
d2525524 | 65 | TRUE, |
40a8d1c2 | 66 | FALSE, /* keep dialog open after success */ |
b2aa700f | 67 | TRUE, |
40a8d1c2 EB |
68 | NULL, NULL, NULL, |
69 | (VikDataSourceGetCmdStringFunc) datasource_bfilter_simplify_get_cmd_string, | |
eb3f9398 | 70 | (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, |
40a8d1c2 | 71 | NULL, NULL, NULL, |
2b756ea0 | 72 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
73 | |
74 | bfilter_simplify_params, | |
75 | sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]), | |
76 | bfilter_simplify_params_defaults, | |
77 | NULL, | |
78 | 0 | |
79 | }; | |
80 | ||
81 | ||
ed691ed1 | 82 | static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) |
40a8d1c2 EB |
83 | { |
84 | *input_file_type = NULL; | |
85 | *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,count=%d -o gpx -F -", input_filename, paramdatas[0].u ); | |
86 | } | |
87 | ||
0e94c83d RN |
88 | /**************************** Compress (Simplify by Error Factor Method) *****************************/ |
89 | ||
90 | static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); | |
91 | ||
92 | /* TODO: shell_escape stuff */ | |
93 | ||
94 | static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} }; | |
95 | ||
96 | VikLayerParam bfilter_compress_params[] = { | |
97 | //{ 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 }, | |
98 | { VIK_LAYER_NUM_TYPES, "compressfactor", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Error Factor:"), VIK_LAYER_WIDGET_SPINBUTTON, compress_spin_scales, NULL, | |
99 | 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 }, | |
100 | }; | |
101 | ||
102 | VikLayerParamData bfilter_compress_params_defaults[] = { | |
103 | /* Annoyingly 'C' cannot initialize unions properly */ | |
104 | /* It's dependent on the standard used or the compiler support... */ | |
105 | #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ | |
106 | { .d = 0.001 }, | |
107 | #else | |
108 | { 0.001 }, | |
109 | #endif | |
110 | }; | |
111 | ||
112 | /** | |
113 | * Allow 'compressing' tracks/routes using the Simplify by Error Factor method | |
114 | */ | |
115 | VikDataSourceInterface vik_datasource_bfilter_compress_interface = { | |
116 | N_("Compress Tracks..."), | |
117 | N_("Compressed Tracks"), | |
118 | VIK_DATASOURCE_CREATENEWLAYER, | |
119 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
120 | TRUE, | |
121 | FALSE, // Close the dialog after successful operation | |
122 | TRUE, | |
123 | NULL, NULL, NULL, | |
124 | (VikDataSourceGetCmdStringFunc) datasource_bfilter_compress_get_cmd_string, | |
125 | (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, | |
126 | NULL, NULL, NULL, | |
127 | (VikDataSourceOffFunc) NULL, | |
128 | ||
129 | bfilter_compress_params, | |
130 | sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]), | |
131 | bfilter_compress_params_defaults, | |
132 | NULL, | |
133 | 0 | |
134 | }; | |
135 | ||
136 | /** | |
137 | * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html | |
138 | */ | |
139 | static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) | |
140 | { | |
141 | *input_file_type = NULL; | |
142 | gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' '; | |
143 | // I toyed with making the length,crosstrack or relative methods selectable | |
144 | // However several things: | |
145 | // - 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 | |
146 | // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM | |
147 | // - options make this more complicated to use - is even that useful to be allowed to change the error value? | |
148 | // NB units not applicable if relative method used - defaults to Miles when not specified | |
149 | *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,crosstrack,error=%-.5f%c -o gpx -F -", input_filename, paramdatas[0].d, units ); | |
150 | } | |
151 | ||
40a8d1c2 EB |
152 | /************************************ Duplicate Location ***********************************/ |
153 | ||
ed691ed1 | 154 | static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); |
40a8d1c2 EB |
155 | |
156 | /* TODO: shell_escape stuff */ | |
157 | /* TODO: name is useless for filters */ | |
158 | ||
159 | ||
160 | VikDataSourceInterface vik_datasource_bfilter_dup_interface = { | |
4c77d5e0 GB |
161 | N_("Remove Duplicate Waypoints"), |
162 | N_("Remove Duplicate Waypoints"), | |
40a8d1c2 EB |
163 | VIK_DATASOURCE_CREATENEWLAYER, |
164 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER, | |
d2525524 | 165 | TRUE, |
40a8d1c2 | 166 | FALSE, /* keep dialog open after success */ |
b2aa700f | 167 | TRUE, |
40a8d1c2 EB |
168 | NULL, NULL, NULL, |
169 | (VikDataSourceGetCmdStringFunc) datasource_bfilter_dup_get_cmd_string, | |
eb3f9398 | 170 | (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, |
40a8d1c2 | 171 | NULL, NULL, NULL, |
2b756ea0 | 172 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
173 | |
174 | NULL, 0, NULL, NULL, 0 | |
175 | }; | |
176 | ||
177 | ||
ed691ed1 | 178 | static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) |
40a8d1c2 EB |
179 | { |
180 | *input_file_type = NULL; | |
7de42638 | 181 | *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename ); |
40a8d1c2 EB |
182 | } |
183 | ||
184 | ||
185 | /************************************ Polygon ***********************************/ | |
186 | ||
ed691ed1 | 187 | static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ); |
40a8d1c2 EB |
188 | |
189 | /* TODO: shell_escape stuff */ | |
190 | /* TODO: name is useless for filters */ | |
191 | ||
192 | ||
193 | VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { | |
4c77d5e0 | 194 | N_("Waypoints Inside This"), |
8a7788c9 | 195 | N_("Polygonized Layer"), |
40a8d1c2 EB |
196 | VIK_DATASOURCE_CREATENEWLAYER, |
197 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, | |
d2525524 | 198 | TRUE, |
40a8d1c2 | 199 | FALSE, /* keep dialog open after success */ |
b2aa700f | 200 | TRUE, |
40a8d1c2 EB |
201 | NULL, NULL, NULL, |
202 | (VikDataSourceGetCmdStringFunc) datasource_bfilter_polygon_get_cmd_string, | |
eb3f9398 | 203 | (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, |
40a8d1c2 | 204 | NULL, NULL, NULL, |
2b756ea0 | 205 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
206 | |
207 | NULL, | |
208 | 0, | |
209 | NULL, | |
210 | NULL, | |
211 | 0 | |
212 | }; | |
213 | ||
214 | ||
ed691ed1 | 215 | static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ) |
40a8d1c2 EB |
216 | { |
217 | *input_file_type = NULL; | |
218 | *cmd = 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 ); | |
219 | } | |
220 | ||
221 | /************************************ Exclude Polygon ***********************************/ | |
222 | ||
ed691ed1 | 223 | static void datasource_bfilter_exclude_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ); |
40a8d1c2 EB |
224 | |
225 | /* TODO: shell_escape stuff */ | |
226 | /* TODO: name is useless for filters */ | |
227 | ||
228 | ||
229 | VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { | |
4c77d5e0 GB |
230 | N_("Waypoints Outside This"), |
231 | N_("Polygonzied Layer"), | |
40a8d1c2 EB |
232 | VIK_DATASOURCE_CREATENEWLAYER, |
233 | VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, | |
d2525524 | 234 | TRUE, |
40a8d1c2 | 235 | FALSE, /* keep dialog open after success */ |
b2aa700f | 236 | TRUE, |
40a8d1c2 EB |
237 | NULL, NULL, NULL, |
238 | (VikDataSourceGetCmdStringFunc) datasource_bfilter_exclude_polygon_get_cmd_string, | |
eb3f9398 | 239 | (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, |
40a8d1c2 | 240 | NULL, NULL, NULL, |
2b756ea0 | 241 | (VikDataSourceOffFunc) NULL, |
40a8d1c2 EB |
242 | |
243 | NULL, | |
244 | 0, | |
245 | NULL, | |
246 | NULL, | |
247 | 0 | |
248 | }; | |
249 | ||
250 | ||
ed691ed1 | 251 | static void datasource_bfilter_exclude_polygon_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, const gchar *input_track_filename, gpointer not_used ) |
40a8d1c2 EB |
252 | { |
253 | *input_file_type = NULL; | |
254 | *cmd = 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 ); | |
255 | } | |
256 |