Sha256: 681ccee860f64fa8f5db4ca0dd97fe78b65764d12c2b6872819b66b99e4daed7

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

module Terraformer

  class Geometry < Primitive

    MULTI_REGEX = /^Multi/

    attr_accessor :coordinates

    def initialize *args
      if args.length > 1 or Array === args[0]
        self.coordinates = Coordinate.from_array args
      else
        super *args do |arg|
          self.coordinates = Coordinate.from_array arg['coordinates']
        end
      end
    end

    def to_hash
      {
        type: type,
        coordinates: coordinates
      }
    end

    def to_mercator
      self.class.new *coordinates.map_coordinate(&:to_mercator)
    end

    def to_geographic
      self.class.new *coordinates.map_coordinate(&:to_geographic)
    end

    def first_coordinate
      raise NotImplementedError
    end

    def mercator?
      first_coordinate.mercator?
    end

    def geographic?
      first_coordinate.geographic?
    end

    def get index
      if MULTI_REGEX.match type
        sub = type.sub MULTI_REGEX, ''
        Terraformer.const_get(sub).new *coordinates[index]
      else
        raise NotImplementedError
      end
    end

    def convex_hull
      raise NotImplementedError
    end

    def contains other
      raise NotImplementedError
    end

    def within other
      raise NotImplementedError
    end

    def intersects other
      raise NotImplementedError
    end

  end

  class GeometryCollection < Primitive

    attr_writer :geometries

    def initialize *args
      unless args.empty?
        super *args do |arg|
          self.geometries = arg['geometries'].map {|g| Terraformer.parse g}
        end
      end
    end

    def geometries
      @geometries ||= []
    end

    def to_hash
      {
        type: type,
        geometries: geometries.map(&:to_hash)
      }
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraformer-0.0.1 lib/terraformer/geometry.rb