lib/turf/meta.rb
# Reduce geometry in any GeoJSON object, similar to Array.reduce().
# @see https://turfjs.org/docs/#geomReduce
# @param geojson [FeatureCollection|Feature|Geometry] any GeoJSON object
# @param initial_value [*] Value to use as the first argument to the first call of the callback.
# @yieldparam previous_value [*] Result of previous reduction
# @yieldparam geom [Geometry] The current Feature being processed.
# @yieldparam geom_index [number] The current index of the Feature being processed.
# @yieldparam properties [Hash] an Object of key-value pairs to add as properties
# @yieldparam bbox [Array<number>] Bounding Box Array [west, south, east, north] associated with the Feature
# @yieldparam id [string|number] Identifier associated with the Feature
# @return [*] The value that results from the reduction.
Reduce geometry in any GeoJSON object, similar to Array.reduce().
Reduce geometry in any GeoJSON object similar to Array . reduce () .
def geom_reduce(geojson, initial_value: nil)
    previous_value = initial_value
    geom_each(
      geojson,
    ) do |geom, geom_index, properties, bbox, id|
      previous_value =
        if geom_index.zero? && initial_value.nil?
          geom
        else
          yield(
            previous_value,
            geom,
            geom_index,
            properties,
            bbox,
            id
          )
        end
    end
    previous_value
  end
def geom_reduce ( geojson , initial_value : nil ) previous_value = initial_value geom_each ( geojson , ) do | geom , geom_index , properties , bbox , id | previous_value = if geom_index . zero? && initial_value . nil? geom else yield ( previous_value , geom , geom_index , properties , bbox , id ) end end previous_value end
Reduce geometry in any GeoJSON object, similar to Array.reduce().
Reduce geometry in any GeoJSON object similar to Array . reduce () .
The value that results from the reduction.
The value that results from the reduction .
*
geojson
any GeoJSON object
any GeoJSON object
initial_value
Value to use as the first argument to the first call of the callback.
Value to use as the first argument to the first call of the callback .
previous_value
Result of previous reduction
Result of previous reduction
geom
The current Feature being processed.
The current Feature being processed .
geom_index
The current index of the Feature being processed.
The current index of the Feature being processed .
properties
an Object of key-value pairs to add as properties
an Object 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