lib/turf/meta.rb
# Reduce flattened features in any GeoJSON object, similar to Array.reduce().
# @see https://turfjs.org/docs/#flattenEach
# @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 feature [Feature<any>] The current Feature being processed.
# @yieldparam feature_index [number] The current index of the Feature being processed.
# @yieldparam multi_feature_index [number] The current index of the Feature in the multi-Feature
# @return [*] The value that results from the reduction.
Reduce flattened features in any GeoJSON object, similar to Array.reduce().
Reduce flattened features in any GeoJSON object similar to Array . reduce () .
def flatten_reduce(geojson, initial_value: nil)
    previous_value = initial_value
    flatten_each(
      geojson,
    ) do |feature, feature_index, multi_feature_index|
      previous_value =
        if feature_index.zero? && multi_feature_index.zero? && initial_value.nil?
          feature
        else
          yield(
            previous_value,
            feature,
            feature_index,
            multi_feature_index
          )
        end
    end
    previous_value
  end
def flatten_reduce ( geojson , initial_value : nil ) previous_value = initial_value flatten_each ( geojson , ) do | feature , feature_index , multi_feature_index | previous_value = if feature_index . zero? && multi_feature_index . zero? && initial_value . nil? feature else yield ( previous_value , feature , feature_index , multi_feature_index ) end end previous_value end
Reduce flattened features in any GeoJSON object, similar to Array.reduce().
Reduce flattened features 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
feature
The current Feature being processed.
The current Feature being processed .
feature_index
The current index of the Feature being processed.
The current index of the Feature being processed .
multi_feature_index
The current index of the Feature in the multi-Feature
The current index of the Feature in the multi - Feature
see
None