gpx_doctor 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62f11c008dcbf53c4585d1cc1d4935555ddecbfc98ce4db4f0141476f2847ce3
4
- data.tar.gz: ebf37bed3a22db9e84a6a0d1b593f2e3f9e9bf0146f114a06d8b900cc2e853f8
3
+ metadata.gz: c13f7a8d06c283b5a8dba624cced9d7244d60f2720918b495f35cf96ce8ae1e3
4
+ data.tar.gz: 4237a5927878077f57a7912e8cd61ec7d2300e31551890e653840aca9197049c
5
5
  SHA512:
6
- metadata.gz: b096d0f32832c3ecd0147bd5b6066dd18f1fd19233af68101d486b5a4895febb2228da30fd907b849436a1feaca98bc707cfd2a0963b05b0587962d11a803f85
7
- data.tar.gz: 5cf20d498a2247483904a86ca637bff0cc527bafe74f7c312d869694ef05fa798f675940f536980240eab12a90034bed42e841bcc6056bf43fb5505484baddc8
6
+ metadata.gz: 9841a014b0a980fd3c980ad92cb6ad04affb45eb711058bca7575967086bf2edeb311833ed5117233c379a80c5616ee0c15ec1cecf3eef15c8d40ed2c6450cc8
7
+ data.tar.gz: e022a619a37fb50308ed5414644c8c82cc4e70cacc6b30c06a588718e70c71d54f56e1f49b953fb2875a628399cc50dde6424037da8760f88066db3079f26566
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GPX Doctor
2
2
 
3
- A Ruby gem for parsing and manipulating GPX 1.1 routes.
3
+ A Ruby gem for parsing and manipulating GPX routes. The parser reads GPX 1.1 and GPX 1.0 (`http://www.topografix.com/GPX/1/0`, e.g. Traseo and older RideWithGPS exports); the builder always writes GPX 1.1.
4
4
 
5
5
  ## Installation
6
6
 
@@ -116,19 +116,28 @@ Processing is applied in the following order:
116
116
  ## Accessing data
117
117
 
118
118
  ```ruby
119
- result.points # => [#<Waypoint lat=…, lon=…, ele=…>, …] (all geographic points)
120
- result.waypoints # => [#<Waypoint …>] (top-level <wpt> elements only)
121
- result.routes # => [#<Route …>]
122
- result.tracks # => [#<Track …>]
123
- result.metadata # => #<Metadata …> (or nil)
124
- result.pois # => Hash (only when parsed with full_poi_data: true, otherwise nil)
119
+ result.points # => [#<Waypoint lat=…, lon=…, ele=…>, …] (the path)
120
+ result.all_points # => [#<Waypoint …>, …] (the path plus standalone waypoints)
121
+ result.waypoints # => [#<Waypoint …>] (top-level <wpt> elements only)
122
+ result.routes # => [#<Route …>]
123
+ result.tracks # => [#<Track …>]
124
+ result.metadata # => #<Metadata …> (or nil)
125
+ result.pois # => Hash (only when parsed with full_poi_data: true, otherwise nil)
125
126
  ```
126
127
 
127
- `result.points` is a flat array containing **all** geographic points from:
128
- - Top-level `<wpt>` elements
128
+ `result.points` is a flat array describing **the path**, in order:
129
129
  - `<rtept>` elements inside each `<rte>`
130
130
  - `<trkpt>` elements inside each `<trkseg>` inside each `<trk>`
131
131
 
132
+ Top-level `<wpt>` elements are **not** included. They are points of interest that may
133
+ sit anywhere on — or off — the path, and exporters list them in file order rather than
134
+ path order, so treating them as path points draws straight lines back and forth across
135
+ the map. Read them from `result.waypoints`, or use `result.all_points` (standalone
136
+ waypoints first, then the path) when you genuinely want every geographic point in the
137
+ file. All processing params (`max_points`, `cumulative_distance`, `label_interval`,
138
+ `segment_statistics`, `full_poi_data`) operate on the path only; `enhance_elevation` is
139
+ the exception and fills in elevations for standalone waypoints too.
140
+
132
141
  ### `result.pois`
133
142
 
134
143
  When parsed with `full_poi_data: true`, `result.pois` contains boundary data for the entire GPX and each track segment:
@@ -6,10 +6,32 @@ require 'time'
6
6
  module GpxDoctor
7
7
  class Parser
8
8
  GPX_NS = 'http://www.topografix.com/GPX/1/1'
9
+ GPX_10_NS = 'http://www.topografix.com/GPX/1/0'
10
+ # Validator accepts both versions, so the parser must read both. Element
11
+ # names used here (wpt, rte, trk, trkseg, trkpt, ele, time, name) are the
12
+ # same in 1.0 and 1.1 — only the namespace differs.
13
+ GPX_NAMESPACES = [GPX_NS, GPX_10_NS].freeze
9
14
 
10
15
  Result = Struct.new(:waypoints, :routes, :tracks, :metadata, :pois, keyword_init: true) do
16
+ # The path described by the file, in order: <rtept> then <trkpt>.
17
+ #
18
+ # Standalone <wpt> elements are deliberately NOT part of it. They are
19
+ # points of interest scattered anywhere on (or off) the path — exporters
20
+ # such as komoot emit them for highlights like bridges or churches — so
21
+ # folding them in front of the path turns a valid route into a zig-zag of
22
+ # straight lines back and forth across the whole map. Every other stage of
23
+ # the gem (split_segments, select_max_points, enhance_statistics,
24
+ # enhance_cumulative_distance, label_points, build_pois) already walks
25
+ # routes and track segments only; this makes #points agree with them.
26
+ #
27
+ # Use #all_points for every geographic point in the file, waypoints included.
11
28
  def points
12
- waypoints + routes.flat_map(&:points) + tracks.flat_map(&:points)
29
+ routes.flat_map(&:points) + tracks.flat_map(&:points)
30
+ end
31
+
32
+ # Every geographic point in the file: standalone waypoints followed by the path.
33
+ def all_points
34
+ waypoints + points
13
35
  end
14
36
  end
15
37
 
@@ -31,7 +53,7 @@ module GpxDoctor
31
53
 
32
54
  def detect_namespace(doc)
33
55
  root_ns = doc.root&.namespace&.href
34
- root_ns == GPX_NS ? GPX_NS : nil
56
+ GPX_NAMESPACES.include?(root_ns) ? root_ns : nil
35
57
  end
36
58
  end
37
59
 
@@ -224,7 +246,9 @@ module GpxDoctor
224
246
  config = GpxDoctor.configuration
225
247
  return unless config.elevation_server && config.elevation_server_url
226
248
 
227
- ElevationClient.new.enhance(result.points)
249
+ # all_points, not points: standalone waypoints are POIs the caller still
250
+ # wants an elevation for, even though they are not part of the path.
251
+ ElevationClient.new.enhance(result.all_points)
228
252
  end
229
253
 
230
254
  def effective_max_distance(result)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GpxDoctor
4
- VERSION = '0.6.1'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx_doctor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Poltrax