Module: KMLUtils

Included in:
KMLMaker
Defined in:
lib/kml_maker.rb

Overview

Utilities for KML generation

Instance Method Summary collapse

Instance Method Details

#create_circle(center, radius, nb_points = 400) ⇒ Array<Array>

Create circle around a center

Parameters:

  • center (Array)

    the center of the circle

  • radius (Float)

    the radius of the circle

  • nb_points (Integer) (defaults to: 400)

    the number of points to create the circle

Returns:

  • (Array<Array>)

    the list of points of the circle



17
18
19
20
21
22
23
24
25
# File 'lib/kml_maker.rb', line 17

def create_circle(center, radius, nb_points = 400)
  x, y = center
  points = []
  angle_step = 2 * Math::PI / nb_points
  nb_points.times do |i|
    points << [x + radius * Math.cos(i * angle_step), y + radius * Math.sin(i * angle_step)]
  end
  points
end

#create_ellipse(center, hradius, vradius, angle = 0, nb_points = 400) ⇒ Array<Array>

Create ellipse around a center, given horizontal and vertical radii

Parameters:

  • center (Array)

    the center of the ellipse

  • hradius (Float)

    the horizontal radius of the ellipse

  • vradius (Float)

    the vertical radius of the ellipse

  • angle (Float) (defaults to: 0)

    the angle of the ellipse

  • nb_points (Integer) (defaults to: 400)

    the number of points to create the ellipse

Returns:

  • (Array<Array>)

    the list of points of the ellipse



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kml_maker.rb', line 34

def create_ellipse(center, hradius, vradius, angle = 0, nb_points = 400)
  x, y = center
  points = []
  angle = angle * Math::PI / 180
  angle_step = 2 * Math::PI / nb_points
  nb_points.times do |i|
    points << [x + hradius * Math.cos(i * angle_step + angle),
               y + vradius * Math.sin(i * angle_step + angle)]
  end
  points << points[0]
  points
end

#create_line(center, length, angle = 0) ⇒ Array<Array>

create a line apart from a center, given a length and an angle

Parameters:

  • center (Array<float>)

    the center of the line

  • length (Float)

    the length of the line

  • angle (Float) (defaults to: 0)

    the angle of the line

Returns:

  • (Array<Array>)

    the list of points of the line



52
53
54
55
56
57
58
59
# File 'lib/kml_maker.rb', line 52

def create_line(center, length, angle = 0)
  points = []
  angle = angle * Math::PI / 180
  points << [center[0] + length * Math.cos(angle), center[1] + length * Math.sin(angle)]
  points << [center[0], center[1]]
  points << [center[0] - length * Math.cos(angle), center[1] - length * Math.sin(angle)]
  points
end

#meters_to_degrees(meters) ⇒ Object



8
9
10
# File 'lib/kml_maker.rb', line 8

def meters_to_degrees(meters)
  meters / 111_111
end