gpx2geojson 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +3 -0
- data/gpx2geojson.gemspec +26 -0
- data/lib/gpx2geojson.rb +25 -0
- data/lib/gpx2geojson/version.rb +3 -0
- data/spec/fixtures/elevator_shaft_garmin.gpx +64 -0
- data/spec/fixtures/holy_x_non_garmin.gpx +52 -0
- data/spec/gpx2geojson_spec.rb +27 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rspec.rake +3 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69264ad298a5d2fcffc82993c61ff5aa3a864fd7
|
4
|
+
data.tar.gz: 7b8a5dd42d0094faee78604ff7f44180fc0c5447
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cda42526e24d0460e290f0ff679a8ae33fb70418adc5a8c860e3ed321d4a4f17fe1df8b77f5880f29baf0560c81ed0e7eee247daa97d10ea8cf0ead3dd0069a4
|
7
|
+
data.tar.gz: 4406c6cb4d566db4fdbac2f7aab498e99f88965f4a9c46aaf759f0b430e1d454685e9fda8dddc5b90772c491a9de999ece0358ccfaaf555804d96ad7f0496983
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andy Mention
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Gpx2geojson
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'gpx2geojson'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install gpx2geojson
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/gpx2geojson/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/gpx2geojson.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gpx2geojson/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gpx2geojson"
|
8
|
+
spec.version = Gpx2geojson::VERSION
|
9
|
+
spec.authors = ["Andy Mention"]
|
10
|
+
spec.email = ["amention@gmail.com"]
|
11
|
+
spec.summary = %q{A simple tool for converting GPX files into GeoJSON.}
|
12
|
+
spec.description = %q{Convert GPX to GeoJSON}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_dependency "nokogiri", "~>1.6"
|
26
|
+
end
|
data/lib/gpx2geojson.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "gpx2geojson/version"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module Gpx2geojson
|
5
|
+
def self.parse(file_thing)
|
6
|
+
@gpx = file_thing || file_thing.tempfile
|
7
|
+
parse_file
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse_file
|
11
|
+
data = @gpx.read
|
12
|
+
|
13
|
+
file_mode = data =~ /trkpt/ ? "//trkpt" : (data =~ /rtept/ ? "//rtept" : "//wpt")
|
14
|
+
|
15
|
+
geo_json = '{"type": "Feature", "geometry": {"type": "MultiLineString","coordinates": [['
|
16
|
+
Nokogiri.HTML(data).search(file_mode).each do |tp|
|
17
|
+
geo_json += '[' + "#{tp[:lon].to_f}" + ", " + "#{tp[:lat].to_f}" + '], '
|
18
|
+
end
|
19
|
+
|
20
|
+
geo_json = geo_json[0..-3]
|
21
|
+
geo_json += ']]}}'
|
22
|
+
geo_json
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<gpx version="1.1" creator="Garmin Connect"
|
3
|
+
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"
|
4
|
+
xmlns="http://www.topografix.com/GPX/1/1"
|
5
|
+
xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"
|
6
|
+
xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
7
|
+
<metadata>
|
8
|
+
<link href="connect.garmin.com">
|
9
|
+
<text>Garmin Connect</text>
|
10
|
+
</link>
|
11
|
+
<time>2014-04-12T12:07:43.000Z</time>
|
12
|
+
</metadata>
|
13
|
+
<trk>
|
14
|
+
<name>Elevator Shaft Couloir on Hallett Peak</name>
|
15
|
+
<desc>Skied the Elevator Shaft Couloir on Hallett Peak</desc>
|
16
|
+
<trkseg>
|
17
|
+
<trkpt lon="-105.64569155685604" lat="40.311814388260245">
|
18
|
+
<ele>2922.39990234375</ele>
|
19
|
+
<time>2014-04-12T12:07:43.000Z</time>
|
20
|
+
<extensions>
|
21
|
+
<gpxtpx:TrackPointExtension>
|
22
|
+
<gpxtpx:atemp>19.0</gpxtpx:atemp>
|
23
|
+
</gpxtpx:TrackPointExtension>
|
24
|
+
</extensions>
|
25
|
+
</trkpt>
|
26
|
+
<trkpt lon="-105.6465789489448" lat="40.31086714938283">
|
27
|
+
<ele>2931.800048828125</ele>
|
28
|
+
<time>2014-04-12T12:13:13.000Z</time>
|
29
|
+
<extensions>
|
30
|
+
<gpxtpx:TrackPointExtension>
|
31
|
+
<gpxtpx:atemp>17.0</gpxtpx:atemp>
|
32
|
+
</gpxtpx:TrackPointExtension>
|
33
|
+
</extensions>
|
34
|
+
</trkpt>
|
35
|
+
<trkpt lon="-105.64668657258153" lat="40.309694185853004">
|
36
|
+
<ele>2948.0</ele>
|
37
|
+
<time>2014-04-12T12:15:18.000Z</time>
|
38
|
+
<extensions>
|
39
|
+
<gpxtpx:TrackPointExtension>
|
40
|
+
<gpxtpx:atemp>17.0</gpxtpx:atemp>
|
41
|
+
</gpxtpx:TrackPointExtension>
|
42
|
+
</extensions>
|
43
|
+
</trkpt>
|
44
|
+
<trkpt lon="-105.64773741178215" lat="40.30902463942766">
|
45
|
+
<ele>2960.800048828125</ele>
|
46
|
+
<time>2014-04-12T12:16:55.000Z</time>
|
47
|
+
<extensions>
|
48
|
+
<gpxtpx:TrackPointExtension>
|
49
|
+
<gpxtpx:atemp>16.0</gpxtpx:atemp>
|
50
|
+
</gpxtpx:TrackPointExtension>
|
51
|
+
</extensions>
|
52
|
+
</trkpt>
|
53
|
+
<trkpt lon="-105.6488900911063" lat="40.30884870328009">
|
54
|
+
<ele>2972.199951171875</ele>
|
55
|
+
<time>2014-04-12T12:18:31.000Z</time>
|
56
|
+
<extensions>
|
57
|
+
<gpxtpx:TrackPointExtension>
|
58
|
+
<gpxtpx:atemp>16.0</gpxtpx:atemp>
|
59
|
+
</gpxtpx:TrackPointExtension>
|
60
|
+
</extensions>
|
61
|
+
</trkpt>
|
62
|
+
</trkseg>
|
63
|
+
</trk>
|
64
|
+
</gpx>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="National Geographic Maps TOPO! 4.x"
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4
|
+
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
5
|
+
<metadata>
|
6
|
+
<desc>The information contained in this file may not be accurate. Use with caution.</desc>
|
7
|
+
<copyright author="14ers.com">
|
8
|
+
<year>2012</year>
|
9
|
+
</copyright>
|
10
|
+
<link href="http://www.14ers.com">
|
11
|
+
<text>14ers.com</text>
|
12
|
+
</link>
|
13
|
+
<bounds minlat="39.4652079343796" minlon="-106.4814155101776" maxlat="39.4972063302994" maxlon="-106.4658612012863"/>
|
14
|
+
</metadata>
|
15
|
+
<wpt lat="39.4667506217957" lon="-106.4816812276840">
|
16
|
+
<ele>4249.830</ele>
|
17
|
+
<name>SUMMIT</name>
|
18
|
+
</wpt>
|
19
|
+
<wpt lat="39.5005422830582" lon="-106.4331833124161">
|
20
|
+
<ele>3144.630</ele>
|
21
|
+
<name>TH</name>
|
22
|
+
</wpt>
|
23
|
+
<rte>
|
24
|
+
<name>holy2</name>
|
25
|
+
<number>1</number>
|
26
|
+
<rtept lat="39.5002144575119" lon="-106.4329234361649">
|
27
|
+
<ele>3144.320</ele>
|
28
|
+
<time>2014-06-22T15:56:14Z</time>
|
29
|
+
<name>W0</name>
|
30
|
+
</rtept>
|
31
|
+
<rtept lat="39.5000683069229" lon="-106.4331908226013">
|
32
|
+
<ele>3144.630</ele>
|
33
|
+
<time>2014-06-22T15:56:14Z</time>
|
34
|
+
<name>W1</name>
|
35
|
+
</rtept>
|
36
|
+
<rtept lat="39.4999943971634" lon="-106.4337532520294">
|
37
|
+
<ele>3153.770</ele>
|
38
|
+
<time>2014-06-22T15:56:14Z</time>
|
39
|
+
<name>W2</name>
|
40
|
+
</rtept>
|
41
|
+
<rtept lat="39.4998021125793" lon="-106.4342716932297">
|
42
|
+
<ele>3165.350</ele>
|
43
|
+
<time>2014-06-22T15:56:14Z</time>
|
44
|
+
<name>W3</name>
|
45
|
+
</rtept>
|
46
|
+
<rtept lat="39.4994632005692" lon="-106.4346312284470">
|
47
|
+
<ele>3167.490</ele>
|
48
|
+
<time>2014-06-22T15:56:14Z</time>
|
49
|
+
<name>W4</name>
|
50
|
+
</rtept>
|
51
|
+
</rte>
|
52
|
+
</gpx>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
describe Gpx2geojson do
|
6
|
+
subject { Gpx2geojson.new }
|
7
|
+
|
8
|
+
describe 'convert' do
|
9
|
+
it 'converts a (Garmin) file to JSON' do
|
10
|
+
file = File.open('./spec/fixtures/elevator_shaft_garmin.gpx')
|
11
|
+
parsed = JSON.parse(Gpx2geojson.parse(file))
|
12
|
+
|
13
|
+
expect(parsed["type"]).to eq("Feature")
|
14
|
+
expect(parsed["geometry"]["type"]).to eq("MultiLineString")
|
15
|
+
expect(parsed['geometry']['coordinates'][0].length).to eq(5)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'converts a non-Garmin GPX file to GeoJSON' do
|
19
|
+
file = File.open('./spec/fixtures/holy_x_non_garmin.gpx')
|
20
|
+
parsed = JSON.parse(Gpx2geojson.parse(file))
|
21
|
+
|
22
|
+
expect(parsed["type"]).to eq("Feature")
|
23
|
+
expect(parsed["geometry"]["type"]).to eq("MultiLineString")
|
24
|
+
expect(parsed['geometry']['coordinates'][0].length).to eq(5)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'gpx2geojson'
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpx2geojson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Mention
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
description: Convert GPX to GeoJSON
|
84
|
+
email:
|
85
|
+
- amention@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- gpx2geojson.gemspec
|
96
|
+
- lib/gpx2geojson.rb
|
97
|
+
- lib/gpx2geojson/version.rb
|
98
|
+
- spec/fixtures/elevator_shaft_garmin.gpx
|
99
|
+
- spec/fixtures/holy_x_non_garmin.gpx
|
100
|
+
- spec/gpx2geojson_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
- tasks/rspec.rake
|
103
|
+
homepage: ''
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.2
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A simple tool for converting GPX files into GeoJSON.
|
127
|
+
test_files:
|
128
|
+
- spec/fixtures/elevator_shaft_garmin.gpx
|
129
|
+
- spec/fixtures/holy_x_non_garmin.gpx
|
130
|
+
- spec/gpx2geojson_spec.rb
|
131
|
+
- spec/spec_helper.rb
|