overpass-api-ruby 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/lib/overpass_api_ruby.rb +83 -0
- data/overpass-api-ruby.gemspec +28 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea5cecdd3df6b4d7e87716955266e3f80ef6ffa5
|
4
|
+
data.tar.gz: a0e5a5050fc4325c9d80f6754a33f71071bc9798
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62cf9544008ced451ac288797b26e2eafda76957b25ddb450cef6266cc8fcffcb19b34c19f63045553280870071005e2e450fc19a4c2fcc537f158c31830671c
|
7
|
+
data.tar.gz: 1f2708c93d10cb57ffb7683903fe3016bef70ef3e2949487da43c556b5c94eaf90c19ebc9ed53dbb0a2cc048f45f0774a6c1ec4bcc9f640fdf20f372e1af9cf6
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
.idea
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.1.0)
|
5
|
+
columnize (0.9.0)
|
6
|
+
debugger (1.6.8)
|
7
|
+
columnize (>= 0.3.1)
|
8
|
+
debugger-linecache (~> 1.2.0)
|
9
|
+
debugger-ruby_core_source (~> 1.3.5)
|
10
|
+
debugger-linecache (1.2.0)
|
11
|
+
debugger-ruby_core_source (1.3.7)
|
12
|
+
diskcached (1.1.0)
|
13
|
+
httpi (1.1.1)
|
14
|
+
rack
|
15
|
+
method_source (0.8.2)
|
16
|
+
mini_portile (0.6.2)
|
17
|
+
nokogiri (1.6.5)
|
18
|
+
mini_portile (~> 0.6.0)
|
19
|
+
pry (0.10.1)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.8.1)
|
22
|
+
slop (~> 3.4)
|
23
|
+
pry-debugger (0.2.3)
|
24
|
+
debugger (~> 1.3)
|
25
|
+
pry (>= 0.9.10, < 0.11.0)
|
26
|
+
rack (1.6.0)
|
27
|
+
slop (3.6.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
diskcached
|
34
|
+
httpi (~> 1.1.0)
|
35
|
+
nokogiri
|
36
|
+
pry-debugger
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Bruno Salerno
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
Overpass API Ruby
|
2
|
+
=================
|
3
|
+
|
4
|
+
A Ruby wrapper for OpenStreetMap Overpass API. Returns a Hash from a query.
|
5
|
+
|
6
|
+
Install
|
7
|
+
-------
|
8
|
+
|
9
|
+
`gem install overpass-api-ruby`
|
10
|
+
|
11
|
+
or add `gem 'overpass-api-ruby'` to your Gemfile
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'overpass_api_ruby'
|
18
|
+
|
19
|
+
ba_query = "<union><query type='relation'><has-kv k='route' v='subway'/></query>" <<
|
20
|
+
"</union><union><item/><recurse type='down'/></union>"
|
21
|
+
|
22
|
+
options={:bbox => {:s => -34.705448,:n => -34.526562,:w => -58.531471,:e => -58.335159},
|
23
|
+
:timeout => 900,
|
24
|
+
:element_limit => 1073741824,
|
25
|
+
:json => true}
|
26
|
+
|
27
|
+
overpass = OverpassAPI.new(options)
|
28
|
+
result_hash = overpass.query(ba_query)
|
29
|
+
```
|
30
|
+
|
31
|
+
Options on instantiation
|
32
|
+
------------------------
|
33
|
+
```
|
34
|
+
bbox Hash. Global bounding box.
|
35
|
+
endpoint String. Defaults to http://overpass-api.de/api/interpreter?data= .
|
36
|
+
timeout Integer.
|
37
|
+
element_init Integer.
|
38
|
+
json Boolean. API response is in JSON format, so parse to hash doesn't use the private
|
39
|
+
parse_nokogiri method. Default: false.
|
40
|
+
cache_expiration_time Integer. Default: 7200.
|
41
|
+
```
|
42
|
+
See [Overpass API](http://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide)
|
43
|
+
|
44
|
+
Public methods
|
45
|
+
--------------
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
query (<String query>) Intended to pass only children tags of <osm-script>.
|
49
|
+
|
50
|
+
raw_query (<String query>) The whole query must be passed.
|
51
|
+
|
52
|
+
bbox (s,n,w,e) Defines global bounding box.
|
53
|
+
```
|
54
|
+
|
55
|
+
|
56
|
+
License
|
57
|
+
-------
|
58
|
+
MIT.
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'httpi'
|
2
|
+
require 'diskcached'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class OverpassAPI
|
8
|
+
VERSION=0.1
|
9
|
+
DEFAULT_ENDPOINT='http://overpass-api.de/api/interpreter?data='
|
10
|
+
|
11
|
+
def initialize(args={})
|
12
|
+
bbox = args[:bbox]
|
13
|
+
bbox(bbox[:s],bbox[:n],bbox[:w],bbox[:e])
|
14
|
+
|
15
|
+
cache_expiration_time = args[:cache_expiration_time] || 7200
|
16
|
+
@cache = Diskcached.new('/tmp/cache',cache_expiration_time,true)
|
17
|
+
|
18
|
+
@endpoint = args[:endpoint] || DEFAULT_ENDPOINT
|
19
|
+
@json = args[:json] ? "output='json'" : ''
|
20
|
+
@timeout = args[:timeout] ? "timeout='#{args[:timeout]}'" : ''
|
21
|
+
@element_limit = args[:element_limit] ? "element-limit='#{args[:element_limit]}'" : ''
|
22
|
+
end
|
23
|
+
|
24
|
+
def bbox(s,n,w,e)
|
25
|
+
@bbox = "bbox='#{s},#{w},#{n},#{e}'"
|
26
|
+
end
|
27
|
+
|
28
|
+
def query(query)
|
29
|
+
return unless query
|
30
|
+
perform "<osm-script #{@bbox} #{@timeout} #{@element_limit} #{@json}>" <<
|
31
|
+
"#{query}<print/></osm-script>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def raw_query(query)
|
35
|
+
return unless query
|
36
|
+
perform query
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def perform(query)
|
41
|
+
url = URI::encode("#{@endpoint}#{query}")
|
42
|
+
data = @cache.cache("overpass_api_ruby_#{query}") do
|
43
|
+
request = HTTPI::Request.new(url)
|
44
|
+
HTTPI.get(request).body
|
45
|
+
end
|
46
|
+
|
47
|
+
return JSON.parse(data, :symbolize_names=> true)[:elements] unless @json.empty?
|
48
|
+
|
49
|
+
doc = Nokogiri::XML(data) do |config|
|
50
|
+
config.options = Nokogiri::XML::ParseOptions::NOBLANKS
|
51
|
+
end
|
52
|
+
|
53
|
+
raw = doc.children.first.children.select{|e| e.name != 'note' and e.name != 'meta'}
|
54
|
+
parse_nokogiri raw
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_nokogiri(xml)
|
58
|
+
xml.map {|e|
|
59
|
+
element = {:type => e.name}
|
60
|
+
|
61
|
+
e.attributes.each {|a|
|
62
|
+
element[a[1].name.to_sym] = a[1].value
|
63
|
+
}
|
64
|
+
|
65
|
+
members = e.children.select{|n| n.name != 'tag'}.map {|child|
|
66
|
+
key_values={:type => child.name }
|
67
|
+
child.attributes.each {|a|
|
68
|
+
key_values[a[1].name.to_sym] = a[1].value
|
69
|
+
}
|
70
|
+
key_values
|
71
|
+
}
|
72
|
+
element[:members] = members unless members.empty?
|
73
|
+
|
74
|
+
tags={}
|
75
|
+
e.children.select{|n| n.name == 'tag'}.each {|child|
|
76
|
+
tags[child.values.first] = child.values[1]
|
77
|
+
}
|
78
|
+
element[:tags] = tags unless tags.empty?
|
79
|
+
|
80
|
+
element
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'overpass_api_ruby'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "overpass-api-ruby"
|
8
|
+
spec.version = OverpassAPI::VERSION
|
9
|
+
spec.authors = ["Bruno Salerno"]
|
10
|
+
spec.email = ["br.salerno@gmail.com"]
|
11
|
+
spec.description = %q{A Ruby wrapper for OpenStreetMap Overpass API}
|
12
|
+
spec.summary = %q{Returns a Hash from a query}
|
13
|
+
spec.homepage = "https://github.com/BrunoSalerno/overpass-api-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_runtime_dependency "httpi", "~> 1.1.0"
|
22
|
+
spec.add_runtime_dependency "diskcached"
|
23
|
+
spec.add_runtime_dependency "nokogiri"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "pry-debugger"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: overpass-api-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Salerno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: diskcached
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-debugger
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A Ruby wrapper for OpenStreetMap Overpass API
|
98
|
+
email:
|
99
|
+
- br.salerno@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- lib/overpass_api_ruby.rb
|
110
|
+
- overpass-api-ruby.gemspec
|
111
|
+
homepage: https://github.com/BrunoSalerno/overpass-api-ruby
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Returns a Hash from a query
|
135
|
+
test_files: []
|