Class: Road

Inherits:
Object
  • Object
show all
Defined in:
lib/geonames_local/features/road.rb

Overview

Road/Street/Via/Autoban

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys, vals, nation = nil, city = nil) ⇒ Road

Returns a new instance of Road.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/geonames_local/features/road.rb', line 7

def initialize(keys, vals, nation = nil, city = nil)
  s = vals.split("\t")
  r = {}
  keys.each_with_index do |k, i|
    r[k] = s[i]
  end
  @name = r[:name]
  @zone = r[:zone]
  kind  = r[:kind] || @name.split(' ')[0]
  @geom = parse_geom(r[:geom])
  @kind = parse_kind(kind)
  @city = city
  @nation = nation
  @table = :roads
end

Instance Attribute Details

#cityObject (readonly)

Returns the value of attribute city.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def city
  @city
end

#geomObject

Returns the value of attribute geom.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def geom
  @geom
end

#kindObject (readonly)

Returns the value of attribute kind.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def name
  @name
end

#nationObject (readonly)

Returns the value of attribute nation.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def nation
  @nation
end

#regionObject (readonly)

Returns the value of attribute region.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def region
  @region
end

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def table
  @table
end

#zoneObject (readonly)

Returns the value of attribute zone.



5
6
7
# File 'lib/geonames_local/features/road.rb', line 5

def zone
  @zone
end

Instance Method Details

#parse_geom(hex) ⇒ Object



23
24
25
26
27
28
# File 'lib/geonames_local/features/road.rb', line 23

def parse_geom(hex)
  if hex =~ /^SRID/ # PG 8.3 support
    hex = hex.split(';')[1]
  end
  GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(hex)
end

#parse_kind(k) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/geonames_local/features/road.rb', line 32

def parse_kind(k)
  case k
    when /^tun/i then :tunnel
    when /^av/i then :avenue
    when /^r/i then :street
    when /\d/ then :road
    else :unknown
  end
end