Skip to content

Commit 0e9a694

Browse files
committed
convert each linestring to a track, not a segment
1 parent 82e4f2a commit 0e9a694

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

lib/gpx/geo_json.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def parse_geojson_data(data)
6262
end
6363

6464
def add_tracks_to(gpx_file, geojson, opts)
65-
tracks = [line_strings_to_track(geojson, opts)] +
65+
tracks = line_strings_to_track(geojson, opts) +
6666
multi_line_strings_to_tracks(geojson, opts)
6767
tracks.compact!
6868
gpx_file.tracks += tracks
@@ -83,6 +83,28 @@ def line_strings_to_track(geojson, opts)
8383
line_strings = line_strings_in(geojson)
8484
return nil unless line_strings.any?
8585

86+
tracks = []
87+
88+
line_strings.each do |ls|
89+
track = GPX::Track.new
90+
coords = ls['geometry']['coordinates']
91+
segment = coords_to_segment(coords)
92+
93+
opts[:line_string_feature_to_segment]&.call(ls, segment)
94+
track.append_segment(segment)
95+
tracks << track
96+
end
97+
tracks
98+
end
99+
100+
# Converts GeoJSON 'LineString' features.
101+
# Current strategy is to convert each LineString into a
102+
# Track Segment, returning a Track for all LineStrings.
103+
#
104+
def line_strings_to_track_segment(geojson, opts)
105+
line_strings = line_strings_in(geojson)
106+
return nil unless line_strings.any?
107+
86108
track = GPX::Track.new
87109
line_strings.each do |ls|
88110
coords = ls['geometry']['coordinates']

0 commit comments

Comments
 (0)