Class: Gull::Polygon
- Inherits:
-
Object
- Object
- Gull::Polygon
- Defined in:
- lib/gull/polygon.rb
Overview
Represents the geographic boundary of an alert as a series of lat/lon coordinate pairs. Coordinates are stored in [lat, lon] order.
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
Returns the value of attribute coordinates.
Instance Method Summary collapse
-
#initialize(coords) ⇒ Polygon
constructor
Accepts GeoJSON coordinates ([lon, lat]) and stores them as [lat, lon].
-
#to_s ⇒ Object
Returns coordinates as "lat,lon lat,lon ..." string.
-
#to_wkt ⇒ Object
Returns coordinates in Well-Known Text format.
Constructor Details
#initialize(coords) ⇒ Polygon
Accepts GeoJSON coordinates ([lon, lat]) and stores them as [lat, lon].
12 13 14 |
# File 'lib/gull/polygon.rb', line 12 def initialize(coords) self.coordinates = coords.map { |point| [point[1], point[0]] } end |
Instance Attribute Details
#coordinates ⇒ Object
Returns the value of attribute coordinates.
8 9 10 |
# File 'lib/gull/polygon.rb', line 8 def coordinates @coordinates end |
Instance Method Details
#to_s ⇒ Object
Returns coordinates as "lat,lon lat,lon ..." string.
17 18 19 |
# File 'lib/gull/polygon.rb', line 17 def to_s coordinates.map { |pair| pair.join(',') }.join(' ') end |
#to_wkt ⇒ Object
Returns coordinates in Well-Known Text format.
22 23 24 25 26 |
# File 'lib/gull/polygon.rb', line 22 def to_wkt pairs = coordinates.map { |pair| "#{pair.last} #{pair.first}" } .join(', ') "POLYGON((#{pairs}))" end |