lib/rcap/base/polygon.rb in rcap-2.5.1 vs lib/rcap/base/polygon.rb in rcap-2.6.0

- old
+ new

@@ -25,9 +25,15 @@ yield(point) if block_given? points << point point end + # Returns GeoJSON representation of the polygon + def to_geojson + coordinates = @points.map { |point| [point.longitude, point.lattitude] } + { 'type' => 'Polygon', 'coordinates' => coordinates }.to_json + end + # Returns a string representation of the polygon of the form # points[0] points[1] points[2] ... # where each point is formatted with Point#to_s def to_s @points.join(' ')