Sha256: 538ad30a87895702e32d64ec7922d20d010c3e240b2097aeb60f2388db6ee7ed

Contents?: true

Size: 615 Bytes

Versions: 1

Compression:

Stored size: 615 Bytes

Contents

require "gpx2geojson/version"
require "nokogiri"

module Gpx2geojson
  def self.parse(file_thing)
    @gpx = file_thing || file_thing.tempfile
    parse_file
  end

  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gpx2geojson-1.0.0 lib/gpx2geojson.rb