2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2014-2015, Rob Norris <rw_norris@hotmail.com>
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.
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.
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
21 * See: http://www.gpsbabel.org/htmldoc-development/Data_Filters.html
27 #include <glib/gi18n.h>
35 /************************************ Simplify (Count) *****************************/
37 /* spin button scales */
38 VikLayerParamScale simplify_params_scales[] = {
42 VikLayerParam bfilter_simplify_params[] = {
43 { 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 },
46 VikLayerParamData bfilter_simplify_params_defaults[] = {
47 /* Annoyingly 'C' cannot initialize unions properly */
48 /* It's dependent on the standard used or the compiler support... */
49 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__
56 static void datasource_bfilter_simplify_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
58 po->babelargs = g_strdup ( "-i gpx" );
59 po->filename = g_strdup ( input_filename );
60 po->babel_filters = g_strdup_printf ( "-x simplify,count=%d", paramdatas[0].u );
62 // Store for subsequent default use
63 bfilter_simplify_params_defaults[0].u = paramdatas[0].u;
66 #define VIK_SETTINGS_BFILTER_SIMPLIFY "bfilter_simplify"
67 static gboolean bfilter_simplify_default_set = FALSE;
69 static gpointer datasource_bfilter_simplify_init ( acq_vik_t *not_used )
71 if ( !bfilter_simplify_default_set ) {
73 if ( !a_settings_get_integer ( VIK_SETTINGS_BFILTER_SIMPLIFY, &tmp ) )
76 bfilter_simplify_params_defaults[0].u = tmp;
77 bfilter_simplify_default_set = TRUE;
83 VikDataSourceInterface vik_datasource_bfilter_simplify_interface = {
84 N_("Simplify All Tracks..."),
85 N_("Simplified Tracks"),
86 VIK_DATASOURCE_CREATENEWLAYER,
87 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
89 FALSE, /* keep dialog open after success */
91 (VikDataSourceInitFunc) datasource_bfilter_simplify_init,
93 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_simplify_get_process_options,
94 (VikDataSourceProcessFunc) a_babel_convert_from,
96 (VikDataSourceOffFunc) NULL,
98 bfilter_simplify_params,
99 sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]),
100 bfilter_simplify_params_defaults,
105 /**************************** Compress (Simplify by Error Factor Method) *****************************/
107 static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} };
109 VikLayerParam bfilter_compress_params[] = {
110 //{ 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 },
111 { VIK_LAYER_NUM_TYPES, "compressfactor", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Error Factor:"), VIK_LAYER_WIDGET_SPINBUTTON, compress_spin_scales, NULL,
112 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 },
115 VikLayerParamData bfilter_compress_params_defaults[] = {
116 /* Annoyingly 'C' cannot initialize unions properly */
117 /* It's dependent on the standard used or the compiler support... */
118 #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__
126 * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html
128 static void datasource_bfilter_compress_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
130 gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' ';
131 // I toyed with making the length,crosstrack or relative methods selectable
132 // However several things:
133 // - 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
134 // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM
135 // - options make this more complicated to use - is even that useful to be allowed to change the error value?
136 // NB units not applicable if relative method used - defaults to Miles when not specified
137 po->babelargs = g_strdup ( "-i gpx" );
138 po->filename = g_strdup ( input_filename );
139 po->babel_filters = g_strdup_printf ( "-x simplify,crosstrack,error=%-.5f%c", paramdatas[0].d, units );
141 // Store for subsequent default use
142 bfilter_compress_params_defaults[0].d = paramdatas[0].d;
145 #define VIK_SETTINGS_BFILTER_COMPRESS "bfilter_compress"
146 static gboolean bfilter_compress_default_set = FALSE;
148 static gpointer datasource_bfilter_compress_init ( acq_vik_t *not_used )
150 if ( !bfilter_compress_default_set ) {
152 if ( !a_settings_get_double ( VIK_SETTINGS_BFILTER_COMPRESS, &tmp ) )
155 bfilter_compress_params_defaults[0].d = tmp;
156 bfilter_compress_default_set = TRUE;
163 * Allow 'compressing' tracks/routes using the Simplify by Error Factor method
165 VikDataSourceInterface vik_datasource_bfilter_compress_interface = {
166 N_("Compress Tracks..."),
167 N_("Compressed Tracks"),
168 VIK_DATASOURCE_CREATENEWLAYER,
169 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
171 FALSE, // Close the dialog after successful operation
173 (VikDataSourceInitFunc) datasource_bfilter_compress_init,
175 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_compress_get_process_options,
176 (VikDataSourceProcessFunc) a_babel_convert_from,
178 (VikDataSourceOffFunc) NULL,
180 bfilter_compress_params,
181 sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]),
182 bfilter_compress_params_defaults,
187 /************************************ Duplicate Location ***********************************/
189 static void datasource_bfilter_dup_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
191 po->babelargs = g_strdup ( "-i gpx" );
192 po->filename = g_strdup ( input_filename );
193 po->babel_filters = g_strdup ( "-x duplicate,location" );
196 VikDataSourceInterface vik_datasource_bfilter_dup_interface = {
197 N_("Remove Duplicate Waypoints"),
198 N_("Remove Duplicate Waypoints"),
199 VIK_DATASOURCE_CREATENEWLAYER,
200 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
202 FALSE, /* keep dialog open after success */
205 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_dup_get_process_options,
206 (VikDataSourceProcessFunc) a_babel_convert_from,
208 (VikDataSourceOffFunc) NULL,
210 NULL, 0, NULL, NULL, 0
214 /************************************ Swap Lat<->Lon ***********************************/
216 VikLayerParamData bfilter_manual_params_defaults[] = {
220 VikLayerParam bfilter_manual_params[] = {
221 { VIK_LAYER_NUM_TYPES, "manual", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Manual filter:"), VIK_LAYER_WIDGET_ENTRY, NULL, NULL,
222 N_("Manual filter command: e.g. 'swap'."), NULL, NULL, NULL },
225 static void datasource_bfilter_manual_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
227 po->babelargs = g_strdup ( "-i gpx" );
228 po->filename = g_strdup ( input_filename );
229 po->babel_filters = g_strconcat ( "-x ", paramdatas[0].s, NULL );
232 VikDataSourceInterface vik_datasource_bfilter_manual_interface = {
235 VIK_DATASOURCE_CREATENEWLAYER,
236 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
238 FALSE, /* keep dialog open after success */
241 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_manual_get_process_options,
242 (VikDataSourceProcessFunc) a_babel_convert_from,
244 (VikDataSourceOffFunc) NULL,
246 bfilter_manual_params,
247 sizeof(bfilter_manual_params)/sizeof(bfilter_manual_params[0]),
248 bfilter_manual_params_defaults,
253 /************************************ Polygon ***********************************/
255 static void datasource_bfilter_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename )
257 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 );
259 /* TODO: shell_escape stuff */
261 VikDataSourceInterface vik_datasource_bfilter_polygon_interface = {
262 N_("Waypoints Inside This"),
263 N_("Polygonized Layer"),
264 VIK_DATASOURCE_CREATENEWLAYER,
265 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
267 FALSE, /* keep dialog open after success */
270 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_polygon_get_process_options,
271 (VikDataSourceProcessFunc) a_babel_convert_from,
273 (VikDataSourceOffFunc) NULL,
282 /************************************ Exclude Polygon ***********************************/
284 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 )
286 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 );
288 /* TODO: shell_escape stuff */
290 VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = {
291 N_("Waypoints Outside This"),
292 N_("Polygonzied Layer"),
293 VIK_DATASOURCE_CREATENEWLAYER,
294 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
296 FALSE, /* keep dialog open after success */
299 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_exclude_polygon_get_process_options,
300 (VikDataSourceProcessFunc) a_babel_convert_from,
302 (VikDataSourceOffFunc) NULL,