lib/turf/meta.rb
# Get all coordinates from any GeoJSON object.
# @see https://turfjs.org/docs/#coordAll
# @param geojson [FeatureCollection|Feature|Geometry] any GeoJSON object
# @param exclude_wrap_coord [boolean] whether or not to include the final coordinate of LinearRings that wraps the
# ring in its iteration
# @return [Array<Array<number>>] coordinate position array
Get all coordinates from any GeoJSON object.
Get all coordinates from any GeoJSON object .
def coord_all(geojson, exclude_wrap_coord: false)
    geometries = self.geometries(geojson)
    geometries.flat_map do |geometry|
      next [] if geometry.nil?
      case geometry[:type]
      when "Point"
        [geometry[:coordinates]]
      when "LineString", "MultiPoint"
        geometry[:coordinates]
      when "Polygon", "MultiLineString"
        geometry[:coordinates].flat_map do |line_coords|
          (
            exclude_wrap_coord ? line_coords.slice(0...-1) : line_coords
          )
        end
      when "MultiPolygon"
        geometry[:coordinates].flat_map do |polygon_coords|
          polygon_coords.flat_map do |line_coords|
            (
              exclude_wrap_coord ? line_coords.slice(0...-1) : line_coords
            )
          end
        end
      when "Feature"
        [].tap do |feature_coords|
          coord_each geometry, exclude_wrap_coord: exclude_wrap_coord do |coord|
            feature_coords.push coord
          end
        end
      else
        raise Error, "Unknown Geometry Type: #{geometry[:type]}"
      end
    end
  end
def coord_all ( geojson , exclude_wrap_coord : false ) geometries = self . geometries ( geojson ) geometries . flat_map do | geometry | next [ ] if geometry . nil? case geometry [ :type ] when "Point" [ geometry [ :coordinates ] ] when "LineString" , "MultiPoint" geometry [ :coordinates ] when "Polygon" , "MultiLineString" geometry [ :coordinates ] . flat_map do | line_coords | ( exclude_wrap_coord ? line_coords . slice ( 0 ... - 1 ) : line_coords ) end when "MultiPolygon" geometry [ :coordinates ] . flat_map do | polygon_coords | polygon_coords . flat_map do | line_coords | ( exclude_wrap_coord ? line_coords . slice ( 0 ... - 1 ) : line_coords ) end end when "Feature" [ ] . tap do | feature_coords | coord_each geometry , exclude_wrap_coord : exclude_wrap_coord do | coord | feature_coords . push coord end end else raise Error , "Unknown Geometry Type: #{geometry[:type]}" end end end
Get all coordinates from any GeoJSON object.
Get all coordinates from any GeoJSON object .
coordinate position array
coordinate position array
Array<Array<number>>
geojson
any GeoJSON object
any GeoJSON object
exclude_wrap_coord
whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration
whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration
see
None