nofxx-georuby 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.1
1
+ 1.6.2
data/georuby.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{georuby}
8
- s.version = "1.6.1"
8
+ s.version = "1.6.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Guilhem Vellut", "Marcos Augusto"]
@@ -11,13 +11,14 @@ module GeoRuby
11
11
  include Enumerable
12
12
 
13
13
  # Opens a GPX file. Both "abc.shp" and "abc" are accepted.
14
- def initialize(file, with_z = true, with_m = true)
14
+ def initialize(file, *opts) #with_z = true, with_m = true)
15
15
  @file_root = file.gsub(/\.gpx$/i,"")
16
16
  raise MalformedGpxException.new("Missing GPX File") unless
17
17
  File.exists? @file_root + ".gpx"
18
18
  @points, @envelope = [], nil
19
19
  @gpx = File.open(@file_root + ".gpx", "rb")
20
- parse_file
20
+ opt = opts.inject({}) { |o, h| h.merge(o) }
21
+ parse_file(opt[:with_z], opt[:with_m])
21
22
  end
22
23
 
23
24
  #force the reopening of the files compsing the shp. Close before calling this.
@@ -26,8 +27,8 @@ module GeoRuby
26
27
  end
27
28
 
28
29
  #opens a GPX "file". If a block is given, the GpxFile object is yielded to it and is closed upon return. Else a call to <tt>open</tt> is equivalent to <tt>GpxFile.new(...)</tt>.
29
- def self.open(file)
30
- gpxfile = GpxFile.new(file)
30
+ def self.open(file, *opts)
31
+ gpxfile = GpxFile.new(file, *opts)
31
32
  if block_given?
32
33
  yield gpxfile
33
34
  gpxfile.close
@@ -91,12 +92,13 @@ module GeoRuby
91
92
  # wpt => waypoint => TODO?
92
93
  # rte(pt) => route
93
94
  # trk(pt) => track /
94
- def parse_file(parse_time=true)
95
+ def parse_file(with_z, with_m)
95
96
  data = @gpx.read
96
97
  @file_mode = data =~ /trkpt/ ? "//trkpt" : "//rtept"
97
98
  Nokogiri.HTML(data).search(@file_mode).each do |tp|
98
- time = time.inner_text if parse_time && time = tp.at("time")
99
- @points << Point.from_x_y_z_m(tp["lon"].to_f, tp["lat"].to_f, tp.at("ele").inner_text.to_i, time)
99
+ z = z.inner_text.to_i if with_z && z = tp.at("ele")
100
+ m = m.inner_text if with_m && m = tp.at("time")
101
+ @points << Point.from_coordinates([tp["lon"].to_f, tp["lat"].to_f, z, m],nil,with_z, with_m)
100
102
  end
101
103
  close
102
104
  @record_count = @points.length
@@ -15,9 +15,9 @@ describe Gpx4r do
15
15
  describe "Waypoints" do
16
16
 
17
17
  before(:all) do
18
- @gpxfile = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/short.gpx')
19
- @gpxfile2 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/fells_loop')
20
- @gpxfile3 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/tracktreks.gpx')
18
+ @gpxfile = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/short.gpx', :with_z => true, :with_m => true)
19
+ @gpxfile2 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/fells_loop', :with_z => true, :with_m => true)
20
+ @gpxfile3 = GpxFile.open(File.dirname(__FILE__) + '/../../data/gpx/tracktreks.gpx', :with_z => true)
21
21
  end
22
22
 
23
23
  it "should open and parse" do
@@ -59,7 +59,7 @@ describe Gpx4r do
59
59
 
60
60
  it "should read Z and M 3" do
61
61
  @gpxfile3[0].z.should eql(88)
62
- @gpxfile3[0].m.should be_nil
62
+ @gpxfile3[0].m.should eql(0.0)
63
63
  end
64
64
 
65
65
  it "should return it as a linestring" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nofxx-georuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilhem Vellut