]> git.street.me.uk Git - andy/viking.git/blob - src/datasource_bfilter.c
Fix drawing of copied MBTiles map layers.
[andy/viking.git] / src / datasource_bfilter.c
1 /*
2  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
3  *
4  * Copyright (C) 2003-2007, Evan Battaglia <gtoevan@gmx.net>
5  * Copyright (C) 2014, Rob Norris <rw_norris@hotmail.com>
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  *
21  * See: http://www.gpsbabel.org/htmldoc-development/Data_Filters.html
22  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include <string.h>
27 #include <glib/gi18n.h>
28
29 #include "viking.h"
30 #include "babel.h"
31 #include "gpx.h"
32 #include "acquire.h"
33
34 /************************************ Simplify (Count) *****************************/
35
36 static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used );
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[] = {
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 },
48 };
49
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__
54   { .i = 100 },
55 #else
56   { 100 },
57 #endif
58 };
59
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,
65   TRUE,
66   FALSE, /* keep dialog open after success */
67   TRUE,
68   NULL, NULL, NULL,
69   (VikDataSourceGetCmdStringFunc)       datasource_bfilter_simplify_get_cmd_string,
70   (VikDataSourceProcessFunc)        a_babel_convert_from_shellcommand,
71   NULL, NULL, NULL,
72   (VikDataSourceOffFunc) NULL,
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
82 static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used )
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
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
152 /************************************ Duplicate Location ***********************************/
153
154 static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used );
155
156 /* TODO: shell_escape stuff */
157 /* TODO: name is useless for filters */
158
159
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,
165   TRUE,
166   FALSE, /* keep dialog open after success */
167   TRUE,
168   NULL, NULL, NULL,
169   (VikDataSourceGetCmdStringFunc)       datasource_bfilter_dup_get_cmd_string,
170   (VikDataSourceProcessFunc)        a_babel_convert_from_shellcommand,
171   NULL, NULL, NULL,
172   (VikDataSourceOffFunc) NULL,
173
174   NULL, 0, NULL, NULL, 0
175 };
176
177
178 static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used )
179 {
180   *input_file_type = NULL;
181   *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename );
182 }
183
184
185 /************************************ Polygon ***********************************/
186
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 );
188
189 /* TODO: shell_escape stuff */
190 /* TODO: name is useless for filters */
191
192
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,
198   TRUE,
199   FALSE, /* keep dialog open after success */
200   TRUE,
201   NULL, NULL, NULL,
202   (VikDataSourceGetCmdStringFunc)       datasource_bfilter_polygon_get_cmd_string,
203   (VikDataSourceProcessFunc)        a_babel_convert_from_shellcommand,
204   NULL, NULL, NULL,
205   (VikDataSourceOffFunc) NULL,
206
207   NULL,
208   0,
209   NULL,
210   NULL,
211   0
212 };
213
214
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 )
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
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 );
224
225 /* TODO: shell_escape stuff */
226 /* TODO: name is useless for filters */
227
228
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,
234   TRUE,
235   FALSE, /* keep dialog open after success */
236   TRUE,
237   NULL, NULL, NULL,
238   (VikDataSourceGetCmdStringFunc)       datasource_bfilter_exclude_polygon_get_cmd_string,
239   (VikDataSourceProcessFunc)        a_babel_convert_from_shellcommand,
240   NULL, NULL, NULL,
241   (VikDataSourceOffFunc) NULL,
242
243   NULL,
244   0,
245   NULL,
246   NULL,
247   0
248 };
249
250
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 )
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