Module: Gpx2geojson
- Defined in:
- lib/gpx2geojson.rb,
lib/gpx2geojson/version.rb
Constant Summary collapse
- VERSION =
"1.0.0"
Class Method Summary collapse
Class Method Details
.parse(file_thing) ⇒ Object
5 6 7 8 |
# File 'lib/gpx2geojson.rb', line 5 def self.parse(file_thing) @gpx = file_thing || file_thing.tempfile parse_file end |
.parse_file ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gpx2geojson.rb', line 10 def self.parse_file data = @gpx.read file_mode = data =~ /trkpt/ ? "//trkpt" : (data =~ /rtept/ ? "//rtept" : "//wpt") geo_json = '{"type": "Feature", "geometry": {"type": "MultiLineString","coordinates": [[' Nokogiri.HTML(data).search(file_mode).each do |tp| geo_json += '[' + "#{tp[:lon].to_f}" + ", " + "#{tp[:lat].to_f}" + '], ' end geo_json = geo_json[0..-3] geo_json += ']]}}' geo_json end |