class Terraformer::FeatureCollection

Attributes

crs[RW]
features[W]

Public Class Methods

new(*args) click to toggle source
Calls superclass method Terraformer::Primitive::new
# File lib/terraformer/feature.rb, line 63
def initialize *args
  unless args.empty?
    super *args do |arg|
      self.features = arg['features'].map {|f| Terraformer.parse f unless Primitive === f}
    end
  end
end
with_features(*f) click to toggle source
# File lib/terraformer/feature.rb, line 56
def self.with_features *f
  raise ArgumentError unless f.all? {|e| Feature === e}
  fc = FeatureCollection.new
  fc.features = f
  fc
end

Public Instance Methods

<<(feature) click to toggle source
# File lib/terraformer/feature.rb, line 75
def << feature
  raise ArgumentError unless Feature === feature
  features << feature
end
==(obj) click to toggle source
# File lib/terraformer/feature.rb, line 89
def == obj
  return false unless FeatureCollection === obj
  to_hash == obj.to_hash
end
convex_hull() click to toggle source
# File lib/terraformer/feature.rb, line 94
def convex_hull
  ConvexHull.for features.map(&:geometry).map(&:coordinates)
end
features() click to toggle source
# File lib/terraformer/feature.rb, line 71
def features
  @features ||= []
end
geojson_io() click to toggle source
# File lib/terraformer/feature.rb, line 98
def geojson_io
  Terraformer.geojson_io self
end
to_hash(*args) click to toggle source
# File lib/terraformer/feature.rb, line 80
def to_hash *args
  h = {
    type: type,
    features: features.map {|f| f.to_hash *args}
  }
  h[:crs] = crs if crs
  h
end