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