lib/turf/helpers.rb
# Creates a Polygon Feature from an Array of LinearRings.
# @see https://turfjs.org/docs/#polygon
# @param coordinates [Array<Array<Array<number>>>] an array of LinearRings
# @param properties [Hash] an Hash of key-value pairs to add as properties
# @param bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
# @param id [string | number] Identifier associated with the Feature
# @return [Feature<Polygon>] Polygon feature
Creates a Polygon Feature from an Array of LinearRings.
Creates a Polygon Feature from an Array of LinearRings .
def polygon(coordinates, properties: {}, bbox: nil, id: nil)
    coordinates.each do |ring|
      if ring.size < 4
        raise(
          Error,
          "Each LinearRing of a Polygon must have 4 or more Positions.",
        )
      end
      ring.last.each_with_index do |number, idx|
        if ring.first[idx] != number
          raise Error, "First and last Position are not equivalent."
        end
      end
    end
    geom = {
      type: "Polygon",
      coordinates: coordinates
    }
    feature(geom, properties: properties, id: id, bbox: bbox)
  end
def polygon ( coordinates , properties : { } , bbox : nil , id : nil ) coordinates . each do | ring | if ring . size < 4 raise ( Error , "Each LinearRing of a Polygon must have 4 or more Positions." , ) end ring . last . each_with_index do | number , idx | if ring . first [ idx ] != number raise Error , "First and last Position are not equivalent." end end end geom = { type : "Polygon" , coordinates : coordinates } feature ( geom , properties : properties , id : id , bbox : bbox ) end
Creates a Polygon Feature from an Array of LinearRings.
Creates a Polygon Feature from an Array of LinearRings .
None
Feature<Polygon>
coordinates
an array of LinearRings
an array of LinearRings
properties
an Hash of key-value pairs to add as properties
an Hash of key - value pairs to add as properties
bbox
Bounding Box Array [west, south, east, north] associated with the Feature
Bounding Box Array [ west south east north ] associated with the Feature
id
Identifier associated with the Feature
Identifier associated with the Feature
see
None