gpx_kml 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a769390353e349aae0b7248da2cbafa2cea2b09b3ab7a73e5da31f4ea38c984c
4
+ data.tar.gz: 495c06241c9507766d2d7d823d90235ea3705c68336fb49693aca83d7a32bafc
5
+ SHA512:
6
+ metadata.gz: e8c7e05c43c76a3091b23794c16fc4f94f1d6ad4c5c74c0214cfca2ec4fa79160921eed33bcb3daee69f92cf71c38b08dbd9e017502d7a1ceceddd8dc5124556
7
+ data.tar.gz: cc82f60ad4054bd515a469e3dfaea2ea0448a1fa88913963b487c2973014d946eb77c4bdc1d5d8b9e1dc37162fb01cc996d0c1c26dfef188f5d5e7191087d609
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,3 @@
1
+ <component name="ProjectDictionaryState">
2
+ <dictionary name="angelo" />
3
+ </component>
data/.idea/gpx_kml.iml ADDED
@@ -0,0 +1,61 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.4.1, RVM: ruby-2.7.2) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.7.2) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, RVM: ruby-2.7.2) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, RVM: ruby-2.7.2) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="factory_bot (v6.2.0, RVM: ruby-2.7.2) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.10, RVM: ruby-2.7.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.6.1, RVM: ruby-2.7.2) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, RVM: ruby-2.7.2) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.12.5, RVM: ruby-2.7.2) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.5.2, RVM: ruby-2.7.2) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, RVM: ruby-2.7.2) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, RVM: ruby-2.7.2) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, RVM: ruby-2.7.2) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, RVM: ruby-2.7.2) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, RVM: ruby-2.7.2) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, RVM: ruby-2.7.2) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, RVM: ruby-2.7.2) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.2, RVM: ruby-2.7.2) [gem]" level="application" />
32
+ </component>
33
+ <component name="RakeTasksCache">
34
+ <option name="myRootTask">
35
+ <RakeTaskImpl id="rake">
36
+ <subtasks>
37
+ <RakeTaskImpl description="Build gpx_kml-0.0.0.gem into the pkg directory" fullCommand="build" id="build" />
38
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
39
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
40
+ <RakeTaskImpl description="Build and install gpx_kml-0.0.0.gem into system gems" fullCommand="install" id="install" />
41
+ <RakeTaskImpl id="install">
42
+ <subtasks>
43
+ <RakeTaskImpl description="Build and install gpx_kml-0.0.0.gem into system gems without network access" fullCommand="install:local" id="local" />
44
+ </subtasks>
45
+ </RakeTaskImpl>
46
+ <RakeTaskImpl description="Create tag v0.0.0 and build and push gpx_kml-0.0.0.gem to TODO: Set to 'https://mygemserver.com'" fullCommand="release[remote]" id="release[remote]" />
47
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
48
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
49
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
50
+ <RakeTaskImpl id="release">
51
+ <subtasks>
52
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
53
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
54
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
55
+ </subtasks>
56
+ </RakeTaskImpl>
57
+ </subtasks>
58
+ </RakeTaskImpl>
59
+ </option>
60
+ </component>
61
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectResources">
4
+ <resource url="http://www.w3.org/2005/atom-author-link.xsd" location="$USER_HOME$/Desktop/atom-author-link.xsd" />
5
+ </component>
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-2.7.2" project-jdk-type="RUBY_SDK" />
7
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/gpx_kml.iml" filepath="$PROJECT_DIR$/.idea/gpx_kml.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
File without changes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at a.terzi@engim.eu. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in gpx_kml.gemspec
6
+ gemspec
7
+
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gpx_kml (0.0.1)
5
+ nokogiri (~> 1.12.0)
6
+ rake (~> 12.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.4.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ concurrent-ruby (1.1.9)
18
+ diff-lcs (1.4.4)
19
+ factory_bot (6.2.0)
20
+ activesupport (>= 5.0.0)
21
+ i18n (1.8.10)
22
+ concurrent-ruby (~> 1.0)
23
+ minitest (5.14.4)
24
+ nokogiri (1.12.5-x86_64-linux)
25
+ racc (~> 1.4)
26
+ racc (1.6.0)
27
+ rake (12.3.3)
28
+ rspec (3.10.0)
29
+ rspec-core (~> 3.10.0)
30
+ rspec-expectations (~> 3.10.0)
31
+ rspec-mocks (~> 3.10.0)
32
+ rspec-core (3.10.1)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-expectations (3.10.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.10.0)
37
+ rspec-mocks (3.10.2)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.10.0)
40
+ rspec-support (3.10.2)
41
+ tzinfo (2.0.4)
42
+ concurrent-ruby (~> 1.0)
43
+ zeitwerk (2.4.2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ factory_bot (~> 6.2)
50
+ gpx_kml!
51
+ rspec (~> 3.0)
52
+
53
+ BUNDLED WITH
54
+ 2.1.4
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # GpxKml
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gpx_kml`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Before using
8
+
9
+ Please take note that this only converts essentials data for the gpx and kml files compatibility.
10
+ However the gem doesn't just include the converter, it also transforms gpx files and kml files (only their track/route/point parts) into a Gpx/Kml file, which could be useful for a new fork or other uses.
11
+ Just dig in deep, tests are present for everything you need, except the mere conversion.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'gpx_kml'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle install
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install gpx_kml
28
+
29
+ ## Usage
30
+
31
+ To use it just ```require 'gpx_kml'``` in the script you need the converter and use either one of the following two functions:
32
+
33
+ - ```GPXKML::GpxKml.kml_to_gpx('file_path', 'destination_path')```
34
+ - ```GPXKML::GpxKml.gpx_to_kml('file_path', 'destination_path')```
35
+
36
+ Note: destination_path must be a directory
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Engim-eu/gpx_kml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/gpx_kml/blob/master/CODE_OF_CONDUCT.md).
47
+
48
+
49
+ ## Code of Conduct
50
+
51
+ Everyone interacting in the GpxKml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gpx_kml/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gpx_kml"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/gpx_kml.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ require_relative 'lib/gpx_kml/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'gpx_kml'
5
+ spec.version = GPXKML::VERSION
6
+ spec.authors = ['Angelo Terzi']
7
+ spec.email = ['info@engim.eu']
8
+
9
+ spec.summary = 'Gem to convert .gpx into .kml and back'
10
+ spec.description = 'This gem adds the capability to convert GPS Exchange Format (GPX) to Keyhole Markup Language (KML) and viceversa'
11
+ spec.homepage = 'https://www.github.com/engim-eu/'
12
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
13
+
14
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://www.github.com/engim-eu/gpx_kml'
18
+ spec.metadata['changelog_uri'] = 'https://www.github.com/engim-eu/gpx_kml/CHANGELOG.md'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ # Building tool
30
+ spec.add_dependency 'rake', '~> 12.0'
31
+
32
+ # XML parsing
33
+ spec.add_dependency 'nokogiri', '~>1.12.0'
34
+
35
+ # Gem testing
36
+ spec.add_development_dependency 'factory_bot', '~>6.2'
37
+ spec.add_development_dependency 'rspec', '~>3.0'
38
+ end
data/lib/converter.rb ADDED
@@ -0,0 +1,199 @@
1
+ # frozen_string_literal:true
2
+
3
+ module CONVERTER
4
+ # Docu
5
+ class Converter
6
+ def self.gpx_to_kml(gpx_path, output_path)
7
+ return unless File.directory?(output_path)
8
+
9
+ output_path = output_path[0..-2] if output_path[-1].eql?('/')
10
+ gpx = GPXKML::Gpx.new(gpx_path)
11
+ return nil if gpx.nil? || !gpx.valid?
12
+
13
+ kml = Nokogiri::XML::Builder.new do |xml|
14
+ xml.kml('xmlns': 'http://www.opengis.net/kml/2.2', 'xmlns:gx': 'http://www.google.com/kml/ext/2.2',
15
+ 'xmlns:atom': 'http://www.w3.org/Atom') do
16
+ xml.Document do
17
+ if gpx.name.nil? || gpx.name.empty?
18
+ xml.name(gpx.file_name[0..-5])
19
+ else
20
+ xml.name(gpx.name)
21
+ end
22
+ xml.visibility('1')
23
+ xml.open('0')
24
+ unless gpx.author.nil? || gpx.author.empty?
25
+ xml['atom'].author do
26
+ xml['atom'].name(gpx.author)
27
+ end
28
+ end
29
+ xml['atom'].link(href: gpx.link) unless gpx.link.nil? || gpx.link.empty?
30
+ kml_points(xml, gpx)
31
+ kml_routes(xml, gpx)
32
+ kml_tracks(xml, gpx)
33
+ end
34
+ end
35
+ end
36
+ name = "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{gpx.file_name[0..-5]}.kml"
37
+ f = File.open("#{output_path}/#{name}", 'w')
38
+ f.write(kml.to_xml)
39
+ f.close
40
+ name
41
+ end
42
+
43
+ def self.kml_to_gpx(kml_path, output_path)
44
+ return unless File.directory?(output_path)
45
+
46
+ output_path = output_path[0..-2] if output_path[-1].eql?('/')
47
+ kml = GPXKML::Kml.new(kml_path)
48
+ return nil if kml.nil? || !kml.valid?
49
+
50
+ gpx = Nokogiri::XML::Builder.new do |xml|
51
+ xml.gpx('version': '1.1', 'creator': 'https://www.github.com/engim-eu/gpx_kml',
52
+ 'xmlns': 'https://www.topografix.com/GPX/1/1', 'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance') do
53
+ xml.metadata do
54
+ xml.name(kml.file_name[0..-5])
55
+ end
56
+ gpx_points(xml, kml)
57
+ gpx_routes(xml, kml)
58
+ gpx_tracks(xml, kml)
59
+ end
60
+ end
61
+ name = "#{Time.now.strftime('%Y%m%d%H%M%S')}_#{kml.file_name[0..-5]}.gpx"
62
+ f = File.open("#{output_path}/#{name}", 'w')
63
+ f.write(gpx.to_xml)
64
+ f.close
65
+ name
66
+ end
67
+
68
+ private
69
+
70
+ def self.kml_routes(xml, gpx)
71
+ if gpx.routes?
72
+ gpx.routes.each do |r|
73
+ xml.LinearRing do
74
+ xml.extrude('0')
75
+ xml.tassellate('0')
76
+ xml.altitudeMode('clampToGroud')
77
+ s = ''
78
+ r.points.each do |p|
79
+ s = if p.elevation.nil? || p.elevation.empty?
80
+ s + "#{p.latitude},#{p.longitude} "
81
+ else
82
+ s + "#{p.latitude},#{p.longitude},#{p.elevation} "
83
+ end
84
+ end
85
+ xml.coordinates(s[0..-2])
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ def self.kml_tracks(xml, gpx)
92
+ if gpx.tracks?
93
+ gpx.tracks.each do |t|
94
+ xml.LineString do
95
+ xml.extrude('0')
96
+ xml.tassellate('0')
97
+ xml.altitudeMode('clampToGroud')
98
+ s = ''
99
+ points = []
100
+ t.segments.each do |sg|
101
+ sg.points.each do |p|
102
+ points = points << p
103
+ end
104
+ end
105
+ points.each do |p|
106
+ next if p.nil?
107
+
108
+ s = if p.elevation.nil? || p.elevation.empty?
109
+ s + "#{p.latitude},#{p.longitude} "
110
+ else
111
+ s + "#{p.latitude},#{p.longitude},#{p.elevation} "
112
+ end
113
+ end
114
+ xml.coordinates(s[0..-2])
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ def self.kml_points(xml, gpx)
121
+ if gpx.points?
122
+ gpx.points.each do |p|
123
+ xml.Point do
124
+ xml.extrude('0')
125
+ xml.altitudeMode('clampToGroud')
126
+ if p.elevation.nil? || p.elevation.empty?
127
+ xml.coordinates("#{p.latitude},#{p.longitude}")
128
+ else
129
+ xml.coordinates("#{p.latitude},#{p.longitude},#{p.elevation}")
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ def self.gpx_points(xml, kml)
137
+ if kml.points?
138
+ kml.points.each do |p|
139
+ next if p.nil?
140
+
141
+ xml.wpt('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
142
+ xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
143
+ xml.name(p.name) unless p.name.nil? || p.name.empty?
144
+ xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
145
+ xml.link('href': p.link) unless p.link.nil? || p.link.empty?
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ def self.gpx_routes(xml, kml)
152
+ if kml.routes?
153
+ kml.routes.each do |r|
154
+ next if r.nil?
155
+
156
+ xml.rte do
157
+ xml.name(r.name) unless r.name.nil? || r.name.empty?
158
+ xml.desc("author= #{r.author}") unless r.author.nil? || r.author.empty?
159
+ xml.link('href': r.link) unless r.link.nil? || r.link.empty?
160
+ r.points.each do |p|
161
+ next if p.nil?
162
+
163
+ xml.rtept('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
164
+ xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
165
+ xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
166
+ xml.link('href': p.link) unless p.link.nil? || p.link.empty?
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+
174
+ def self.gpx_tracks(xml, kml)
175
+ if kml.tracks?
176
+ kml.tracks.each do |t|
177
+ next if t.nil?
178
+
179
+ xml.trk do
180
+ xml.name(t.name) unless t.name.nil? || t.name.empty?
181
+ xml.desc("author= #{t.author}") unless t.author.nil? || t.author.empty?
182
+ xml.link('href': t.link) unless t.link.nil? || t.link.empty?
183
+ xml.trkseg do
184
+ t.points.each do |p|
185
+ next if p.nil?
186
+
187
+ xml.trkpt('lat': "#{p.latitude}", 'lon': "#{p.longitude}") do
188
+ xml.ele("#{p.elevation}") unless p.elevation.nil? || p.elevation.empty?
189
+ xml.desc("author = #{p.author}") unless p.author.nil? || p.author.empty?
190
+ xml.link('href': p.link) unless p.link.nil? || p.link.empty?
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GPX
4
+ # Docu
5
+ class Point
6
+
7
+ def initialize(point, father)
8
+ return unless point.is_a? Nokogiri::XML::Element
9
+ return if point.xpath('self::*[self::xmlns:wpt or self::xmlns:rtept or self::xmlns:trkpt]').empty?
10
+
11
+ @longitude = point.xpath('@lon').to_s
12
+ @latitude = point.xpath('@lat').to_s
13
+ @elevation = point.xpath('./xmlns:ele/text()').to_s
14
+ @name = point.xpath('./xmlns:name/text()').to_s
15
+ @description = point.xpath('./xmlns:desc/text()').to_s
16
+ @link = point.xpath('./xmlns:link/@href').to_s
17
+ return unless valid_father? father
18
+
19
+ @father = father
20
+ end
21
+
22
+
23
+ attr_reader :longitude, :latitude, :link, :name, :description, :father, :elevation
24
+
25
+ private
26
+
27
+ def valid_father?(father)
28
+ father.is_a?(GPX::Segment) || father.is_a?(GPX::Route) || father.is_a?(GPXKML::Gpx)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gpx_kml/gpx/point'
4
+
5
+ module GPX
6
+ # Docu
7
+ class Route
8
+ def initialize(route)
9
+ return unless route.is_a?(Nokogiri::XML::Element) && !route.xpath('self::xmlns:rte').empty?
10
+
11
+ @name = route.xpath('./xmlns:name/text()').to_s
12
+ @number = route.xpath('./xmlns:number/text()').to_s
13
+ @description = route.xpath('./xmlns:desc/text()').to_s
14
+ @link = route.xpath('./xmlns:link/@href').to_s
15
+ @points = _points route
16
+ end
17
+
18
+ attr_reader :name, :link, :points, :description, :number, :time
19
+
20
+ private
21
+
22
+ def _points(route)
23
+ route_points = []
24
+ route.xpath('./xmlns:rtept').each_with_index do |rp, i|
25
+ route_points[i] = Point.new(rp, self)
26
+ end
27
+ route_points
28
+ end
29
+ end
30
+ end