wheretz 0.0.1 → 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 +4 -4
- data/Changelog.md +9 -0
- data/README.md +6 -3
- data/lib/wheretz.rb +23 -4
- data/wheretz.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68585df38909578b7e89a731f3ee4f89c0600787
|
4
|
+
data.tar.gz: 5ef6f73de30fe6f954b132ec74f8407b33a619af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e84235f01b2c82c75a9af7eec670b598641071f7f1262bce3d0f6980daa6b9635f7a630880ba6ca26d6004645c684d4b250f9abe051372a345c62a77616edb72
|
7
|
+
data.tar.gz: 74bc547aa0bd00c26a4e9cdcbb0036e49ca68a8f7c4c32293f1eee6830358be22c349cb636c96a728f1b2f80faac05e206317a69bfc85410d689e7f579c94c1f
|
data/Changelog.md
ADDED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ WhereTZ.get(50.004444, 36.231389)
|
|
32
32
|
# you should have tzinfo gem installed, wheretz doesn't list it as dependency
|
33
33
|
```
|
34
34
|
|
35
|
-
From
|
35
|
+
From command-line, after gem installed:
|
36
36
|
|
37
37
|
```bash
|
38
38
|
wheretz 50.004444,36.231389
|
@@ -51,11 +51,14 @@ wheretz 50.004444,36.231389
|
|
51
51
|
4. If there's several intersecting bounding boxes, `WhereTZ` reads only
|
52
52
|
relevant timezone files (which are not very large) and checks which
|
53
53
|
polygon actually contains the point.
|
54
|
+
5. **Added in 0.0.2** If point occures outside any of polygons, find
|
55
|
+
the closest one (it's last resort for really rare cases and slower
|
56
|
+
than other approaches).
|
54
57
|
|
55
58
|
## Known problems
|
56
59
|
|
57
|
-
* On "bounding box only" check, some points deeply in sea (and
|
58
|
-
belonging to no timezone polygon) can be
|
60
|
+
* On "bounding box only" check, some points deeply in sea (and actually
|
61
|
+
belonging to no timezone polygon) can be wrongly guessed as belonging
|
59
62
|
to some timezone;
|
60
63
|
* Loading/unloading `.geojson` files can be uneffective when called
|
61
64
|
multiple times; future releases will provide option for preserve
|
data/lib/wheretz.rb
CHANGED
@@ -8,7 +8,7 @@ require 'geo_ruby/geojson'
|
|
8
8
|
# ```ruby
|
9
9
|
# WhereTZ.lookup(50.004444, 36.231389)
|
10
10
|
# # => 'Europe/Kiev'
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# WhereTZ.get(50.004444, 36.231389)
|
13
13
|
# # => #<TZInfo::DataTimezone: Europe/Kiev>
|
14
14
|
# ```
|
@@ -80,17 +80,36 @@ module WhereTZ
|
|
80
80
|
def lookup_geo(lat, lng, candidates)
|
81
81
|
point = GeoRuby::SimpleFeatures::Point.from_coordinates([lng, lat])
|
82
82
|
|
83
|
-
|
83
|
+
polygons = candidates.map{|fname, zone, *|
|
84
84
|
[zone, PARSER.parse(File.read(fname)).features.first.geometry]
|
85
|
-
}
|
85
|
+
}
|
86
|
+
candidates = polygons.select{|_, multipolygon|
|
86
87
|
multipolygon.geometries.any?{|polygon| polygon.contains_point?(point)}
|
87
88
|
}
|
88
89
|
|
89
90
|
case candidates.size
|
90
|
-
when 0 then
|
91
|
+
when 0 then guess_outside(point, polygons)
|
91
92
|
when 1 then candidates.first.first
|
92
93
|
else
|
93
94
|
fail(AmbigousTimezone, "Ambigous timezone: #{candidates.map(&:first)}")
|
94
95
|
end
|
95
96
|
end
|
97
|
+
|
98
|
+
# Last resort: pretty slow check for the cases when the point
|
99
|
+
# is slightly outside polygons.
|
100
|
+
# See https://github.com/zverok/wheretz/issues/4
|
101
|
+
def guess_outside(point, polygons)
|
102
|
+
# create pairs [timezone, distance to closest point of its polygon]
|
103
|
+
distances = polygons.map{|zone, multipolygon|
|
104
|
+
[
|
105
|
+
zone,
|
106
|
+
multipolygon.geometries.map(&:rings).flatten.
|
107
|
+
map{|p| p.ellipsoidal_distance(point)}.min
|
108
|
+
]
|
109
|
+
}
|
110
|
+
|
111
|
+
# FIXME: maybe need some tolerance range for maximal reasonable distance?
|
112
|
+
|
113
|
+
distances.sort_by(&:last).first.first
|
114
|
+
end
|
96
115
|
end
|
data/wheretz.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wheretz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Shepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: georuby
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".yardopts"
|
119
|
+
- Changelog.md
|
119
120
|
- LICENSE.txt
|
120
121
|
- README.md
|
121
122
|
- bin/wheretz
|