X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/b0fcb409d4bbd8243676f3e520e505fc68343351..0a25e23214e753d9190e33e58b23685783099bd5:/src/datasource_bfilter.c diff --git a/src/datasource_bfilter.c b/src/datasource_bfilter.c index 453eb182..9b61cc7b 100644 --- a/src/datasource_bfilter.c +++ b/src/datasource_bfilter.c @@ -1,7 +1,8 @@ /* * viking -- GPS Data and Topo Analyzer, Explorer, and Manager * - * Copyright (C) 2003-2005, Evan Battaglia + * Copyright (C) 2003-2007, Evan Battaglia + * Copyright (C) 2014, Rob Norris * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,6 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * See: http://www.gpsbabel.org/htmldoc-development/Data_Filters.html */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -29,10 +31,9 @@ #include "gpx.h" #include "acquire.h" +/************************************ Simplify (Count) *****************************/ -/************************************ Simplify ***********************************/ - -static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename ); +static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); /* TODO: shell_escape stuff */ /* TODO: name is useless for filters */ @@ -43,22 +44,30 @@ VikLayerParamScale simplify_params_scales[] = { }; VikLayerParam bfilter_simplify_params[] = { - { "numberofpoints", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Max number of points:"), VIK_LAYER_WIDGET_SPINBUTTON, simplify_params_scales + 0 }, + { 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 }, }; VikLayerParamData bfilter_simplify_params_defaults[] = { + /* Annoyingly 'C' cannot initialize unions properly */ + /* It's dependent on the standard used or the compiler support... */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ + { .i = 100 }, +#else { 100 }, +#endif }; VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { - N_("Simplify All Tracks"), + N_("Simplify All Tracks..."), N_("Simplified Tracks"), - VIK_DATASOURCE_SHELL_CMD, VIK_DATASOURCE_CREATENEWLAYER, VIK_DATASOURCE_INPUTTYPE_TRWLAYER, + TRUE, FALSE, /* keep dialog open after success */ + TRUE, NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_simplify_get_cmd_string, + (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -70,15 +79,79 @@ VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { }; -static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename ) +static void datasource_bfilter_simplify_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) { *input_file_type = NULL; *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,count=%d -o gpx -F -", input_filename, paramdatas[0].u ); } +/**************************** Compress (Simplify by Error Factor Method) *****************************/ + +static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); + +/* TODO: shell_escape stuff */ + +static VikLayerParamScale compress_spin_scales[] = { {0.0, 1.000, 0.001, 3} }; + +VikLayerParam bfilter_compress_params[] = { + //{ 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 }, + { VIK_LAYER_NUM_TYPES, "compressfactor", VIK_LAYER_PARAM_DOUBLE, VIK_LAYER_GROUP_NONE, N_("Error Factor:"), VIK_LAYER_WIDGET_SPINBUTTON, compress_spin_scales, NULL, + 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 }, +}; + +VikLayerParamData bfilter_compress_params_defaults[] = { + /* Annoyingly 'C' cannot initialize unions properly */ + /* It's dependent on the standard used or the compiler support... */ +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L || __GNUC__ + { .d = 0.001 }, +#else + { 0.001 }, +#endif +}; + +/** + * Allow 'compressing' tracks/routes using the Simplify by Error Factor method + */ +VikDataSourceInterface vik_datasource_bfilter_compress_interface = { + N_("Compress Tracks..."), + N_("Compressed Tracks"), + VIK_DATASOURCE_CREATENEWLAYER, + VIK_DATASOURCE_INPUTTYPE_TRWLAYER, + TRUE, + FALSE, // Close the dialog after successful operation + TRUE, + NULL, NULL, NULL, + (VikDataSourceGetCmdStringFunc) datasource_bfilter_compress_get_cmd_string, + (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, + NULL, NULL, NULL, + (VikDataSourceOffFunc) NULL, + + bfilter_compress_params, + sizeof(bfilter_compress_params)/sizeof(bfilter_compress_params[0]), + bfilter_compress_params_defaults, + NULL, + 0 +}; + +/** + * http://www.gpsbabel.org/htmldoc-development/filter_simplify.html + */ +static void datasource_bfilter_compress_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) +{ + *input_file_type = NULL; + gchar units = a_vik_get_units_distance() == VIK_UNITS_DISTANCE_KILOMETRES ? 'k' : ' '; + // I toyed with making the length,crosstrack or relative methods selectable + // However several things: + // - 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 + // - also using relative method fails when track doesn't have HDOP info - error reported to stderr - which we don't capture ATM + // - options make this more complicated to use - is even that useful to be allowed to change the error value? + // NB units not applicable if relative method used - defaults to Miles when not specified + *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x simplify,crosstrack,error=%-.5f%c -o gpx -F -", input_filename, paramdatas[0].d, units ); +} + /************************************ Duplicate Location ***********************************/ -static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename ); +static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ); /* TODO: shell_escape stuff */ /* TODO: name is useless for filters */ @@ -87,12 +160,14 @@ static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdata VikDataSourceInterface vik_datasource_bfilter_dup_interface = { N_("Remove Duplicate Waypoints"), N_("Remove Duplicate Waypoints"), - VIK_DATASOURCE_SHELL_CMD, VIK_DATASOURCE_CREATENEWLAYER, VIK_DATASOURCE_INPUTTYPE_TRWLAYER, + TRUE, FALSE, /* keep dialog open after success */ + TRUE, NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_dup_get_cmd_string, + (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -100,7 +175,7 @@ VikDataSourceInterface vik_datasource_bfilter_dup_interface = { }; -static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename ) +static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdatas, gchar **cmd, gchar **input_file_type, const gchar *input_filename, gpointer not_used ) { *input_file_type = NULL; *cmd = g_strdup_printf ( "gpsbabel -i gpx -f %s -x duplicate,location -o gpx -F -", input_filename ); @@ -109,7 +184,7 @@ static void datasource_bfilter_dup_get_cmd_string ( VikLayerParamData *paramdata /************************************ Polygon ***********************************/ -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 ); +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 ); /* TODO: shell_escape stuff */ /* TODO: name is useless for filters */ @@ -118,12 +193,14 @@ static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *param VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { N_("Waypoints Inside This"), N_("Polygonized Layer"), - VIK_DATASOURCE_SHELL_CMD, VIK_DATASOURCE_CREATENEWLAYER, VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, + TRUE, FALSE, /* keep dialog open after success */ + TRUE, NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_polygon_get_cmd_string, + (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -135,7 +212,7 @@ VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { }; -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 ) +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 ) { *input_file_type = NULL; *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 ); @@ -143,7 +220,7 @@ static void datasource_bfilter_polygon_get_cmd_string ( VikLayerParamData *param /************************************ Exclude Polygon ***********************************/ -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 ); +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 ); /* TODO: shell_escape stuff */ /* TODO: name is useless for filters */ @@ -152,12 +229,14 @@ static void datasource_bfilter_exclude_polygon_get_cmd_string ( VikLayerParamDat VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { N_("Waypoints Outside This"), N_("Polygonzied Layer"), - VIK_DATASOURCE_SHELL_CMD, VIK_DATASOURCE_CREATENEWLAYER, VIK_DATASOURCE_INPUTTYPE_TRWLAYER_TRACK, + TRUE, FALSE, /* keep dialog open after success */ + TRUE, NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_exclude_polygon_get_cmd_string, + (VikDataSourceProcessFunc) a_babel_convert_from_shellcommand, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -169,7 +248,7 @@ VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { }; -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 ) +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 ) { *input_file_type = NULL; *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 );