module RGeo::Feature::Type

This module provides the API for geometry type objects. Technically these objects are modules (such as ::RGeo::Feature::Point), but as objects they respond to the methods documented here.

For example, you may determine whether a feature object is a point by calling:

::RGeo::Feature::Point.check_type(object)

A corresponding === operator is provided so you can use the type modules in a case-when clause:

case object
when ::RGeo::Feature::Point
  # do stuff here...

However, a feature object may not actually include the point module itself; hence, the following will not work:

object.is_a?(::RGeo::Feature::Point)  # DON'T DO THIS-- DOES NOT WORK

You may obtain the type of a feature object by calling its geometry_type method. You may then use the methods in this module to interrogate that type.

# supppose object is a Point
type = object.geometry_type  # ::RGeo::Feature::Point
type.type_name               # "Point"
type.supertype               # ::RGeo::Feature::Geometry

You may also use the presence of this module to determine whether a particular object is a feature type:

::RGeo::Feature::Type === object.geometry_type  # true

Constants

Instance

Deprecated alias for RGeo::Feature::Instance

Public Instance Methods

===(rhs_) click to toggle source
Alias for: check_type
check_type(rhs_) click to toggle source

Returns true if the given object is this type or a subtype thereof, or if it is a feature object whose geometry_type is this type or a subtype thereof.

Note that feature objects need not actually include this module. Therefore, the is_a? method will generally not work.

# File lib/rgeo/feature/types.rb, line 99
def check_type(rhs_)
  rhs_ = rhs_.geometry_type if rhs_.kind_of?(Feature::Instance)
  rhs_.kind_of?(Type) && (rhs_ == self || rhs_.include?(self))
end
Also aliased as: ===
each_immediate_subtype(&block_) click to toggle source

Iterates over the known immediate subtypes of this type.

# File lib/rgeo/feature/types.rb, line 124
def each_immediate_subtype(&block_)
  @subtypes.each(&block_) if defined?(@subtypes) && @subtypes
end
subtype_of?(type_) click to toggle source

Returns true if this type is the same type or a subtype of the given type.

# File lib/rgeo/feature/types.rb, line 109
def subtype_of?(type_)
  self == type_ || self.include?(type_)
end
supertype() click to toggle source

Returns the supertype of this type. The supertype of Geometry is nil.

# File lib/rgeo/feature/types.rb, line 117
def supertype
  @supertype
end
to_s() click to toggle source
Alias for: type_name
type_name() click to toggle source

Returns the OpenGIS type name of this type. For example:

::RGeo::Feature::Point.type_name  # "Point"
# File lib/rgeo/feature/types.rb, line 133
def type_name
  self.name.sub('RGeo::Feature::', '')
end
Also aliased as: to_s