Class: MapWKT::Geometry::Polygon
- Inherits:
-
MapWKT::Geometry
- Object
- MapWKT::Geometry
- MapWKT::Geometry::Polygon
- Defined in:
- lib/mapwkt/wkt/polygon.rb
Instance Method Summary collapse
-
#center ⇒ Object
Returns a Point midway between the N/S- & E/W-most Points in the perimeter.
-
#initialize(perimeter, *lacunae) ⇒ Polygon
constructor
Returns a new MapWKT::Geometry::Polygon with the given outer perimeter and internal lacunae.
-
#lacunae ⇒ Object
Returns an array of LineStrings representing the geographical areas treated as lacunae in this Polygon’s enclosed area.
-
#perimeter ⇒ Object
Returns a LineString representing the geographical area treated as the outer perimeter of this Polygon’s enclosed area.
-
#to_s ⇒ Object
Returns a string representation of this Polygon.
-
#wkt ⇒ Object
Returns this Polygon’s WKT representation, with latitudes and longitudes rounded to 7 decimal places.
Methods inherited from MapWKT::Geometry
parse_linestrings, parse_points, parse_polygons, parse_wkt, parse_x_y
Constructor Details
#initialize(perimeter, *lacunae) ⇒ Polygon
Returns a new MapWKT::Geometry::Polygon with the given outer perimeter and internal lacunae. If the given LineStrings were unclosed, closes them for use in the Polygon, but leaves the original LineStrings unchanged.
12 13 14 15 |
# File 'lib/mapwkt/wkt/polygon.rb', line 12 def initialize (perimeter, *lacunae) @perimeter = perimeter.dup.close! @lacunae = lacunae.map {|lacuna| lacuna.dup.close! } end |
Instance Method Details
#center ⇒ Object
Returns a Point midway between the N/S- & E/W-most Points in the perimeter.
5 6 7 |
# File 'lib/mapwkt/wkt/polygon.rb', line 5 def center self.perimeter.center end |
#lacunae ⇒ Object
Returns an array of LineStrings representing the geographical areas treated as lacunae in this Polygon’s enclosed area. Does not return the objects themselves, nor the actual array containing them.
20 21 22 |
# File 'lib/mapwkt/wkt/polygon.rb', line 20 def lacunae @lacunae.map(&:dup) end |
#perimeter ⇒ Object
Returns a LineString representing the geographical area treated as the outer perimeter of this Polygon’s enclosed area. Does not return the actual LineString object used in this Polygon.
27 28 29 |
# File 'lib/mapwkt/wkt/polygon.rb', line 27 def perimeter @perimeter.dup end |
#to_s ⇒ Object
Returns a string representation of this Polygon. ⭓ indicates the perimeter LineString, while ⬠ indicates a lacuna LineString.
33 34 35 |
# File 'lib/mapwkt/wkt/polygon.rb', line 33 def to_s "⭓ #{@perimeter.points.join(", ")} ⭓#{@lacunae.map {|lacuna| " | ⬠ #{lacuna.points.join(", ")} ⬠" }.join} " end |
#wkt ⇒ Object
Returns this Polygon’s WKT representation, with latitudes and longitudes rounded to 7 decimal places.
39 40 41 |
# File 'lib/mapwkt/wkt/polygon.rb', line 39 def wkt "POLYGON((#{[*@perimeter.points, @perimeter.points.first].map {|p| "#{p.longitude_f} #{p.latitude_f}" }.join(", ")})#{@lacunae.map {|lacuna| ", (#{[*lacuna.points, lacuna.points.first].map {|p| "#{p.longitude_f} #{p.latitude_f}" }.join(", ")})" }.join })" end |