Class: Terragona::Base
- Inherits:
-
Object
- Object
- Terragona::Base
- Defined in:
- lib/terragona/base.rb
Instance Method Summary collapse
- #create_polygons(names, options = {}) ⇒ Object
- #create_polygons_family(names, parents_table, children_table, opts = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
7 8 9 10 |
# File 'lib/terragona/base.rb', line 7 def initialize(={}) @options= @minimal_polygon_points = [:minimal_polygon_points] || 5 end |
Instance Method Details
#create_polygons(names, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/terragona/base.rb', line 12 def create_polygons(names,={}) opts=@options.merge() concave_hull = ConcaveHull.new(opts) if not opts[:dont_create_polygons] names.map{|n| name = @geonames.search(n) if name[:points].count < @minimal_polygon_points puts "No points for #{n[:name]}" next end unless opts[:dont_create_polygons] if concave_hull.perform(name[:points],name[:place_name],name[:place_id]) puts "Polygon created for #{n[:name]}" end end name } end |
#create_polygons_family(names, parents_table, children_table, opts = {}) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/terragona/base.rb', line 34 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 |