Class: HkGeo::Converter

Inherits:
Object
  • Object
show all
Defined in:
lib/hk_geo/converter.rb

Constant Summary collapse

SERVICE_URL =
"http://www.geodetic.gov.hk/smo/tform/tra_tform.aspx"

Class Method Summary collapse

Class Method Details

.convert(north, east, from_coord_system = SYSTEM_HK80, to_coord_system = SYSTEM_ITRF96, unit_type = UNIT_DEC) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hk_geo/converter.rb', line 18

def self.convert(north, east, from_coord_system=SYSTEM_HK80, to_coord_system=SYSTEM_ITRF96, unit_type=UNIT_DEC)
  agent = Mechanize.new do |agent|
    agent.user_agent_alias = 'Mac Safari'
  end

  page = agent.get(SERVICE_URL) 
  form = page.form_with(:name => 'form1')
  form.DropDownList1 = "in#{from_coord_system}"
  form.DropDownList2 = "out#{to_coord_system}"
  form.TextBox12 = north.to_s
  form.TextBox13 = east.to_s
  form.radiobuttons_with(:name => 'RadioButtonList1')[UNITS.index(unit_type)].check
  result = form.submit(form.buttons.first)

  doc = Nokogiri::HTML(result.body)
  [doc.css("#Label16").text, doc.css("#Label17").text]
end

.systemsObject



36
37
38
# File 'lib/hk_geo/converter.rb', line 36

def self.systems
  [SYSTEM_HK80, SYSTEM_HKLATLONG, SYSTEM_ITRF96, SYSTEM_UTM84, SYSTEM_UTMGR]
end