underpass 0.0.2
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/LICENSE +20 -0
- data/README.md +36 -0
- data/lib/underpass/ql/bounding_box.rb +15 -0
- data/lib/underpass/ql/parser.rb +44 -0
- data/lib/underpass/ql/ql.rb +15 -0
- data/lib/underpass/ql/query.rb +14 -0
- data/lib/underpass/ql/request.rb +30 -0
- data/lib/underpass/ql/shape.rb +29 -0
- data/lib/underpass.rb +19 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6eb4a19e646598efaf21f69ec0d0e3bc4d398efc4fcc9dd3cc4bc906c970e60
|
4
|
+
data.tar.gz: 7f1b2578cc5d3abaeeb99ceb91bcf20a5c64097ed6c3b90f39554001ccbf7ffc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a67e96bf3764f6235251f08c464a9597bea694d8578647affbbe6fe3cd37045c743b05d385f40d0406a146f7f750284296c6021445b772cd13f62667463ea356
|
7
|
+
data.tar.gz: 20e28a130ceb311dabb78104087fe5a25e59bfb6127d55c944a8697f175be03dd916a61dc52c0edcfe5a397676021bffdb3153d3113f1774c3708690d671adce
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2019 Janos Rusiczki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# underpass
|
2
|
+
|
3
|
+
A library that makes it easy to translate [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) responses into RGeo objects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install globally:
|
8
|
+
|
9
|
+
gem install underpass
|
10
|
+
|
11
|
+
Or put it in your Gemfile:
|
12
|
+
|
13
|
+
gem 'underpass'
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
# create a bounding box
|
18
|
+
f = RGeo::Geographic.spherical_factory
|
19
|
+
bbox = f.parse_wkt('POLYGON ((23.669 47.65, 23.725 47.65, 23.725 47.674, 23.669 47.674, 23.669 47.65))')
|
20
|
+
# provide the query part
|
21
|
+
op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
|
22
|
+
# perform the query and get results
|
23
|
+
result = Underpass::QL::Query.perform(bbox, op_query)
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet;
|
28
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and / or contributed it;
|
29
|
+
* Fork the project;
|
30
|
+
* Start a feature / bugfix branch;
|
31
|
+
* Commit and push until you are happy with your contribution;
|
32
|
+
* Make sure to add specs for it. This is important so your contribution won't be broken in a future version unintentionally.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
underpass is released under the MIT License. See the [LICENSE file](LICENSE) for further details.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underpass
|
4
|
+
module QL
|
5
|
+
# Bounding box related utilities.
|
6
|
+
class BoundingBox
|
7
|
+
# returns the Overpass query language bounding box string
|
8
|
+
# when provided with an RGeo geometry
|
9
|
+
def self.from_geometry(geometry)
|
10
|
+
r_bb = RGeo::Cartesian::BoundingBox.create_from_geometry(geometry)
|
11
|
+
"bbox:#{r_bb.min_y},#{r_bb.min_x},#{r_bb.max_y},#{r_bb.max_x}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underpass
|
4
|
+
module QL
|
5
|
+
# Parses the API request response into easily digestable objects
|
6
|
+
# which are then returned as matches.
|
7
|
+
class Parser
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
@matches = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def parse
|
14
|
+
parsed_json = JSON.parse(@response.body, symbolize_names: true)
|
15
|
+
elements = parsed_json[:elements]
|
16
|
+
|
17
|
+
@nodes = extract_indexed_nodes(elements)
|
18
|
+
@ways = extract_indexed_ways(elements)
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def matches
|
24
|
+
@ways.each_value do |way|
|
25
|
+
@matches << Underpass::QL::Shape.polygon_from_way(way, @nodes)
|
26
|
+
end
|
27
|
+
|
28
|
+
@matches
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def extract_indexed_nodes(elements)
|
34
|
+
nodes = elements.select { |e| e[:type] == 'node' }
|
35
|
+
nodes.map { |e| [e[:id], e] }.to_h
|
36
|
+
end
|
37
|
+
|
38
|
+
def extract_indexed_ways(elements)
|
39
|
+
ways = elements.select { |e| e[:type] == 'way' }
|
40
|
+
ways.map { |e| [e[:id], e] }.to_h
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'underpass/ql/bounding_box'
|
4
|
+
require 'underpass/ql/shape'
|
5
|
+
require 'underpass/ql/request'
|
6
|
+
require 'underpass/ql/parser'
|
7
|
+
require 'underpass/ql/query'
|
8
|
+
|
9
|
+
module Underpass
|
10
|
+
# Provides the means to work with Overpass by using the
|
11
|
+
# Overpass Query Language (QL). Overpass also provides an XML based
|
12
|
+
# query language but we're not interested in that.
|
13
|
+
module QL
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underpass
|
4
|
+
module QL
|
5
|
+
# Convenience class, provides the perform static method.
|
6
|
+
class Query
|
7
|
+
def self.perform(bounding_box, query)
|
8
|
+
op_bbox = Underpass::QL::BoundingBox.from_geometry(bounding_box)
|
9
|
+
response = Underpass::QL::Request.new(query, op_bbox).run
|
10
|
+
Underpass::QL::Parser.new(response).parse.matches
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underpass
|
4
|
+
module QL
|
5
|
+
# Deals with performing the Overpass API request.
|
6
|
+
class Request
|
7
|
+
API_URI = 'https://overpass-api.de/api/interpreter'.freeze
|
8
|
+
QUERY_TEMPLATE = <<-TEMPLATE.freeze
|
9
|
+
[out:json][timeout:25]BBOX;
|
10
|
+
(
|
11
|
+
QUERY
|
12
|
+
);
|
13
|
+
out body;
|
14
|
+
>;
|
15
|
+
out skel qt;
|
16
|
+
TEMPLATE
|
17
|
+
|
18
|
+
def initialize(query, bbox)
|
19
|
+
@overpass_query = query
|
20
|
+
@global_bbox ||= "[#{bbox}]"
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
query = QUERY_TEMPLATE.sub('BBOX', @global_bbox)
|
25
|
+
.sub('QUERY', @overpass_query)
|
26
|
+
Net::HTTP.post_form(URI(API_URI), data: query)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Underpass
|
4
|
+
module QL
|
5
|
+
# Contains factories for various shapes from ways and nodes.
|
6
|
+
class Shape
|
7
|
+
def self.polygon_from_way(way, nodes)
|
8
|
+
f = RGeo::Geographic.spherical_factory(srid: 4326)
|
9
|
+
f.polygon(line_string_from_way(way, nodes))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.line_string_from_way(way, nodes)
|
13
|
+
f = RGeo::Geographic.spherical_factory(srid: 4326)
|
14
|
+
f.line_string(
|
15
|
+
way[:nodes].map do |n|
|
16
|
+
f.point(nodes[n][:lon], nodes[n][:lat])
|
17
|
+
end
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# There should be some sort of 'decorator' to return an object
|
22
|
+
# with the shape and a copy of the tags as
|
23
|
+
# {
|
24
|
+
# tags: way[:tags],
|
25
|
+
# shape: shape
|
26
|
+
# }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/underpass.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rgeo'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
require 'underpass/ql/ql'
|
7
|
+
|
8
|
+
# The Underpass library
|
9
|
+
# Offers various helpers to work with the Overpass API and RGeo objects
|
10
|
+
module Underpass
|
11
|
+
end
|
12
|
+
|
13
|
+
# Example usage
|
14
|
+
#
|
15
|
+
# require 'underpass'
|
16
|
+
# f = RGeo::Geographic.spherical_factory
|
17
|
+
# bbox = f.parse_wkt('POLYGON ((23.669 47.65, 23.725 47.65, 23.725 47.674, 23.669 47.674, 23.669 47.65))')
|
18
|
+
# op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
|
19
|
+
# Underpass::QL::Query.perform(bbox, op_query)
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: underpass
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Janos Rusiczki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rgeo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.5.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.16.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.16.0
|
55
|
+
description: underpass makes it easy to translate Overpass API responses into RGeo
|
56
|
+
objects
|
57
|
+
email: janos.rusiczki@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- lib/underpass.rb
|
65
|
+
- lib/underpass/ql/bounding_box.rb
|
66
|
+
- lib/underpass/ql/parser.rb
|
67
|
+
- lib/underpass/ql/ql.rb
|
68
|
+
- lib/underpass/ql/query.rb
|
69
|
+
- lib/underpass/ql/request.rb
|
70
|
+
- lib/underpass/ql/shape.rb
|
71
|
+
homepage: http://github.com/haiafara/underpass
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.1
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: A library that translates Overpass API responses into RGeo objects
|
94
|
+
test_files: []
|