From 56a03f2c8b0e6e59c63937b7183b07426618dd11 Mon Sep 17 00:00:00 2001 From: Leo Roos Date: Mon, 11 May 2015 21:02:40 -0700 Subject: [PATCH] fix gpx file parsing `to_polygon` always closes the list of parsed GPX points inside the GPXFile object. Since it is used while parsing the GPX file it always resulted in a closed list of GPX points even if that was not the case. --- lib/geo_ruby/gpx.rb | 2 +- spec/geo_ruby/gpx_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/geo_ruby/gpx.rb b/lib/geo_ruby/gpx.rb index 10a1a26..7594ff5 100644 --- a/lib/geo_ruby/gpx.rb +++ b/lib/geo_ruby/gpx.rb @@ -73,7 +73,7 @@ def as_line_string # If the GPX isn't closed, a line from the first # to the last point will be created to close it. def as_polygon - GeoRuby::SimpleFeatures::Polygon.from_points([@points[0] == @points[-1] ? @points : @points.push(@points[0].clone)]) + GeoRuby::SimpleFeatures::Polygon.from_points([@points[0] == @points[-1] ? @points : (@points + [@points[0].clone])]) end # Return GPX Envelope diff --git a/spec/geo_ruby/gpx_spec.rb b/spec/geo_ruby/gpx_spec.rb index fbe6753..eeeea93 100644 --- a/spec/geo_ruby/gpx_spec.rb +++ b/spec/geo_ruby/gpx_spec.rb @@ -34,6 +34,11 @@ expect(@gpxfile[0].y).to be_within(0.0001).of(48.731813) end + it 'should point last record to last waypoint' do + expect(@gpxfile[-1].x).to be_within(0.0001).of(9.09436) + expect(@gpxfile[-1].y).to be_within(0.0001).of(48.731805) + end + it 'should read Z and M' do expect(@gpxfile[0].z).to eql(468.0) expect(@gpxfile[0].m).to eql('2008-09-07T17:36:57Z')