Class: Terragona::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/terragona/base.rb

Direct Known Subclasses

CSVParser, FromHash, Geonames::API, Geonames::Dump

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/terragona/base.rb', line 8

def initialize(options={})
  @options=options
  @minimal_polygon_points = options[:minimal_polygon_points] || 5
end

Instance Method Details

#create_polygons(names, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/terragona/base.rb', line 13

def create_polygons(names,options={})
  opts=@options.merge(options)

  concave_hull = ConcaveHull.new(opts)

  if (!names or names.empty?) and
      (@input.class == Generic::CSVParser or @input.class == Generic::FromHash)
    n = {:name => :generic}
    name = @input.search(n)
    process_points(n,name,concave_hull,opts)
    return [name]
  end

  names.map{|n|
    name = @input.search(n)
    next unless process_points(n,name,concave_hull,opts)
    name
  }.compact
end

#create_polygons_family(names, parents_table, children_table, opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/terragona/base.rb', line 33

def create_polygons_family(names,parents_table,children_table,opts={})
  created_names = create_polygons(names,opts.merge({:table => parents_table}))
  children = []
  created_names.each {|c|
    children.concat(c[:children_places])
  }
  create_polygons(children,opts.merge({:table => children_table}))
end