overhelper 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6f6e6e6f6736db9a3c53a02df213dcbf07de6df2
4
- data.tar.gz: d5d6458f966fed3230ba0af0261fda4e956b7f41
2
+ SHA256:
3
+ metadata.gz: ded8daf087ebc7f8f69c3af78e61da00041064c5a0d782851ea4a5db493b31b3
4
+ data.tar.gz: 5cfe20eb9e49f70b11fdc9e0cbc417cf27e65c42f0a1b287808b786ad457e403
5
5
  SHA512:
6
- metadata.gz: 27e90774de971b98edf56f230607feeda3b8a37af0d582216b4d7f9a1840fe69d3421d5f285e67ec89db6f49ebafa09f2d2c9eb6d83864709f2975dee6db1811
7
- data.tar.gz: feeaa4ed75bc80f02ec52f13f82e75f205749490aff8d0acefaa6703e8a1634f085c87890dd37d0373e04c29f93f4e7beaf8c23a5a88e9227f0c63e276c320a1
6
+ metadata.gz: 4e445aad84de157fdf1b5e7637054849490caf9376fadb3037dd76a3f375fe77515dbfedc3c2c04d3d27bc0d57b9958327fdb2b5f834e4a8d63e2a62c1b8a793
7
+ data.tar.gz: 2ad4a79792a369a8375825e1329409065848f4e83b2360c0bed52924157d13c3d18051841e8ff7e3adee61222c3185541dc7b63a6c085eb3aa88d9c8a7add693
@@ -1,78 +1,80 @@
1
- # encoding: UTF-8
2
1
  require 'json'
2
+ require_relative 'overhelper/complex_query_builder'
3
+
4
+ include ComplexQueryBuilder
5
+
3
6
 
4
7
  class Overhelper
5
- def self.list_of_locations_from_overpass_into_array(list, data=[])
6
- list.split(/[\n]+/m).each{|element|
7
- element = Hash[[:lat, :lon].zip(element.split(/[\s]+/m))]
8
- element[:lat] = element[:lat].to_f
9
- element[:lon] = element[:lon].to_f
10
- data << element
11
- }
12
- return data
13
- end
8
+ def self.list_of_locations_from_overpass_into_array(list, data = [])
9
+ list.split(/[\n]+/m).each do |element|
10
+ element = Hash[[:lat, :lon].zip(element.split(/[\s]+/m))]
11
+ element[:lat] = element[:lat].to_f
12
+ element[:lon] = element[:lon].to_f
13
+ data << element
14
+ end
15
+ return data
16
+ end
14
17
 
15
- EARTH_RADIUS_IN_M = 6371*1000
16
- def self.distance_in_m(lat1, lon1, lat2, lon2)
18
+ EARTH_RADIUS_IN_M = 6371 * 1000
19
+ def self.distance_in_m(lat1, lon1, lat2, lon2)
17
20
  =begin
18
- * Computes distance between two points on Earth using Haversine formula
19
- * Earth is assumed to be sphere, errors from assuming spherical geometry might be up to 0.55% crossing the equator
20
- * source: https://en.wikipedia.org/wiki/Haversine_formula and http://www.movable-type.co.uk/scripts/latlong.html
21
+ * Computes distance between two points on Earth using Haversine formula
22
+ * Earth is assumed to be sphere, errors from assuming spherical geometry might be up to 0.55% crossing the equator
23
+ * source: https://en.wikipedia.org/wiki/Haversine_formula and http://www.movable-type.co.uk/scripts/latlong.html
21
24
  =end
22
- lat1 = lat1 * Math::PI / 180
23
- lon1 = lon1 * Math::PI / 180
24
- lat2 = lat2 * Math::PI / 180
25
- lon2 = lon2 * Math::PI / 180
25
+ lat1 = lat1 * Math::PI / 180
26
+ lon1 = lon1 * Math::PI / 180
27
+ lat2 = lat2 * Math::PI / 180
28
+ lon2 = lon2 * Math::PI / 180
29
+
30
+ dLat = (lat2 - lat1).abs
31
+ dLon = (lon2 - lon1).abs
26
32
 
27
- dLat = (lat2 - lat1).abs;
28
- dLon = (lon2 - lon1).abs;
33
+ # a: square of half the chord length between the points
34
+ a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
35
+ a += Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat2) * Math.cos(lat1)
36
+ angularDistanceInRadians = Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
37
+ delta_in_m = 2 * EARTH_RADIUS_IN_M * angularDistanceInRadians
38
+ return delta_in_m
39
+ end
29
40
 
30
- #a: square of half the chord length between the points
31
- a = Math.sin(dLat / 2) * Math.sin(dLat / 2);
32
- a += Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat2) * Math.cos(lat1);
33
- angularDistanceInRadians = Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
34
- delta_in_m = 2 * EARTH_RADIUS_IN_M * angularDistanceInRadians;
35
- return delta_in_m
36
- end
41
+ def self.nodes_to_dict(data)
42
+ node_library = {}
43
+ data["elements"].each do |element|
44
+ next unless element["type"] == "node"
37
45
 
