Class: Terragona::ConcaveHull

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ConcaveHull

Returns a new instance of ConcaveHull.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/terragona/concave_hull.rb', line 6

def initialize(options = {})
  @projection = options[:projection] || 4326
  @table  = options[:table] || 'concave_hull'
  @target_percent = options[:target_percent] || 0.8
  @allow_holes = options[:allow_holes]
  @allow_holes = false if @allow_holes.nil?
  @max_distance_ratio = options[:max_distance_ratio] || 1.6

  db_options={
      :database=> options[:db_name],
      :user=> options[:db_username],
      :password=> options[:db_password],
      :host=> options[:db_host] || 'localhost',
      :port=> options[:db_port] || 5432,
      :max_connections=> options[:db_max_connections] || 10
  }

  @db = Sequel.postgres(db_options)

  create_table
end

Instance Method Details

#perform(points, tags, id) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/terragona/concave_hull.rb', line 28

def perform(points,tags,id)
  filtered_points=filter_points_by_distance(points)
  points_stringified=stringify_points(filtered_points)

  query = %Q{
  ST_ConcaveHull(
    ST_GeomFromText(
      'MULTIPOINT(
        #{points_stringified}
      )',
      #{@projection}
    ),
    #{@target_percent},
    #{@allow_holes})
  }

  create_concave_hull(query,tags,filtered_points.count,id)
end