ydf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c785b2c43b43119e247b6cf7710de9679c6ab07
4
+ data.tar.gz: 58fcd1f0df7fa2f04c84b2d7f343869462f9248e
5
+ SHA512:
6
+ metadata.gz: 773b411b467403fecaf4fdea99630564c23c98bce4e154d5804d4cdd4a1807f2831ec9d5be532da289972e98bf48290fcd62fb724f1c889dd6aee20b114b0c2e
7
+ data.tar.gz: 8be099818bbb398a7a1ae1789fde75f5c0bb59d0dd837aa4574b1de3f4f022493707719dbf8f7415d3fcfd4ec7071156f38ad88a741e0987d05fa027ffdf1590
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at niwasawa@maigo.info. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ydf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Naoki Iwasawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Ydf
2
+
3
+ This library is a converter of geo data format for YDF (YOLP Data Format) on Ruby. This library is experimental and unstable.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ydf'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ydf
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ require "ydf"
25
+
26
+ kml = open("kml_linestring.kml", &:read)
27
+ puts kml
28
+
29
+ doc = YDF::Convert::KML.new().parse(kml)
30
+
31
+ ydf = YDF::Convert::YDFXML.new().generate(doc)
32
+ puts ydf
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/niwasawa/ydf-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
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 "ydf"
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
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
@@ -0,0 +1,23 @@
1
+
2
+ module YDF
3
+
4
+ module Convert
5
+
6
+ class Document
7
+
8
+ def initialize(properties)
9
+ @properties = properties
10
+ @features = []
11
+ end
12
+
13
+ def to_s
14
+ return @features.join("\n")
15
+ end
16
+
17
+ attr_reader :properties
18
+ attr_accessor :features
19
+ end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,22 @@
1
+
2
+ module YDF
3
+
4
+ module Convert
5
+
6
+ class Feature
7
+
8
+ def initialize(geometry, properties)
9
+ @geometry = geometry
10
+ @properties = properties
11
+ end
12
+
13
+ def to_s
14
+ return "#{@properties}: #{@geometry}"
15
+ end
16
+
17
+ attr_accessor :geometry, :properties
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,49 @@
1
+ require "rexml/document"
2
+
3
+ module YDF
4
+
5
+ module Convert
6
+
7
+ class KML
8
+
9
+ def parse(kml)
10
+
11
+ xmldoc = REXML::Document.new(kml)
12
+
13
+ d = xmldoc.get_elements("kml/Document")
14
+ h = element_to_hash(d[0])
15
+ c = d[0].get_elements("Placemark/LineString/coordinates")
16
+ properties = h
17
+
18
+ lineString = createLineString(c[0].get_text.value)
19
+ feature = YDF::Convert::Feature.new(lineString, {})
20
+ doc = YDF::Convert::Document.new(properties)
21
+ doc.features.push(feature)
22
+
23
+ return doc
24
+ end
25
+
26
+ def createLineString(coordinates)
27
+ points = []
28
+ coordinates.split("\n").each{|line|
29
+ if line.strip != ""
30
+ ll = line.split(',')
31
+ p = Point.new(ll[1], ll[0])
32
+ points.push(p)
33
+ end
34
+ }
35
+ return YDF::Convert::LineString.new(points)
36
+ end
37
+
38
+ def element_to_hash(element)
39
+ h = {}
40
+ element.elements.each{|e|
41
+ h[e.name] = e.text
42
+ }
43
+ return h
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module YDF
3
+
4
+ module Convert
5
+
6
+ class LineString
7
+
8
+ def initialize(points)
9
+ @points = points
10
+ end
11
+
12
+ def to_s
13
+ return @points.join(" ")
14
+ end
15
+
16
+ attr_accessor :points
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,22 @@
1
+
2
+ module YDF
3
+
4
+ module Convert
5
+
6
+ class Point
7
+
8
+ def initialize(lat, lon)
9
+ @lat = lat
10
+ @lon = lon
11
+ end
12
+
13
+ def to_s
14
+ return "lat=#{@lat}, lon=#{@lon}"
15
+ end
16
+
17
+ attr_accessor :lat, :lon
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,101 @@
1
+ require "rexml/document"
2
+
3
+ module YDF
4
+
5
+ module Convert
6
+
7
+ class YDFXML
8
+
9
+ def generate(doc, option={})
10
+
11
+ id = doc.properties['id']
12
+ name = doc.properties['name']
13
+ description = doc.properties['description']
14
+
15
+ out = REXML::Document.new()
16
+ out.add(REXML::XMLDecl.new(version="1.0", encoding="UTF-8"))
17
+
18
+ out_ydf = REXML::Element.new("YDF")
19
+ out_ydf.add_attributes({
20
+ "xmlns" => "http://olp.yahooapis.jp/ydf/1.0"
21
+ })
22
+ out.add_element(out_ydf)
23
+
24
+ out_ydf.add_element(createYdfResultInfo(doc))
25
+
26
+ doc.features.each{|feature|
27
+ f = createYdfLineStringFeature(feature)
28
+ out_ydf.add_element(f)
29
+ }
30
+
31
+ output = ""
32
+ out.write(output: output, indent: -1, transitive: false, ie_hack: false)
33
+
34
+ return output
35
+ end
36
+
37
+ def createYdfResultInfo(doc)
38
+ ri = REXML::Element.new("ResultInfo")
39
+ ri.add_element(REXML::Element.new("Status").add_text("200"))
40
+ ri.add_element(REXML::Element.new("Count").add_text(doc.features.size().to_s()))
41
+ return ri
42
+ end
43
+
44
+ def createYdfLineStringFeature(feature)
45
+
46
+ id = feature.properties['id']
47
+ name = feature.properties['name']
48
+ description = feature.properties['description']
49
+ coordinates = createYdfCoordinates(feature.geometry)
50
+
51
+ out_feature = REXML::Element.new("Feature")
52
+
53
+ REXML::Element.new("Id", out_feature).add_text(id) if id
54
+ REXML::Element.new("Name", out_feature).add_text(name) if name
55
+ REXML::Element.new("Description", out_feature).add_text(description) if description
56
+
57
+ out_geometry = REXML::Element.new("Geometry", out_feature)
58
+ REXML::Element.new("Type", out_geometry).add_text("linestring")
59
+ REXML::Element.new("Coordinates", out_geometry).add_text(coordinates)
60
+
61
+ #out_style= createYdfStyle()
62
+ #out_feature.add_element(out_style)
63
+
64
+ #out_style = REXML::Element.new("Style", out_feature)
65
+ #REXML::Element.new("Type", out_style).add_text("line")
66
+ #REXML::Element.new("Size", out_style).add_text("3")
67
+ #REXML::Element.new("Opacity", out_style).add_text("50")
68
+ #REXML::Element.new("Color", out_style).add_text("0000ff")
69
+ #REXML::Element.new("EndLine", out_style).add_text("arrow")
70
+ #REXML::Element.new("StartLine", out_style).add_text("arrow")
71
+
72
+ return out_feature
73
+ end
74
+
75
+ def createYdfStyle()
76
+ out_style = REXML::Element.new("Style")
77
+ REXML::Element.new("Type", out_style).add_text("line")
78
+ REXML::Element.new("Size", out_style).add_text("3")
79
+ REXML::Element.new("Opacity", out_style).add_text("50")
80
+ REXML::Element.new("Color", out_style).add_text("0000ff")
81
+ REXML::Element.new("EndLine", out_style).add_text("arrow")
82
+ REXML::Element.new("StartLine", out_style).add_text("arrow")
83
+ return out_style
84
+ end
85
+
86
+ def createYdfCoordinates(lineString)
87
+ c = []
88
+ lineString.points.each{|p|
89
+ c.push("#{p.lon},#{p.lat}")
90
+ }
91
+ return c.join(" ")
92
+ end
93
+
94
+ def parse(xml)
95
+ end
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
@@ -0,0 +1,3 @@
1
+ module YDF
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ydf.rb ADDED
@@ -0,0 +1,10 @@
1
+ module YDF
2
+ end
3
+
4
+ require 'ydf/version'
5
+ require 'ydf/convert/document'
6
+ require 'ydf/convert/feature'
7
+ require 'ydf/convert/kml'
8
+ require 'ydf/convert/linestring'
9
+ require 'ydf/convert/point'
10
+ require 'ydf/convert/ydfxml'
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
3
+ <Document>
4
+ <name>Nagoya Station to Mode Gakuen Spiral Towers</name>
5
+ <atom:author>
6
+ <atom:name>niwasawa</atom:name>
7
+ </atom:author>
8
+ <atom:link href="http://latlonglab.yahoo.co.jp/route/watch?id=c929431b4a7b07546ff59b30f50aa951" />
9
+ <description><![CDATA[Welcome to the last dungeon in Nagoya.]]></description>
10
+ <Placemark>
11
+ <Style>
12
+ <LineStyle>
13
+ <color>99ff0000</color>
14
+ <width>6</width>
15
+ </LineStyle>
16
+ </Style>
17
+ <LineString>
18
+ <coordinates>
19
+ 136.8824888888889,35.170765277777775,1
20
+ 136.88327194444443,35.17087055555555,1
21
+ 136.88327194444443,35.17087055555555,1
22
+ 136.88396944444443,35.17070388888889,1
23
+ 136.88396944444443,35.17070388888889,1
24
+ 136.88425916666668,35.1700725,2
25
+ 136.88425916666668,35.1700725,2
26
+ 136.88446305555556,35.169449444444446,2
27
+ 136.88446305555556,35.169449444444446,2
28
+ 136.884785,35.16826555555556,2
29
+ 136.884785,35.16826555555556,2
30
+ 136.88545027777778,35.168396944444446,2
31
+ 136.88545027777778,35.168396944444446,2
32
+ 136.88550388888888,35.168283055555555,2
33
+ </coordinates>
34
+ </LineString>
35
+ </Placemark>
36
+ </Document>
37
+ </kml>
data/sample/sample.rb ADDED
@@ -0,0 +1,20 @@
1
+ #require 'rubygems'
2
+ require "ydf"
3
+ require 'open-uri'
4
+
5
+ def read(filepath)
6
+ return open(filepath, &:read)
7
+ end
8
+
9
+ #filepath = "http://latlonglab.yahoo.co.jp/route/get?id=c929431b4a7b07546ff59b30f50aa951&format=kml"
10
+ filepath = "kml_linestring.kml"
11
+
12
+ kml = read(filepath)
13
+ puts kml
14
+
15
+ doc = YDF::Convert::KML.new().parse(kml)
16
+ puts doc.to_s
17
+
18
+ ydf = YDF::Convert::YDFXML.new().generate(doc)
19
+ puts ydf
20
+
data/sample/sample.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec ruby sample.rb
4
+
data/ydf.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ydf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ydf"
8
+ spec.version = YDF::VERSION
9
+ spec.authors = ["Naoki Iwasawa"]
10
+ spec.email = ["niwasawa@maigo.info"]
11
+
12
+ spec.summary = %q{This library is a converter of geo data format for YDF (YOLP Data Format) on Ruby. This library is experimental and unstable.}
13
+ spec.description = %q{This library is a converter of geo data format for YDF (YOLP Data Format) on Ruby. This library is experimental and unstable.}
14
+ spec.homepage = "https://github.com/niwasawa/ydf-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ydf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naoki Iwasawa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-14 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: This library is a converter of geo data format for YDF (YOLP Data Format)
56
+ on Ruby. This library is experimental and unstable.
57
+ email:
58
+ - niwasawa@maigo.info
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - CODE_OF_CONDUCT.md
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/ydf.rb
74
+ - lib/ydf/convert/document.rb
75
+ - lib/ydf/convert/feature.rb
76
+ - lib/ydf/convert/kml.rb
77
+ - lib/ydf/convert/linestring.rb
78
+ - lib/ydf/convert/point.rb
79
+ - lib/ydf/convert/ydfxml.rb
80
+ - lib/ydf/version.rb
81
+ - sample/kml_linestring.kml
82
+ - sample/sample.rb
83
+ - sample/sample.sh
84
+ - ydf.gemspec
85
+ homepage: https://github.com/niwasawa/ydf-ruby
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.5.1
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: This library is a converter of geo data format for YDF (YOLP Data Format)
109
+ on Ruby. This library is experimental and unstable.
110
+ test_files: []