46
+ saved = {}
47
+ saved[:lat] = element["lat"].to_f
48
+ saved[:lon] = element["lon"].to_f
49
+ node_library[element["id"]] = saved
50
+ end
51
+ return node_library
52
+ end
38
53
 
39
- def self.nodes_to_dict(data)
40
- node_library = {}
41
- for element in data["elements"]
42
- if element["type"] == "node"
43
- saved = {}
44
- saved[:lat] = element["lat"].to_f
45
- saved[:lon] = element["lon"].to_f
46
- node_library[element["id"]] = saved
47
- end
48
- end
49
- return node_library
50
- end
54
+ def self.convert_to_ways(json_string)
55
+ data = JSON.parse(json_string)
51
56
 
52
- def self.convert_to_ways(json_string)
53
- data = JSON.parse(json_string)
57
+ node_library = nodes_to_dict(data)
54
58
 
55
- node_library = nodes_to_dict(data)
59
+ ways = []
60
+ data["elements"].each do |element|
61
+ next unless element["type"] == "way"
56
62
 
57
- ways = []
58
- for element in data["elements"]
59
- if element["type"] == "way"
60
- nodes_of_way = element["nodes"]
61
- prev_node = nil
62
- for node in nodes_of_way
63
- if prev_node != nil
64
- way = {}
65
- way[:lat1] = (node_library[prev_node])[:lat]
66
- way[:lon1] = (node_library[prev_node])[:lon]
67
- way[:lat2] = (node_library[node])[:lat]
68
- way[:lon2] = (node_library[node])[:lon]
69
- ways << way
70
- end
71
- prev_node = node
72
- end
73
- end
74
- end
63
+ nodes_of_way = element["nodes"]
64
+ prev_node = nil
65
+ nodes_of_way.each do |node|
66
+ unless prev_node.nil?
67
+ way = {}
68
+ way[:lat1] = (node_library[prev_node])[:lat]
69
+ way[:lon1] = (node_library[prev_node])[:lon]
70
+ way[:lat2] = (node_library[node])[:lat]
71
+ way[:lon2] = (node_library[node])[:lon]
72
+ ways << way
73
+ end
74
+ prev_node = node
75
+ end
76
+ end
75
77
 
76
- return ways
77
- end
78
- end
78
+ return ways
79
+ end
80
+ end
@@ -0,0 +1,38 @@
1
+ module ComplexQueryBuilder
2
+ def self.filter_across_named_region(filter, name)
3
+ name_filter = CartoCSSHelper::OverpassQueryGenerator.turn_tag_into_overpass_filter(['name', name])
4
+ return "[out:json][timeout:2500];
5
+ area" + name_filter + "->.searchArea;
6
+ (
7
+ node#{filter}(area.searchArea);
8
+ way#{filter}(area.searchArea);
9
+ relation#{filter}(area.searchArea);
10
+ );
11
+ out meta;
12
+ >;
13
+ out meta qt;"
14
+ end
15
+
16
+ # tag negation is very slow - overpass will sometimes allow this type of query while using tag!=* will cause it to fail
17
+ def self.two_pass_filter_across_named_region(filter, negative_filter, name)
18
+ name_filter = CartoCSSHelper::OverpassQueryGenerator.turn_tag_into_overpass_filter(['name', name])
19
+ return "[out:json][timeout:2500];
20
+ area" + name_filter + "->.searchArea;
21
+ (
22
+ way#{filter}(area.searchArea);
23
+ node#{filter}(area.searchArea);
24
+ relation#{filter}(area.searchArea);
25
+ )-> .a;
26
+ (
27
+ way#{negative_filter}(area.searchArea);
28
+ node#{negative_filter}(area.searchArea);
29
+ relation#{negative_filter}(area.searchArea);
30
+ ) -> .b;
31
+ (
32
+ .a - .b;
33
+ );
34
+ out meta;
35
+ >;
36
+ out meta qt;"
37
+ end
38
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overhelper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Konieczny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: matkoniecz-ruby-style
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: overpass_turbo_helper
14
28
  email:
15
29
  - matkoniecz@gmail.com
@@ -18,6 +32,7 @@ extensions: []
18
32
  extra_rdoc_files: []
19
33
  files:
20
34
  - lib/overhelper.rb
35
+ - lib/overhelper/complex_query_builder.rb
21
36
  - license.txt
22
37
  homepage: https://github.com/matkoniecz/overhelper
23
38
  licenses:
@@ -38,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
53
  - !ruby/object:Gem::Version
39
54
  version: 1.8.23
40
55
  requirements: []
41
- rubyforge_project:
42
- rubygems_version: 2.6.4
56
+ rubygems_version: 3.0.4
43
57
  signing_key:
44
58
  specification_version: 4
45
59
  summary: overpass_turbo_helper.