connect_gsi_api 0.1.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 +11 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/calcdist +5 -0
- data/connect_gsi_api.gemspec +25 -0
- data/lib/connect_gsi_api/version.rb +3 -0
- data/lib/connect_gsi_api.rb +33 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38537d0cf3ffca147f1ffa8b5bffb46f569d0791
|
4
|
+
data.tar.gz: 4ac06d8ee844edb1fccbda8acdc762dbdb0d9f15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8c2642f5a352f52da7510e422cc098d0aefef9d6ee3a735517023c75d4e9cc5ecee1804ae211f6c06762abaf5946c297a18727f2790b18416bc88b57de05056
|
7
|
+
data.tar.gz: fce3b1b8ce9bd52b61dd770d380ca8697e0758e386576177e6e48ac30305f7fee6e541f09179541b3956bc24f52635cd27144569b87a5957ca1b81edb6e73640
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Yasuhiro Matsumura (ym.contributor@gmail.com)
|
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,46 @@
|
|
1
|
+
# ConnectGsiApi
|
2
|
+
|
3
|
+
緯度・経度を入力値に、国土地理院提供のAPI経由で二点間の距離を算出します。
|
4
|
+
本gemは、一回のリクエストで、一回だけ国土地理院提供のAPIを叩きます。
|
5
|
+
APIの使用回数上限については、国土地理院が提示しているAPI利用規約を参照してください。
|
6
|
+
また、APIの仕様上、日本の緯度・経度にしか対応していません。
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Gemfile に下記の記述を追加してください。
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'connect_gsi_api'
|
14
|
+
```
|
15
|
+
|
16
|
+
その後、インストールをします:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
もしくは自分で手動でインストールしてください:
|
21
|
+
|
22
|
+
$ gem install connect_gsi_api
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
まず、本Gemを使いたいファイルの中で、requireしてください。
|
27
|
+
その上で、地点1の緯度/経度、地点2の緯度/経度 を引数に `ConnectGsiApi.distance2p` を呼び出してください。
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require "connect_gsi_api"
|
31
|
+
|
32
|
+
ConnectGsiApi.distance2p 35.6581, 139.701742, 36.123456, 138.705749
|
33
|
+
```
|
34
|
+
|
35
|
+
なお、パラメータ不正など、エラーが返ってくる呼び出しの場合は、nilが返ってくる仕様になっています。
|
36
|
+
|
37
|
+
また、動作確認目的として、コマンドでの呼び出しにも対応しています。
|
38
|
+
|
39
|
+
$ bundle exec calcdist 35.6581 139.701742 36.123456 138.705749
|
40
|
+
$ => 103682.866
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
本GemはMITライセンスです。
|
45
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
46
|
+
|
data/Rakefile
ADDED
data/bin/calcdist
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 'connect_gsi_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "connect_gsi_api"
|
8
|
+
spec.version = ConnectGsiApi::VERSION
|
9
|
+
spec.authors = ["Yasuhiro Matsumura"]
|
10
|
+
spec.email = ["ym.works1985@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{緯度・経度を入力値に、国土地理院提供のAPI経由で二点間の距離を算出します。}
|
13
|
+
spec.description = %q{本gemは、一回のリクエストで、一回だけ国土地理院提供のAPIを叩きます。APIの使用回数上限については、国土地理院が提示しているAPI利用規約を参照してください。また、APIの仕様上、日本の緯度・経度にしか対応していません。}
|
14
|
+
spec.homepage = "http://muramurasan.hatenablog.jp"
|
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 = "bin"
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "connect_gsi_api/version"
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
API_URL = "http://vldb.gsi.go.jp/sokuchi/surveycalc/"
|
6
|
+
BL2ST_CALC = "surveycalc/bl2st_calc.pl?"
|
7
|
+
|
8
|
+
module ConnectGsiApi
|
9
|
+
def self.distance2p(lat1, lng1, lat2, lng2, ellipsoid = "bessel")
|
10
|
+
req_params = {
|
11
|
+
outputType: 'json', # 出力タイプ
|
12
|
+
ellipsoid: ellipsoid, # 楕円体
|
13
|
+
latitude1: lat1.to_s, # 出発点緯度
|
14
|
+
longitude1: lng1.to_s, # 出発点経度
|
15
|
+
latitude2: lat2.to_s, # 到着点緯度
|
16
|
+
longitude2: lng2.to_s # 到着点経度
|
17
|
+
}
|
18
|
+
result = connect_gsi_api(API_URL + BL2ST_CALC, req_params)
|
19
|
+
result["OutputData"]["geoLength"].to_f
|
20
|
+
rescue
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def self.join_params(params)
|
27
|
+
params.map { |k, v| "#{k}=#{v}" }.join("&")
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.connect_gsi_api(api_path, params)
|
31
|
+
JSON.parse(open(api_path + join_params(params)).read)
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: connect_gsi_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yasuhiro Matsumura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: 本gemは、一回のリクエストで、一回だけ国土地理院提供のAPIを叩きます。APIの使用回数上限については、国土地理院が提示しているAPI利用規約を参照してください。また、APIの仕様上、日本の緯度・経度にしか対応していません。
|
56
|
+
email:
|
57
|
+
- ym.works1985@gmail.com
|
58
|
+
executables:
|
59
|
+
- calcdist
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/calcdist
|
70
|
+
- connect_gsi_api.gemspec
|
71
|
+
- lib/connect_gsi_api.rb
|
72
|
+
- lib/connect_gsi_api/version.rb
|
73
|
+
homepage: http://muramurasan.hatenablog.jp
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.14.1
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: 緯度・経度を入力値に、国土地理院提供のAPI経由で二点間の距離を算出します。
|
97
|
+
test_files: []
|