You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
6.1KB

  1. /*
  2. Discard points based on high Degree of Precision (DOP) values.
  3. Copyright (C) 2005-2014 Robert Lipe, robertlipe+source@gpsbabel.org
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  15. */
  16. #include "defs.h"
  17. #include "filterdefs.h"
  18. #include <stdlib.h>
  19. // Can't use QRegularExpression because Linux won't get Qt 5 for years.
  20. #include <QtCore/QRegExp>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #if FILTERS_ENABLED
  24. static char* hdopopt = NULL;
  25. static char* vdopopt = NULL;
  26. static char* andopt = NULL;
  27. static char* satopt = NULL;
  28. static char* fixnoneopt = NULL;
  29. static char* fixunknownopt = NULL;
  30. static char* eleminopt = NULL;
  31. static char* elemaxopt = NULL;
  32. static char* nameopt = NULL;
  33. static QRegExp name_regex;
  34. static char* descopt = NULL;
  35. static QRegExp desc_regex;
  36. static char* cmtopt = NULL;
  37. static QRegExp cmt_regex;
  38. static char* iconopt = NULL;
  39. static QRegExp icon_regex;
  40. static double hdopf;
  41. static double vdopf;
  42. static int satpf;
  43. static int eleminpf;
  44. static int elemaxpf;
  45. static gpsdata_type what;
  46. static route_head* head;
  47. static
  48. arglist_t fix_args[] = {
  49. {
  50. "hdop", &hdopopt, "Suppress points with higher hdop",
  51. "-1.0", ARGTYPE_BEGIN_REQ | ARGTYPE_FLOAT, ARG_NOMINMAX
  52. },
  53. {
  54. "vdop", &vdopopt, "Suppress points with higher vdop",
  55. "-1.0", ARGTYPE_END_REQ | ARGTYPE_FLOAT, ARG_NOMINMAX
  56. },
  57. {
  58. "hdopandvdop", &andopt, "Link hdop and vdop supression with AND",
  59. NULL, ARGTYPE_BOOL, ARG_NOMINMAX
  60. },
  61. {
  62. "sat", &satopt, "Minimium sats to keep points",
  63. "-1.0", ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
  64. },
  65. {
  66. "fixnone", &fixnoneopt, "Suppress points without fix",
  67. NULL, ARGTYPE_BOOL, ARG_NOMINMAX
  68. },
  69. {
  70. "fixunknown", &fixunknownopt, "Suppress points with unknown fix",
  71. NULL, ARGTYPE_BOOL, ARG_NOMINMAX
  72. },
  73. {
  74. "elemin", &eleminopt, "Suppress points below given elevation in meters",
  75. NULL, ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
  76. },
  77. {
  78. "elemax", &elemaxopt, "Suppress points above given elevation in meters",
  79. NULL, ARGTYPE_BEGIN_REQ | ARGTYPE_INT, ARG_NOMINMAX
  80. },
  81. {
  82. "matchname", &nameopt,
  83. "Suppress points where name matches given name", NULL, ARGTYPE_STRING,
  84. ARG_NOMINMAX, NULL
  85. },
  86. {
  87. "matchdesc", &descopt,
  88. "Suppress points where description matches given name", NULL, ARGTYPE_STRING,
  89. ARG_NOMINMAX, NULL
  90. },
  91. {
  92. "matchcmt", &cmtopt,
  93. "Suppress points where comment matches given name", NULL, ARGTYPE_STRING,
  94. ARG_NOMINMAX, NULL
  95. },
  96. {
  97. "matchicon", &iconopt,
  98. "Suppress points where type matches given name", NULL, ARGTYPE_STRING,
  99. ARG_NOMINMAX, NULL
  100. },
  101. ARG_TERMINATOR
  102. };
  103. /*
  104. * Decide whether to keep or toss this point.
  105. */
  106. static void
  107. fix_process_wpt(const Waypoint* wpt)
  108. {
  109. int del = 0;
  110. int delh = 0;
  111. int delv = 0;
  112. Waypoint* waypointp = (Waypoint*) wpt;
  113. if ((hdopf >= 0.0) && (waypointp->hdop > hdopf)) {
  114. delh = 1;
  115. }
  116. if ((vdopf >= 0.0) && (waypointp->vdop > vdopf)) {
  117. delv = 1;
  118. }
  119. if (andopt) {
  120. del = delh && delv;
  121. } else {
  122. del = delh || delv;
  123. }
  124. if ((satpf >= 0) && (waypointp->sat < satpf)) {
  125. del = 1;
  126. }
  127. if ((fixnoneopt) && (waypointp->fix == fix_none)) {
  128. del = 1;
  129. }
  130. if ((fixunknownopt) && (waypointp->fix == fix_unknown)) {
  131. del = 1;
  132. }
  133. if ((eleminopt) && (waypointp->altitude < eleminpf)) {
  134. del = 1;
  135. }
  136. if ((elemaxopt) && (waypointp->altitude > elemaxpf)) {
  137. del = 1;
  138. }
  139. if (nameopt && name_regex.indexIn(waypointp->shortname) >= 0) {
  140. del = 1;
  141. }
  142. if (descopt && desc_regex.indexIn(waypointp->description) >= 0) {
  143. del = 1;
  144. }
  145. if (cmtopt && cmt_regex.indexIn(waypointp->notes) >= 0) {
  146. del = 1;
  147. }
  148. if (iconopt && icon_regex.indexIn(waypointp->icon_descr) >= 0) {
  149. del = 1;
  150. }
  151. if (del) {
  152. switch (what) {
  153. case wptdata:
  154. waypt_del(waypointp);
  155. break;
  156. case trkdata:
  157. track_del_wpt(head, waypointp);
  158. break;
  159. case rtedata:
  160. route_del_wpt(head, waypointp);
  161. break;
  162. default:
  163. return;
  164. }
  165. delete waypointp;
  166. }
  167. }
  168. static void
  169. fix_process_head(const route_head* trk)
  170. {
  171. head = (route_head*)trk;
  172. }
  173. static void
  174. fix_process(void)
  175. {
  176. // Filter waypoints.
  177. what = wptdata;
  178. waypt_disp_all(fix_process_wpt);
  179. // Filter tracks
  180. what = trkdata;
  181. track_disp_all(fix_process_head, NULL, fix_process_wpt);
  182. // And routes
  183. what = rtedata;
  184. route_disp_all(fix_process_head, NULL, fix_process_wpt);
  185. }
  186. static void
  187. fix_init(const char* args)
  188. {
  189. if (hdopopt) {
  190. hdopf = atof(hdopopt);
  191. } else {
  192. hdopf = -1.0;
  193. }
  194. if (vdopopt) {
  195. vdopf = atof(vdopopt);
  196. } else {
  197. vdopf = -1.0;
  198. }
  199. if (satopt) {
  200. satpf = atoi(satopt);
  201. } else {
  202. satpf = -1;
  203. }
  204. if (eleminopt) {
  205. eleminpf = atoi(eleminopt);
  206. }
  207. if (elemaxopt) {
  208. elemaxpf = atoi(elemaxopt);
  209. }
  210. if (nameopt) {
  211. name_regex.setCaseSensitivity(Qt::CaseInsensitive);
  212. name_regex.setPatternSyntax(QRegExp::WildcardUnix);
  213. name_regex.setPattern(nameopt);
  214. }
  215. if (descopt) {
  216. desc_regex.setCaseSensitivity(Qt::CaseInsensitive);
  217. desc_regex.setPatternSyntax(QRegExp::WildcardUnix);
  218. desc_regex.setPattern(descopt);
  219. }
  220. if (cmtopt) {
  221. cmt_regex.setCaseSensitivity(Qt::CaseInsensitive);
  222. cmt_regex.setPatternSyntax(QRegExp::WildcardUnix);
  223. cmt_regex.setPattern(cmtopt);
  224. }
  225. if (iconopt) {
  226. icon_regex.setCaseSensitivity(Qt::CaseInsensitive);
  227. icon_regex.setPatternSyntax(QRegExp::WildcardUnix);
  228. icon_regex.setPattern(iconopt);
  229. }
  230. }
  231. filter_vecs_t discard_vecs = {
  232. fix_init,
  233. fix_process,
  234. NULL,
  235. NULL,
  236. fix_args
  237. };
  238. #endif