hk_geo 0.1.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.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ = 0.1.0
2
+
3
+ Initial commit
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Francis Chong
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ Manifest.txt
2
+ README.txt
3
+ History.txt
4
+ Rakefile
5
+ LICENSE
6
+ lib/hk_geo.rb
7
+ lib/hk_geo/converter.rb
data/README.txt ADDED
@@ -0,0 +1,31 @@
1
+ = HkGeo
2
+
3
+ == Description
4
+
5
+ A Geo location conversion API for HK.
6
+
7
+ == Dependency
8
+
9
+ * mechanize
10
+ * hoe (build)
11
+
12
+ == Usage
13
+
14
+ By default, convert the HK80 location to WGS84/ITRF96
15
+
16
+ require 'hk_geo'
17
+ result = HkGeo::Converter.convert("835352.749", "815640.774")
18
+ >> ["22.457521648", "113.976469709"]
19
+
20
+ You may specify other conversion
21
+
22
+ require 'hk_geo'
23
+ result = HkGeo::Converter.convert("835352.749", "815640.774", HkGeo::SYSTEM_HK80, HkGeo::SYSTEM_ITRF96, HkGeo::UNIT_DM)
24
+ >> ["22.2745130", "113.5858818"]
25
+
26
+ Check the test for more info.
27
+
28
+ == Credit
29
+
30
+ This api rely on the online conversion tool from Survey and Mapping Office. http://www.geodetic.gov.hk/smo/tform/tra_tform.aspx
31
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+
4
+ $: << 'lib'
5
+ require './lib/hk_geo.rb'
6
+
7
+ Hoe.plugin :gemcutter
8
+ Hoe.spec 'hk_geo' do
9
+ developer('Francis Chong', 'francis@ignition.hk')
10
+ end
11
+
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+
4
+ module HkGeo
5
+ SYSTEM_HK80 = "HK1980"
6
+ SYSTEM_HKLATLONG = "HKLatLong"
7
+ SYSTEM_ITRF96 = "ITRF96"
8
+ SYSTEM_UTM84 = "UTM84"
9
+ SYSTEM_UTMGR = "UTMGR"
10
+
11
+ UNIT_DMS = "DMS"
12
+ UNIT_DEC = "DecDegree"
13
+ UNIT_DM = "DM"
14
+ UNITS = [UNIT_DMS, UNIT_DEC, UNIT_DM]
15
+
16
+ class Converter
17
+ SERVICE_URL = "http://www.geodetic.gov.hk/smo/tform/tra_tform.aspx"
18
+
19
+ def self.convert(north, east, from_coord_system=SYSTEM_HK80, to_coord_system=SYSTEM_ITRF96, unit_type=UNIT_DEC)
20
+ agent = Mechanize.new do |agent|
21
+ agent.user_agent_alias = 'Mac Safari'
22
+ end
23
+
24
+ page = agent.get(SERVICE_URL)
25
+ form = page.form_with(:name => 'form1')
26
+ form.DropDownList1 = "in#{from_coord_system}"
27
+ form.DropDownList2 = "out#{to_coord_system}"
28
+ form.TextBox12 = north.to_s
29
+ form.TextBox13 = east.to_s
30
+ form.radiobuttons_with(:name => 'RadioButtonList1')[UNITS.index(unit_type)].check
31
+ result = form.submit(form.buttons.first)
32
+
33
+ doc = Nokogiri::HTML(result.body)
34
+ [doc.css("#Label16").text, doc.css("#Label17").text]
35
+ end
36
+
37
+ def self.systems
38
+ [SYSTEM_HK80, SYSTEM_HKLATLONG, SYSTEM_ITRF96, SYSTEM_UTM84, SYSTEM_UTMGR]
39
+ end
40
+ end
41
+ end
data/lib/hk_geo.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'hk_geo/converter'
2
+
3
+ module HkGeo
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,18 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "hk_geo"
4
+
5
+ class TestHkGeo < Test::Unit::TestCase
6
+ def test_fetch
7
+ result = HkGeo::Converter.convert("835352.749", "815640.774")
8
+ assert_not_nil(result)
9
+ assert_equal("22.457521648", result[0])
10
+ assert_equal("113.976469709", result[1])
11
+
12
+ result = HkGeo::Converter.convert("835352.749", "815640.774", HkGeo::SYSTEM_HK80, HkGeo::SYSTEM_ITRF96, HkGeo::UNIT_DM)
13
+ assert_not_nil(result)
14
+ assert_equal("22.2745130", result[0])
15
+ assert_equal("113.5858818", result[1])
16
+
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hk_geo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Francis Chong
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-24 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: hoe
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 35
30
+ segments:
31
+ - 2
32
+ - 9
33
+ - 4
34
+ version: 2.9.4
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A Geo location conversion API for HK.
38
+ email:
39
+ - francis@ignition.hk
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - Manifest.txt
46
+ - README.txt
47
+ - History.txt
48
+ files:
49
+ - Manifest.txt
50
+ - README.txt
51
+ - History.txt
52
+ - Rakefile
53
+ - LICENSE
54
+ - lib/hk_geo.rb
55
+ - lib/hk_geo/converter.rb
56
+ - test/test_hk_geo.rb
57
+ - .gemtest
58
+ has_rdoc: true
59
+ homepage:
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --main
65
+ - README.txt
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ requirements: []
87
+
88
+ rubyforge_project: hk_geo
89
+ rubygems_version: 1.6.2
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: A Geo location conversion API for HK.
93
+ test_files:
94
+ - test/test_hk_geo.rb