Module: RGeo::Feature::Type
- Included in:
- Curve, Geometry, GeometryCollection, Line, LineString, LinearRing, MultiCurve, MultiLineString, MultiPoint, MultiPolygon, MultiSurface, Point, Polygon, Surface
- Defined in:
- lib/rgeo/feature/types.rb
Overview
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
Class Method Summary collapse
-
.extended(type) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#add_subtype(type) ⇒ Object
:nodoc:.
-
#check_type(rhs) ⇒ Object
(also: #===)
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.
-
#each_immediate_subtype ⇒ Object
Iterates over the known immediate subtypes of this type.
-
#subtype_of?(type) ⇒ Boolean
Returns true if this type is the same type or a subtype of the given type.
-
#supertype ⇒ Object
Returns the supertype of this type.
-
#type_name ⇒ Object
(also: #to_s)
Returns the OpenGIS type name of this type.
Class Method Details
.extended(type) ⇒ Object
:nodoc:
98 99 100 101 102 |
# File 'lib/rgeo/feature/types.rb', line 98 def self.extended(type) # :nodoc: supertype = type.included_modules.find { |m| m.is_a?(self) } type.instance_variable_set(:@supertype, supertype) supertype&.add_subtype(type) end |
Instance Method Details
#add_subtype(type) ⇒ Object
:nodoc:
94 95 96 |
# File 'lib/rgeo/feature/types.rb', line 94 def add_subtype(type) # :nodoc: (@subtypes ||= []) << type end |
#check_type(rhs) ⇒ Object Also known as: ===
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.
59 60 61 62 |
# File 'lib/rgeo/feature/types.rb', line 59 def check_type(rhs) rhs = rhs.geometry_type if rhs.is_a?(Feature::Instance) rhs.is_a?(Type) && (rhs == self || rhs.include?(self)) end |
#each_immediate_subtype ⇒ Object
Iterates over the known immediate subtypes of this type.
81 82 83 |
# File 'lib/rgeo/feature/types.rb', line 81 def each_immediate_subtype(&) @subtypes&.each(&) end |
#subtype_of?(type) ⇒ Boolean
Returns true if this type is the same type or a subtype of the given type.
68 69 70 |
# File 'lib/rgeo/feature/types.rb', line 68 def subtype_of?(type) self == type || include?(type) end |
#supertype ⇒ Object
Returns the supertype of this type. The supertype of Geometry is nil.
75 76 77 |
# File 'lib/rgeo/feature/types.rb', line 75 def supertype @supertype end |