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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36fb49b5596bf347fba3edc3edfcb183759bbb4a
4
- data.tar.gz: 7decc79f1a4e899b4b83215dd7cfa1c85e981383
3
+ metadata.gz: 750137fe1a67937f1af70ac82b622081630a898a
4
+ data.tar.gz: 5c9218d9ae4b48795ed2e5d2433ce249e3ec3b4b
5
5
  SHA512:
6
- metadata.gz: 2bc791fecc85ed41423694adc9553de8f4c929248e709d829e55a49c3d15d4aad6282bacde824931740c9df257e407eb1d2e26ccf9e9489876f56b9dcd53de21
7
- data.tar.gz: 3d57642cb60b466703a6b930e0a057915d0dcb36f7da5ded0136dcfc2414af3430f511df6a285d43db8e39364c6b4d909c8b59db4a4252dbbe94e9e0aa8bef51
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
- Command line utility to create geohexes
4
+ Geohex command line utility
5
+
5
6
  =======
6
7
  # Geohex::Gen
7
8
 
8
- Docs are WIP! Sorry 'bout that
9
+ ## Installation
9
10
 
10
- TODO: Write a gem description
11
+ $ gem install geohex-gen
11
12
 
12
- ## Installation
13
+ ## Usage
13
14
 
14
- Add this line to your application's Gemfile:
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
- gem 'geohex-gen'
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
- $ bundle
28
+ ### Return geohex 4-6 that includes a geohex
21
29
 
22
- Or install it yourself as:
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
- $ gem install geohex-gen
43
+ $shell> ghgen -g PC2266666
25
44
 
26
- ## Usage
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
 
@@ -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 = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.executables = 'ghgen'
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
@@ -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('-g GH') {|v| opts[:g]=v}
13
- opt.on('-r [RING]', Integer) {|v| opts[:r]=v}
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
- gh = opts[:g]
17
- ring = opts[:r] ? opts[:r] : 1
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
- puts GeoHex.decode(gh).neighbours(ring)
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
@@ -1,5 +1,5 @@
1
1
  module Geohex
2
2
  module Gen
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geohex-gen
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
  - Aki Atoji