underpass 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 499389ab42025a727e89c1bfbee99f0444fb7db0593c06ad2959eda87d794d65
4
- data.tar.gz: c8d700d784d837474e6fa5dd5f8d35339b8bf17cf08de41cdfa32807f87cf889
3
+ metadata.gz: 38e561ec9d01ca1013783c0ea8cedb34b00d52938db669d3f5feb4a10d7fd155
4
+ data.tar.gz: a99031218fec8de7c13d48df9c54e222445a2eb9dbb3399b1ab0605fe390d263
5
5
  SHA512:
6
- metadata.gz: 321f52730a7c02f9828cf5451e4a92507fb32b219114a3d1b20c93956e19e710218594a5afee47370e4cafc7e37f5226c21db8f43806ff9fc2fe7becb2ac6e5f
7
- data.tar.gz: aeeda5fbdf1f1a355a4ee4e9d5484aaf1d71994ba3c6f08d236fc4e4473363c94fabe219a3205a8d8220f74f2ad0cc5ae45198b532e4c0f8516e5ae8f9a69e7b
6
+ metadata.gz: 0d89ebcb48cb6309caee1947acde9f8c946568256017cf4387155952ed2c4e13dbfc8a1d226b4127db7580fe7b70ad7c7250094124f2b9b81eef26338db650e6
7
+ data.tar.gz: 9ea52cceb5fcf0edb4ee634a4c012e6ffbc65c288be0f632fe77639f87aa6b4cee8996315eda23612515bc88cc72abd928f872249cbef95efb3f7e0712747cfe
data/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/underpass.svg)](https://badge.fury.io/rb/underpass)
4
4
  [![Build Status](https://www.travis-ci.org/haiafara/underpass.svg?branch=master)](https://www.travis-ci.org/haiafara/underpass)
5
+ [![Coverage Status](https://coveralls.io/repos/github/haiafara/underpass/badge.svg?branch=master)](https://coveralls.io/github/haiafara/underpass?branch=master)
5
6
 
6
- A library that makes it easy to translate [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) responses into RGeo objects.
7
+ A library that makes it easy to query the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API) and translate its responses into [RGeo](https://github.com/rgeo/rgeo) objects.
7
8
 
8
9
  ## Installation
9
10
 
@@ -17,13 +18,21 @@ Or put it in your Gemfile:
17
18
 
18
19
  ## Usage
19
20
 
20
- # create a bounding box
21
- f = RGeo::Geographic.spherical_factory
22
- 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))')
23
- # provide the query part
24
- op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
25
- # perform the query and get results
26
- result = Underpass::QL::Query.perform(bbox, op_query)
21
+ ```ruby
22
+ # require the library if it's not autoloaded
23
+ require 'underpass'
24
+ # create a bounding box in which the query will be run
25
+ f = RGeo::Geographic.spherical_factory
26
+ 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))')
27
+ # provide the query
28
+ op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
29
+ # perform the query and get your results
30
+ result = Underpass::QL::Query.perform(bbox, op_query)
31
+ ```
32
+
33
+ ## To Do
34
+
35
+ Have a look at the [issue tracker](https://github.com/haiafara/underpass/issues).
27
36
 
28
37
  ## Contributing
29
38
 
data/lib/underpass.rb CHANGED
@@ -13,7 +13,16 @@ end
13
13
  # Example usage
14
14
  #
15
15
  # require 'underpass'
16
+ # wkt = <<-WKT
17
+ # POLYGON ((
18
+ # 23.669 47.65,
19
+ # 23.725 47.65,
20
+ # 23.725 47.674,
21
+ # 23.669 47.674,
22
+ # 23.669 47.65
23
+ # ))
24
+ # WKT
16
25
  # 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))')
26
+ # bbox = f.parse_wkt(wkt)
18
27
  # op_query = 'way["heritage:operator"="lmi"]["ref:ro:lmi"="MM-II-m-B-04508"];'
19
28
  # Underpass::QL::Query.perform(bbox, op_query)
@@ -21,8 +21,12 @@ module Underpass
21
21
  end
22
22
 
23
23
  def matches
24
+ @nodes.each_value do |node|
25
+ @matches << point_from_node(node) if node.key?(:tags)
26
+ end
27
+
24
28
  @ways.each_value do |way|
25
- @matches << Underpass::QL::Shape.polygon_from_way(way, @nodes)
29
+ @matches << polygon_from_way(way, @nodes) if way.key?(:tags)
26
30
  end
27
31
 
28
32
  @matches
@@ -30,6 +34,14 @@ module Underpass
30
34
 
31
35
  private
32
36
 
37
+ def point_from_node(node)
38
+ Underpass::QL::Shape.point_from_node(node)
39
+ end
40
+
41
+ def polygon_from_way(way, nodes)
42
+ Underpass::QL::Shape.polygon_from_way(way, nodes)
43
+ end
44
+
33
45
  def extract_indexed_nodes(elements)
34
46
  nodes = elements.select { |e| e[:type] == 'node' }
35
47
  nodes.map { |e| [e[:id], e] }.to_h
@@ -4,8 +4,8 @@ module Underpass
4
4
  module QL
5
5
  # Deals with performing the Overpass API request
6
6
  class Request
7
- API_URI = 'https://overpass-api.de/api/interpreter'.freeze
8
- QUERY_TEMPLATE = <<-TEMPLATE.freeze
7
+ API_URI = 'https://overpass-api.de/api/interpreter'
8
+ QUERY_TEMPLATE = <<-TEMPLATE
9
9
  [out:json][timeout:25]BBOX;
10
10
  (
11
11
  QUERY
@@ -22,9 +22,14 @@ module Underpass
22
22
 
23
23
  # Performs the API request
24
24
  def run
25
- query = QUERY_TEMPLATE.sub('BBOX', @global_bbox)
26
- .sub('QUERY', @overpass_query)
27
- Net::HTTP.post_form(URI(API_URI), data: query)
25
+ Net::HTTP.post_form(URI(API_URI), data: build_query)
26
+ end
27
+
28
+ private
29
+
30
+ def build_query
31
+ QUERY_TEMPLATE.sub('BBOX', @global_bbox)
32
+ .sub('QUERY', @overpass_query)
28
33
  end
29
34
  end
30
35
  end
@@ -19,6 +19,11 @@ module Underpass
19
19
  )
20
20
  end
21
21
 
22
+ def self.point_from_node(node)
23
+ f = RGeo::Geographic.spherical_factory(srid: 4326)
24
+ f.point(node[:lon], node[:lat])
25
+ end
26
+
22
27
  # There should be some sort of 'decorator' to return an object
23
28
  # with the shape and a copy of the tags as
24
29
  # {
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Returns the version of the gem as a <tt>Gem::Version</tt>
4
+ module Underpass
5
+ # Prints the gem version as a string
6
+ #
7
+ # @return [String]
8
+ def self.gem_version
9
+ Gem::Version.new VERSION::STRING
10
+ end
11
+
12
+ # Used to generate the version string
13
+ module VERSION
14
+ MAJOR = 0
15
+ MINOR = 0
16
+ PATCH = 6
17
+
18
+ STRING = [MAJOR, MINOR, PATCH].join('.')
19
+ end
20
+ end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: underpass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janos Rusiczki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-26 00:00:00.000000000 Z
11
+ date: 2019-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rgeo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.0.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: 2.0.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.8.0
31
40
  - - "~>"
32
41
  - !ruby/object:Gem::Version
33
- version: 3.5.0
42
+ version: '3.8'
34
43
  type: :development
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.8.0
38
50
  - - "~>"
39
51
  - !ruby/object:Gem::Version
40
- version: 3.5.0
52
+ version: '3.8'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: simplecov
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +64,8 @@ dependencies:
52
64
  - - "~>"
53
65
  - !ruby/object:Gem::Version
54
66
  version: 0.16.0
55
- description: A library that makes it easy to query the Overpass API and translate
56
- its responses into RGeo objects.
67
+ description: " A library that makes it easy to query the Overpass API and translate
68
+ its responses into RGeo objects\n"
57
69
  email: janos.rusiczki@gmail.com
58
70
  executables: []
59
71
  extensions: []
@@ -68,10 +80,13 @@ files:
68
80
  - lib/underpass/ql/query.rb
69
81
  - lib/underpass/ql/request.rb
70
82
  - lib/underpass/ql/shape.rb
83
+ - lib/underpass/version.rb
71
84
  homepage: http://github.com/haiafara/underpass
72
85
  licenses:
73
86
  - MIT
74
- metadata: {}
87
+ metadata:
88
+ source_code_uri: http://github.com/haiafara/underpass
89
+ bug_tracker_uri: http://github.com/haiafara/underpass/issues
75
90
  post_install_message:
76
91
  rdoc_options: []
77
92
  require_paths: