]> git.street.me.uk Git - andy/viking.git/blame - src/datasource_bfilter.c
Add settings to override bfilter simplify and compress default values.
[andy/viking.git] / src / datasource_bfilter.c
CommitLineData
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"
4c853de9 33#include "settings.h"
40a8d1c2 34
0e94c83d 35/************************************ Simplify (Count) *****************************/
40a8d1c2 36
40a8d1c2
EB
37/* spin button scales */
38VikLayerParamScale simplify_params_scales[] = {
39 {1, 10000, 10, 0},
40};
41
42VikLayerParam bfilter_simplify_params[] = {
63959706 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 },
40a8d1c2
EB
44};
45
46VikLayerParamData bfilter_simplify_params_defaults[] = {
0f89a3a3
RN
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__
2fcb1893 50 { .u = 100 },
0f89a3a3 51#else
40a8d1c2 52 { 100 },
0f89a3a3 53#endif
40a8d1c2
EB
54};
55
17acdaec
RN
56static void datasource_bfilter_simplify_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
57{
3adb6827
RN
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 );
17acdaec
RN
61}
62
4c853de9
RN
63#define VIK_SETTINGS_BFILTER_SIMPLIFY "bfilter_simplify"
64static gboolean bfilter_simplify_default_set = FALSE;
65
66static gpointer datasource_bfilter_simplify_init ( acq_vik_t *not_used )
67{
68 if ( !bfilter_simplify_default_set ) {
69 gint tmp;
70 if ( !a_settings_get_integer ( VIK_SETTINGS_BFILTER_SIMPLIFY, &tmp ) )
71 tmp = 100;
72
73 bfilter_simplify_params_defaults[0].u = tmp;
74 bfilter_simplify_default_set = TRUE;
75 }
76
77 return NULL;
78}
79
40a8d1c2 80VikDataSourceInterface vik_datasource_bfilter_simplify_interface = {
7306a492 81 N_("Simplify All Tracks..."),
4c77d5e0 82 N_("Simplified Tracks"),
40a8d1c2
EB
83 VIK_DATASOURCE_CREATENEWLAYER,
84 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
d2525524 85 TRUE,
40a8d1c2 86 FALSE, /* keep dialog open after success */
b2aa700f 87 TRUE,
4c853de9
RN
88 (VikDataSourceInitFunc) datasource_bfilter_simplify_init,
89 NULL, NULL,
17acdaec
RN
90 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_simplify_get_process_options,
91 (VikDataSourceProcessFunc) a_babel_convert_from,
40a8d1c2 92 NULL, NULL, NULL,
2b756ea0 93 (VikDataSourceOffFunc) NULL,
40a8d1c2
EB
94
95 bfilter_simplify_params,
96 sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]),
97 bfilter_simplify_params_defaults,
98 NULL,
99 0
100};
101
0e94c83d
RN
102/**************************** Compress (Simplify by Error Factor Method) *****************************/
103
0e94c83d
RN
104static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} };
105
106VikLayerParam bfilter_compress_params[] = {
107 //{ 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 },
108 { VIK_LAYER_NUM_TYPES, "compressfactor", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Error Factor:"), VIK_LAYER_WIDGET_SPINBUTTON, compress_spin_scales, NULL,
109 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 },
110};
111
112VikLayerParamData bfilter_compress_params_defaults[] = {
113 /* Annoyingly 'C' cannot initialize unions properly */
114 /* It's dependent on the standard used or the compiler support... */
115#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__
116 { .d = 0.001 },
117#else
118 { 0.001 },
119#endif
120};
121
17acdaec
RN
122/**
123 * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html
124 */
125static void datasource_bfilter_compress_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
126{
127 gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' ';
128 // I toyed with making the length,crosstrack or relative methods selectable
129 // However several things:
130 // - 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
131 // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM
132 // - options make this more complicated to use - is even that useful to be allowed to change the error value?
133 // NB units not applicable if relative method used - defaults to Miles when not specified
3adb6827
RN
134 po->babelargs = g_strdup ( "-i gpx" );
135 po->filename = g_strdup ( input_filename );
136 po->babel_filters = g_strdup_printf ( "-x simplify,crosstrack,error=%-.5f%c", paramdatas[0].d, units );
17acdaec
RN
137}
138
4c853de9
RN
139#define VIK_SETTINGS_BFILTER_COMPRESS "bfilter_compress"
140static gboolean bfilter_compress_default_set = FALSE;
141
142static gpointer datasource_bfilter_compress_init ( acq_vik_t *not_used )
143{
144 if ( !bfilter_compress_default_set ) {
145 gdouble tmp;
146 if ( !a_settings_get_double ( VIK_SETTINGS_BFILTER_COMPRESS, &tmp ) )
147 tmp = 0.001;
148
149 bfilter_compress_params_defaults[0].d = tmp;
150 bfilter_compress_default_set = TRUE;
151 }
152
153 return NULL;
154}
155
0e94c83d
RN
156/**
157 * Allow 'compressing' tracks/routes using the Simplify by Error Factor method
158 */
159VikDataSourceInterface vik_datasource_bfilter_compress_interface = {
160 N_("Compress Tracks..."),
161 N_("Compressed Tracks"),
162 VIK_DATASOURCE_CREATENEWLAYER,
163 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
164 TRUE,
165 FALSE, // Close the dialog after successful operation
166 TRUE,
4c853de9
RN
167 (VikDataSourceInitFunc) datasource_bfilter_compress_init,
168 NULL, NULL,
17acdaec
RN
169 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_compress_get_process_options,
170 (VikDataSourceProcessFunc) a_babel_convert_from,
0e94c83d
RN
171 NULL, NULL, NULL,
172 (VikDataSourceOffFunc) NULL,
173
174 bfilter_compress_params,
175 sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]),
176 bfilter_compress_params_defaults,
177 NULL,
178 0
179};
180
40a8d1c2
EB
181/************************************ Duplicate Location ***********************************/
182
17acdaec
RN
183static void datasource_bfilter_dup_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
184{
3adb6827
RN
185 po->babelargs = g_strdup ( "-i gpx" );
186 po->filename = g_strdup ( input_filename );
187 po->babel_filters = g_strdup ( "-x duplicate,location" );
17acdaec 188}
40a8d1c2
EB
189
190VikDataSourceInterface vik_datasource_bfilter_dup_interface = {
4c77d5e0
GB
191 N_("Remove Duplicate Waypoints"),
192 N_("Remove Duplicate Waypoints"),
40a8d1c2
EB
193 VIK_DATASOURCE_CREATENEWLAYER,
194 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
d2525524 195 TRUE,
40a8d1c2 196 FALSE, /* keep dialog open after success */
b2aa700f 197 TRUE,
40a8d1c2 198 NULL, NULL, NULL,
17acdaec
RN
199 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_dup_get_process_options,
200 (VikDataSourceProcessFunc) a_babel_convert_from,
40a8d1c2 201 NULL, NULL, NULL,
2b756ea0 202 (VikDataSourceOffFunc) NULL,
40a8d1c2
EB
203
204 NULL, 0, NULL, NULL, 0
205};
206
207
f74395cc
RN
208/************************************ Swap Lat<->Lon ***********************************/
209
210VikLayerParamData bfilter_manual_params_defaults[] = {
211 { .s = NULL },
212};
213
214VikLayerParam bfilter_manual_params[] = {
215 { VIK_LAYER_NUM_TYPES, "manual", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Manual filter:"), VIK_LAYER_WIDGET_ENTRY, NULL, NULL,
216 N_("Manual filter command: e.g. 'swap'."), NULL, NULL, NULL },
217};
218
219static void datasource_bfilter_manual_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *not_used3 )
220{
221 po->babelargs = g_strdup ( "-i gpx" );
222 po->filename = g_strdup ( input_filename );
223 po->babel_filters = g_strconcat ( "-x ", paramdatas[0].s, NULL );
224}
225
226VikDataSourceInterface vik_datasource_bfilter_manual_interface = {
227 N_("Manual filter"),
228 N_("Manual filter"),
229 VIK_DATASOURCE_CREATENEWLAYER,
230 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
231 TRUE,
232 FALSE, /* keep dialog open after success */
233 TRUE,
234 NULL, NULL, NULL,
235 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_manual_get_process_options,
236 (VikDataSourceProcessFunc) a_babel_convert_from,
237 NULL, NULL, NULL,
238 (VikDataSourceOffFunc) NULL,
239
240 bfilter_manual_params,
241 sizeof(bfilter_manual_params)/sizeof(bfilter_manual_params[0]),
242 bfilter_manual_params_defaults,
243 NULL,
244 0
245};
246
40a8d1c2
EB
247/************************************ Polygon ***********************************/
248
17acdaec
RN
249static void datasource_bfilter_polygon_get_process_options ( VikLayerParamData *paramdatas, ProcessOptions *po, gpointer not_used, const gchar *input_filename, const gchar *input_track_filename )
250{
251 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 );
252}
40a8d1c2 253/* TODO: shell_escape stuff */
40a8d1c2
EB
254
255VikDataSourceInterface vik_datasource_bfilter_polygon_interface = {
4c77d5e0 256 N_("Waypoints Inside This"),
8a7788c9 257 N_("Polygonized Layer"),
40a8d1c2
EB
258 VIK_DATASOURCE_CREATENEWLAYER,
259 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
d2525524 260 TRUE,
40a8d1c2 261 FALSE, /* keep dialog open after success */
b2aa700f 262 TRUE,
40a8d1c2 263 NULL, NULL, NULL,
17acdaec
RN
264 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_polygon_get_process_options,
265 (VikDataSourceProcessFunc) a_babel_convert_from,
40a8d1c2 266 NULL, NULL, NULL,
2b756ea0 267 (VikDataSourceOffFunc) NULL,
40a8d1c2
EB
268
269 NULL,
270 0,
271 NULL,
272 NULL,
273 0
274};
275
17acdaec 276/************************************ Exclude Polygon ***********************************/
40a8d1c2 277
17acdaec 278static 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 279{
17acdaec 280 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 281}
40a8d1c2 282/* TODO: shell_escape stuff */
40a8d1c2
EB
283
284VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = {
4c77d5e0
GB
285 N_("Waypoints Outside This"),
286 N_("Polygonzied Layer"),
40a8d1c2
EB
287 VIK_DATASOURCE_CREATENEWLAYER,
288 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
d2525524 289 TRUE,
40a8d1c2 290 FALSE, /* keep dialog open after success */
b2aa700f 291 TRUE,
40a8d1c2 292 NULL, NULL, NULL,
17acdaec
RN
293 (VikDataSourceGetProcessOptionsFunc) datasource_bfilter_exclude_polygon_get_process_options,
294 (VikDataSourceProcessFunc) a_babel_convert_from,
40a8d1c2 295 NULL, NULL, NULL,
2b756ea0 296 (VikDataSourceOffFunc) NULL,
40a8d1c2
EB
297
298 NULL,
299 0,
300 NULL,
301 NULL,
302 0
303};