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 +1 -1
- data/georuby.gemspec +1 -1
- data/lib/geo_ruby/gpx4r/gpx.rb +9 -7
- data/spec/geo_ruby/gpx4r/gpx_spec.rb +4 -4
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.6.
|
1
|
+
1.6.2
|
data/georuby.gemspec
CHANGED
data/lib/geo_ruby/gpx4r/gpx.rb
CHANGED
@@ -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
|
-
|
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(
|
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
|
-
|
99
|
-
|
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
|
62
|
+
@gpxfile3[0].m.should eql(0.0)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should return it as a linestring" do
|