class GeoRuby::SimpleFeatures::GeometryCollection

Represents a collection of arbitrary geometries

Attributes

geometries[R]

Public Class Methods

from_geometries(geometries, srid = DEFAULT_SRID, z = false, m = false) click to toggle source

creates a new GeometryCollection from an array of geometries

# File lib/geo_ruby/simple_features/geometry_collection.rb, line 136
def self.from_geometries(geometries, srid = DEFAULT_SRID, z = false, m = false)
  geometry_collection = new(srid, z, m)
  geometry_collection.concat(geometries)
  geometry_collection
end
new(srid = DEFAULT_SRID, with_z = false, with_m = false) click to toggle source
Calls superclass method GeoRuby::SimpleFeatures::Geometry::new
# File lib/geo_ruby/simple_features/geometry_collection.rb, line 9
def initialize(srid = DEFAULT_SRID, with_z = false, with_m = false)
  super(srid, with_z, with_m)
  @geometries = []
end

Public Instance Methods

==(other) click to toggle source

tests the equality of geometry collections

# File lib/geo_ruby/simple_features/geometry_collection.rb, line 67
def ==(other)
  if (other.class != self.class)
    false
  elsif length != other.length
    false
  else
    index = 0
    while index < length
      return false if self[index] != other[index]
      index += 1
    end
    true
  end
end
as_json(_options = {}) click to toggle source
# File lib/geo_ruby/simple_features/geometry_collection.rb, line 108
def as_json(_options = {})
  { type: 'GeometryCollection', geometries: geometries }
end
bounding_box() click to toggle source

Bounding box in 2D/3D. Returns an array of 2 points

# File lib/geo_ruby/simple_features/geometry_collection.rb, line 20
def bounding_box
  max_x, min_x, max_y, min_y = -Float::MAX, Float::MAX, -Float::MAX, Float::MAX
  if with_z
    max_z, min_z = -Float::MAX, Float::MAX
    each do |geometry|
      bbox = geometry.bounding_box
      sw = bbox[0]
      ne = bbox[1]

      max_y = ne.y if ne.y > max_y
      min_y = sw.y if sw.y < min_y
      max_x = ne.x if ne.x > max_x
      min_x = sw.x if sw.x < min_x
      max_z = ne.z if ne.z > max_z
      min_z = sw.z if sw.z < min_z
    end
    [Point.from_x_y_z(min_x, min_y, min_z), Point.from_x_y_z(max_x, max_y, max_z)]
  else
    each do |geometry|
      bbox = geometry.bounding_box
      sw = bbox[0]
      ne = bbox[1]

      max_y = ne.y if ne.y > max_y
      min_y = sw.y if sw.y < min_y
      max_x = ne.x if ne.x > max_x
      min_x = sw.x if sw.x < min_x
    end
    [Point.from_x_y(min_x, min_y), Point.from_x_y(max_x, max_y)]
  end
end
m_range() click to toggle source
# File lib/geo_ruby/simple_features/geometry_collection.rb, line 52
def m_range
  if with_m
    max_m, min_m = -Float::MAX, Float::MAX
    each do |lr|
      lrmr = lr.m_range
      max_m = lrmr[1] if lrmr[1] > max_m
      min_m = lrmr[0] if lrmr[0] < min_m
    end
    [min_m, max_m]
  else
    [0, 0]
  end
end
method_missing(method_name, *args, &b) click to toggle source

Delegate the unknown methods to the geometries array

# File lib/geo_ruby/simple_features/geometry_collection.rb, line 15
def method_missing(method_name, *args, &b)
  @geometries.send(method_name, *args, &b)
end