overhelper 0.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/overhelper.rb +76 -0
  3. data/license.txt +9 -0
  4. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a8c9f94e0d90910eb04cdd285a22dc75a1c64bfd
4
+ data.tar.gz: 5de61ec3657caed2347ff899ef95e73174f3cc23
5
+ SHA512:
6
+ metadata.gz: 4119dfcc57afe021143fe8952a7ca226c6249b25b5492eca3679244dd6d28e74b08518b3765dfc2a1f2620bda62e5349a21f6071c4272404cda87ac7565f1b88
7
+ data.tar.gz: 85d8c69ff5c6c290390b751cdab7fe526a3fb80e25b9899bb87f77f09de9f562ad2be48d5e0483034a24c7eedfae06e699489eea5057f90d38e9396d0226afb7
@@ -0,0 +1,76 @@
1
+ # encoding: UTF-8
2
+ class Overhelper
3
+ def self.list_of_locations_from_overpass_into_array(list, data=[])
4
+ list.split(/[\n]+/m).each{|element|
5
+ element = Hash[[:lat, :lon].zip(element.split(/[\s]+/m))]
6
+ element[:lat] = element[:lat].to_f
7
+ element[:lon] = element[:lon].to_f
8
+ data << element
9
+ }
10
+ return data
11
+ end
12
+
13
+ EARTH_RADIUS_IN_M = 6371*1000
14
+ def self.distance_in_m(lat1, lon1, lat2, lon2)
15
+ =begin
16
+ * Computes distance between two points on Earth using Haversine formula
17
+ * Earth is assumed to be sphere, errors from assuming spherical geometry might be up to 0.55% crossing the equator
18
+ * source: https://en.wikipedia.org/wiki/Haversine_formula and http://www.movable-type.co.uk/scripts/latlong.html
19
+ =end
20
+ lat1 = lat1 * Math::PI / 180
21
+ lon1 = lon1 * Math::PI / 180
22
+ lat2 = lat2 * Math::PI / 180
23
+ lon2 = lon2 * Math::PI / 180
24
+
25
+ dLat = (lat2 - lat1).abs;
26
+ dLon = (lon2 - lon1).abs;
27
+
28
+ #a: square of half the chord length between the points
29
+ a = Math.sin(dLat / 2) * Math.sin(dLat / 2);
30
+ a += Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat2) * Math.cos(lat1);
31
+ angularDistanceInRadians = Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
32
+ delta_in_m = 2 * EARTH_RADIUS_IN_M * angularDistanceInRadians;
33
+ return delta_in_m
34
+ end
35
+
36
+
37
+ def self.nodes_to_dict(data)
38
+ node_library = {}
39
+ for element in data["elements"]
40
+ if element["type"] == "node"
41
+ saved = {}
42
+ saved[:lat] = element["lat"].to_f
43
+ saved[:lon] = element["lon"].to_f
44
+ node_library[element["id"]] = saved
45
+ end
46
+ end
47
+ return node_library
48
+ end
49
+
50
+ def self.convert_to_ways(json_string)
51
+ data = JSON.parse(json_string)
52
+
53
+ node_library = nodes_to_dict(data)
54
+
55
+ ways = []
56
+ for element in data["elements"]
57
+ if element["type"] == "way"
58
+ nodes_of_way = element["nodes"]
59
+ prev_node = nil
60
+ for node in nodes_of_way
61
+ if prev_node != nil
62
+ way = {}
63
+ way[:lat1] = (node_library[prev_node])[:lat]
64
+ way[:lon1] = (node_library[prev_node])[:lon]
65
+ way[:lat2] = (node_library[node])[:lat]
66
+ way[:lon2] = (node_library[node])[:lon]
67
+ ways << way
68
+ end
69
+ prev_node = node
70
+ end
71
+ end
72
+ end
73
+
74
+ return ways
75
+ end
76
+ end
@@ -0,0 +1,9 @@
1
+ This software and associated documentation files (the "Software") is
2
+ released under the CC0 Public Domain Dedication, version 1.0, as
3
+ published by Creative Commons. To the extent possible under law, the
4
+ author(s) have dedicated all copyright and related and neighboring
5
+ rights to the Software to the public domain worldwide. The Software is
6
+ distributed WITHOUT ANY WARRANTY.
7
+ If you did not receive a copy of the CC0 Public Domain Dedication
8
+ along with the Software, see
9
+ <http://creativecommons.org/publicdomain/zero/1.0/>
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overhelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mateusz Konieczny
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: overpass_turbo_helper
14
+ email:
15
+ - matkoniecz@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/overhelper.rb
21
+ - license.txt
22
+ homepage: https://github.com/matkoniecz/overhelper
23
+ licenses:
24
+ - CC0
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.8.23
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.6.4
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: overpass_turbo_helper.
46
+ test_files: []