Module: KMLUtils
- Included in:
- KMLMaker
- Defined in:
- lib/kml_maker.rb
Overview
Utilities for KML generation
Instance Method Summary collapse
-
#create_circle(center, radius, nb_points = 400) ⇒ Array<Array>
Create circle around a center.
-
#create_ellipse(center, hradius, vradius, angle = 0, nb_points = 400) ⇒ Array<Array>
Create ellipse around a center, given horizontal and vertical radii.
-
#create_line(center, length, angle = 0) ⇒ Array<Array>
create a line apart from a center, given a length and an angle.
- #meters_to_degrees(meters) ⇒ Object
Instance Method Details
#create_circle(center, radius, nb_points = 400) ⇒ Array<Array>
Create circle around a center
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
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
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 |