geohex-gen 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 +4 -4
- data/README.md +72 -12
- data/geohex-gen.gemspec +1 -1
- data/lib/geohex/gen.rb +42 -5
- data/lib/geohex/gen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 750137fe1a67937f1af70ac82b622081630a898a
|
4
|
+
data.tar.gz: 5c9218d9ae4b48795ed2e5d2433ce249e3ec3b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa57f82894d4aedc1dcb47a06dc6a68aeb4204e688239ab822e6a3473be72b96af2b0eb44f6c4d66d5e47d6f032354670839aef00e8f193379e2d0cb40030ea
|
7
|
+
data.tar.gz: b316c5aae1fed2e3fa290832810ee6298fb29a5266d7444d38bc63f680da7287adbcc5eaeb1a879027784657707e1798abb692a6a784fab21c7f53b1760561c8
|
data/README.md
CHANGED
@@ -1,31 +1,91 @@
|
|
1
1
|
geohex-gen
|
2
2
|
==========
|
3
3
|
|
4
|
-
|
4
|
+
Geohex command line utility
|
5
|
+
|
5
6
|
=======
|
6
7
|
# Geohex::Gen
|
7
8
|
|
8
|
-
|
9
|
+
## Installation
|
9
10
|
|
10
|
-
|
11
|
+
$ gem install geohex-gen
|
11
12
|
|
12
|
-
##
|
13
|
+
## Usage
|
13
14
|
|
14
|
-
|
15
|
+
This gem installs a command line tool named ghgen that:
|
16
|
+
|
17
|
+
* Given lat, lon return geohex level 10 code.
|
18
|
+
* Given a GH (any size), display center lat/lon and show GH4/5/6 that contains this location
|
19
|
+
* Given a GH (any size) and a ring size, display geohex codes that form the ring(s).
|
15
20
|
|
16
|
-
|
21
|
+
Usage: ghgen [options]
|
22
|
+
-a LAT Latitude. If used, must have longitude also
|
23
|
+
-o LON Longitude. If used, must have latitude also
|
24
|
+
-g GH Specify center geohex directly
|
25
|
+
-r [RING] Number of rings around center
|
17
26
|
|
18
|
-
And then execute:
|
19
27
|
|
20
|
-
|
28
|
+
### Return geohex 4-6 that includes a geohex
|
21
29
|
|
22
|
-
|
30
|
+
$shell> ghgen -g PC22713455
|
31
|
+
|
32
|
+
Center GH is PC22713455, located at 32.91066810490208, -117.21383935375704
|
33
|
+
|
34
|
+
This location is included in
|
35
|
+
|
36
|
+
GH4: PC2271
|
37
|
+
GH5: PC22713
|
38
|
+
GH6: PC227134
|
39
|
+
|
40
|
+
Note that you can't always truncate a GH string to get to larger size.
|
41
|
+
Geohexes that are on apex ending with 2 or 6 ends up on parent with different code system. ghgen handles this properly.
|
23
42
|
|
24
|
-
$
|
43
|
+
$shell> ghgen -g PC2266666
|
25
44
|
|
26
|
-
|
45
|
+
Center GH is PC2266666, located at 32.70505659484853, -115.56470050297207
|
46
|
+
|
47
|
+
This location is included in
|
48
|
+
|
49
|
+
GH4: PC2500
|
50
|
+
GH5: PC25000
|
51
|
+
GH6: PC218888
|
52
|
+
|
53
|
+
|
54
|
+
### Get geohex from lat lon
|
55
|
+
|
56
|
+
$shell> ghgen -a 32.90475787738992 -o -117.20164609053498
|
57
|
+
|
58
|
+
Center GH is PC2271344444, located at 32.90475787738992, -117.20164609053498
|
59
|
+
|
60
|
+
This location is included in
|
61
|
+
|
62
|
+
GH4: PC2271
|
63
|
+
GH5: PC22713
|
64
|
+
GH6: PC227134
|
65
|
+
|
66
|
+
|
67
|
+
### Get a list of Geohexes that form one or more ring around the center GH
|
68
|
+
|
69
|
+
$shell> ghgen -g PC22751 -r 1
|
70
|
+
|
71
|
+
Center GH is PC22751, located at 33.14380613603259, -117.3662551440329
|
72
|
+
|
73
|
+
This location is included in
|
74
|
+
|
75
|
+
GH4: PC2275
|
76
|
+
GH5: PC22751
|
77
|
+
GH6: PC227514
|
78
|
+
|
79
|
+
Center PC22751, Ring(s) 1:
|
80
|
+
PC22727
|
81
|
+
PC22754
|
82
|
+
PC22752
|
83
|
+
PC22726
|
84
|
+
PC22755
|
85
|
+
PC22750
|
86
|
+
|
87
|
+
You can specify ring size with lat/lon, but the ring is always in GH10.
|
27
88
|
|
28
|
-
TODO: Write usage instructions here
|
29
89
|
|
30
90
|
## Contributing
|
31
91
|
|
data/geohex-gen.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables =
|
17
|
+
spec.executables = 'ghgen'
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
data/lib/geohex/gen.rb
CHANGED
@@ -6,17 +6,54 @@ require 'geo_hex'
|
|
6
6
|
module Geohex
|
7
7
|
module Gen
|
8
8
|
class Process
|
9
|
+
|
10
|
+
def self.gh_to_ll gh
|
11
|
+
zone = GeoHex.decode(gh)
|
12
|
+
[zone.lat, zone.lon]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.convert_gh gh, level
|
16
|
+
lat, lon = self.gh_to_ll gh
|
17
|
+
GeoHex.encode(lat, lon, level)
|
18
|
+
end
|
19
|
+
|
9
20
|
def self.process
|
10
21
|
opt = OptionParser.new
|
11
22
|
opts={}
|
12
|
-
opt.on('-
|
13
|
-
opt.on('-
|
23
|
+
opt.on('-a LAT', Float, "Latitude. If used, must have longitude also") { |v| opts[:a]=v }
|
24
|
+
opt.on('-o LON', Float, "Longitude. If used, must have latitude also") { |v| opts[:o]=v }
|
25
|
+
opt.on('-g GH', String, "Specify center geohex directly") { |v| opts[:g]=v }
|
26
|
+
opt.on('-r [RING]', Integer, "Number of rings around center") { |v| opts[:r]=v }
|
14
27
|
|
15
28
|
opt.parse!(ARGV)
|
16
|
-
|
17
|
-
ring
|
29
|
+
centergh = opts[:g]
|
30
|
+
ring = opts[:r] ? opts[:r] : nil
|
31
|
+
|
32
|
+
if !centergh
|
33
|
+
lat = opts[:a]
|
34
|
+
lon = opts[:o]
|
35
|
+
centergh = GeoHex.encode(lat, lon, 10).code if lat and lon
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
if centergh
|
40
|
+
gh_lat, gh_lon = self.gh_to_ll centergh
|
41
|
+
puts ""
|
42
|
+
puts "Center GH is #{centergh}, located at #{gh_lat}, #{gh_lon}"
|
43
|
+
puts ""
|
44
|
+
puts "This location is included in"
|
45
|
+
puts ""
|
46
|
+
puts "GH4: #{self.convert_gh centergh, 4}"
|
47
|
+
puts "GH5: #{self.convert_gh centergh, 5}"
|
48
|
+
puts "GH6: #{self.convert_gh centergh, 6}"
|
18
49
|
|
19
|
-
|
50
|
+
if ring
|
51
|
+
puts ""
|
52
|
+
puts "Center #{centergh}, Ring(s) #{ring}:"
|
53
|
+
puts GeoHex.decode(centergh).neighbours(ring)
|
54
|
+
puts ""
|
55
|
+
end
|
56
|
+
end
|
20
57
|
end
|
21
58
|
end
|
22
59
|
end
|
data/lib/geohex/gen/version.rb
CHANGED