2 * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4 * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net>
5 * Copyright (C) 2014, 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>
34 /************************************ Simplify (Count) *****************************/
36 static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used );
38 /* TODO: shell_escape stuff */
39 /* TODO: name is useless for filters */
41 /* spin button scales */
42 VikLayerParamScale simplify_params_scales[] = {
46 VikLayerParam bfilter_simplify_params[] = {
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 },
50 VikLayerParamData bfilter_simplify_params_defaults[] = {
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__
60 VikDataSourceInterface vik_datasource_bfilter_simplify_interface = {
61 N_("Simplify All Tracks..."),
62 N_("Simplified Tracks"),
63 VIK_DATASOURCE_CREATENEWLAYER,
64 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
66 FALSE, /* keep dialog open after success */
69 (VikDataSourceGetCmdStringFunc) datasource_bfilter_simplify_get_cmd_string,
70 (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand,
72 (VikDataSourceOffFunc) NULL,
74 bfilter_simplify_params,
75 sizeof(bfilter_simplify_params)/sizeof(bfilter_simplify_params[0]),
76 bfilter_simplify_params_defaults,
82 static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used )
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 );
88 /**************************** Compress (Simplify by Error Factor Method) *****************************/
90 static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used );
92 /* TODO: shell_escape stuff */
94 static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} };
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 },
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__
113 * Allow 'compressing' tracks/routes using the Simplify by Error Factor method
115 VikDataSourceInterface vik_datasource_bfilter_compress_interface = {
116 N_("Compress Tracks..."),
117 N_("Compressed Tracks"),
118 VIK_DATASOURCE_CREATENEWLAYER,
119 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
121 FALSE, // Close the dialog after successful operation
124 (VikDataSourceGetCmdStringFunc) datasource_bfilter_compress_get_cmd_string,
125 (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand,
127 (VikDataSourceOffFunc) NULL,
129 bfilter_compress_params,
130 sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]),
131 bfilter_compress_params_defaults,
137 * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html
139 static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used )
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 );
152 /************************************ Duplicate Location ***********************************/
154 static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used );
156 /* TODO: shell_escape stuff */
157 /* TODO: name is useless for filters */
160 VikDataSourceInterface vik_datasource_bfilter_dup_interface = {
161 N_("Remove Duplicate Waypoints"),
162 N_("Remove Duplicate Waypoints"),
163 VIK_DATASOURCE_CREATENEWLAYER,
164 VIK_DATASOURCE_INPUTTYPE_TRWLAYER,
166 FALSE, /* keep dialog open after success */
169 (VikDataSourceGetCmdStringFunc) datasource_bfilter_dup_get_cmd_string,
170 (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand,
172 (VikDataSourceOffFunc) NULL,
174 NULL, 0, NULL, NULL, 0
178 static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used )
180 *input_file_type = NULL;
181 *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename );
185 /************************************ Polygon ***********************************/
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 );
189 /* TODO: shell_escape stuff */
190 /* TODO: name is useless for filters */
193 VikDataSourceInterface vik_datasource_bfilter_polygon_interface = {
194 N_("Waypoints Inside This"),
195 N_("Polygonized Layer"),
196 VIK_DATASOURCE_CREATENEWLAYER,
197 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
199 FALSE, /* keep dialog open after success */
202 (VikDataSourceGetCmdStringFunc) datasource_bfilter_polygon_get_cmd_string,
203 (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand,
205 (VikDataSourceOffFunc) NULL,
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 )
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 );
221 /************************************ Exclude Polygon ***********************************/
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 );
225 /* TODO: shell_escape stuff */
226 /* TODO: name is useless for filters */
229 VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = {
230 N_("Waypoints Outside This"),
231 N_("Polygonzied Layer"),
232 VIK_DATASOURCE_CREATENEWLAYER,
233 VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK,
235 FALSE, /* keep dialog open after success */
238 (VikDataSourceGetCmdStringFunc) datasource_bfilter_exclude_polygon_get_cmd_string,
239 (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand,
241 (VikDataSourceOffFunc) NULL,
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 )
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 );