module RGeo::Feature::Geometry

SFS 1.1 Description

Geometry is the root class of the hierarchy. Geometry is an abstract (non-instantiable) class.

The instantiable subclasses of Geometry defined in this International Standard are restricted to 0, 1 and 2-dimensional geometric objects that exist in 2-dimensional coordinate space (R2).

All instantiable Geometry classes described in this part of ISO 19125 are defined so that valid instances of a Geometry class are topologically closed, i.e. all defined geometries include their boundary.

Notes

Geometry is defined as a module and is provided primarily for the sake of documentation. Implementations need not necessarily include this module itself. Therefore, you should not depend on the result of is_a?(Geometry) to check type. Instead, use the provided check_type class method (or === operator) defined in the Type module.

Some implementations may support higher dimensional objects or coordinate systems, despite the limits of the SFS.

Forms of equivalence

The Geometry model defines three forms of equivalence.

Different methods test for different types of equivalence:

All ruby objects must provide a suitable test for objective equivalence. Normally, this is simply provided by the Ruby Object base class. Geometry implementations should normally also provide tests for representational and spatial equivalence, if possible. The == operator and the eql? method are standard Ruby methods that are often expected to be usable for every object. Therefore, if an implementation cannot provide a suitable test for their equivalence types, they must degrade to use a stronger form of equivalence.

Public Instance Methods

*(rhs_) click to toggle source

If the given rhs is a geometry object, this operator must behave the same as the intersection method. The behavior for other rhs types is not specified; an implementation may choose to provide additional capabilities as appropriate.

# File lib/rgeo/feature/geometry.rb, line 686
def *(rhs_)
  intersection(rhs_)
end
+(rhs_) click to toggle source

If the given rhs is a geometry object, this operator must behave the same as the union method. The behavior for other rhs types is not specified; an implementation may choose to provide additional capabilities as appropriate.

# File lib/rgeo/feature/geometry.rb, line 676
def +(rhs_)
  union(rhs_)
end
-(rhs_) click to toggle source

If the given rhs is a geometry object, this operator must behave the same as the difference method. The behavior for other rhs types is not specified; an implementation may choose to provide additional capabilities as appropriate.

# File lib/rgeo/feature/geometry.rb, line 666
def -(rhs_)
  difference(rhs_)
end
==(rhs_) click to toggle source

This operator should behave almost the same as the equals? method, with two key differences.

First, the == operator is required to handle rhs values that are not geometry objects (returning false in such cases) in order to fulfill the standard Ruby contract for the == operator, whereas the equals? method may assume that any rhs is a geometry.

Second, the == operator should always be defined. That is, it should never raise Error::UnsupportedOperation. In cases where the underlying implementation cannot provide a spatial equivalence test, the == operator must fall back on representational or objective equivalence.

# File lib/rgeo/feature/geometry.rb, line 648
def ==(rhs_)
  if rhs_.kind_of?(::RGeo::Feature::Instance)
    begin
      equals?(rhs_)
    rescue Error::UnsupportedOperation
      eql?(rhs_)
    end
  else
    false
  end
end
as_binary() click to toggle source

SFS 1.1 Description

Exports this geometric object to a specific Well-known Binary Representation of Geometry.

Notes

Returns a binary string.

# File lib/rgeo/feature/geometry.rb, line 218
def as_binary
  raise Error::UnsupportedOperation, "Method Geometry#as_binary not defined."
end
as_text() click to toggle source

SFS 1.1 Description

Exports this geometric object to a specific Well-known Text Representation of Geometry.

Notes

Returns an ASCII string.

# File lib/rgeo/feature/geometry.rb, line 204
def as_text
  raise Error::UnsupportedOperation, "Method Geometry#as_text not defined."
end
boundary() click to toggle source

SFS 1.1 Description

Returns the closure of the combinatorial boundary of this geometric object. Because the result of this function is a closure, and hence topologically closed, the resulting boundary can be represented using representational Geometry primitives.

Notes

Returns an object that supports the Geometry interface.

# File lib/rgeo/feature/geometry.rb, line 268
def boundary
  raise Error::UnsupportedOperation, "Method Geometry#boundary not defined."
end
buffer(distance_) click to toggle source

SFS 1.1 Description

Returns a geometric object that represents all Points whose distance from this geometric object is less than or equal to distance. Calculations are in the spatial reference system of this geometric object.

Notes

Returns an object that supports the Geometry interface.

# File lib/rgeo/feature/geometry.rb, line 498
def buffer(distance_)
  raise Error::UnsupportedOperation, "Method Geometry#buffer not defined."
end
contains?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object “spatially contains” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 408
def contains?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#contains? not defined."
end
convex_hull() click to toggle source

SFS 1.1 Description

Returns a geometric object that represents the convex hull of this geometric object.

Notes

Returns an object that supports the Geometry interface.

# File lib/rgeo/feature/geometry.rb, line 512
def convex_hull
  raise Error::UnsupportedOperation, "Method Geometry#convex_hull not defined."
end
crosses?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object “spatially crosses” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 368
def crosses?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#crosses? not defined."
end
difference(another_geometry_) click to toggle source

SFS 1.1 Description

Returns a geometric object that represents the Point set difference of this geometric object with another_geometry.

Notes

Returns an object that supports the Geometry interface.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of performing operations on objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 569
def difference(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#difference not defined."
end
dimension() click to toggle source

SFS 1.1 Description

The inherent dimension of this geometric object, which must be less than or equal to the coordinate dimension. This specification is restricted to geometries in 2-dimensional coordinate space.

Notes

Returns an integer. This value is -1 for an empty geometry, 0 for point geometries, 1 for curves, and 2 for surfaces.

# File lib/rgeo/feature/geometry.rb, line 141
def dimension
  raise Error::UnsupportedOperation, "Method Geometry#dimension not defined."
end
disjoint?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object is “spatially disjoint” from another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 308
def disjoint?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#disjoint? not defined."
end
distance(another_geometry_) click to toggle source

SFS 1.1 Description

Returns the shortest distance between any two Points in the two geometric objects as calculated in the spatial reference system of this geometric object.

Notes

Returns a floating-point scalar value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of measuring the distance between objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 482
def distance(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#distance not defined."
end
envelope() click to toggle source

SFS 1.1 Description

The minimum bounding box for this Geometry, returned as a Geometry. The polygon is defined by the corner points of the bounding box [(MINX, MINY), (MAXX, MINY), (MAXX, MAXY), (MINX, MAXY), (MINX, MINY)].

Notes

Returns an object that supports the Geometry interface.

# File lib/rgeo/feature/geometry.rb, line 190
def envelope
  raise Error::UnsupportedOperation, "Method Geometry#envelope not defined."
end
eql?(rhs_) click to toggle source

This method should behave almost the same as the rep_equals? method, with two key differences.

First, the eql? method is required to handle rhs values that are not geometry objects (returning false in such cases) in order to fulfill the standard Ruby contract for the method, whereas the rep_equals? method may assume that any rhs is a geometry.

Second, the eql? method should always be defined. That is, it should never raise Error::UnsupportedOperation. In cases where the underlying implementation cannot provide a representational equivalence test, this method must fall back on objective equivalence.

# File lib/rgeo/feature/geometry.rb, line 621
def eql?(rhs_)
  if rhs_.kind_of?(::RGeo::Feature::Instance)
    begin
      rep_equals?(rhs_)
    rescue Error::UnsupportedOperation
      equal?(rhs_)
    end
  else
    false
  end
end
equals?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object is “spatially equal” to another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 288
def equals?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#equals? not defined."
end
factory() click to toggle source

Returns a factory for creating features related to this one. This does not necessarily need to be the same factory that created this object, but it should create objects that are “compatible” with this one. (i.e. they should be in the same spatial reference system by default, and it should be possible to perform relational operations on them.)

# File lib/rgeo/feature/geometry.rb, line 125
def factory
  raise Error::UnsupportedOperation, "Method Geometry#factory not defined."
end
geometry_type() click to toggle source

SFS 1.1 Description

Returns the instantiable subtype of Geometry of which this geometric object is an instantiable member.

Notes

Returns one of the type modules in RGeo::Feature. e.g. a point object would return RGeo::Feature::Point. Note that this is different from the SFS specification, which stipulates that the string name of the type is returned. To obtain the name string, call the type_name method of the returned module.

# File lib/rgeo/feature/geometry.rb, line 159
def geometry_type
  raise Error::UnsupportedOperation, "Method Geometry#geometry_type not defined."
end
intersection(another_geometry_) click to toggle source

SFS 1.1 Description

Returns a geometric object that represents the Point set intersection of this geometric object with another_geometry.

Notes

Returns an object that supports the Geometry interface.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of performing operations on objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 531
def intersection(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#intersection not defined."
end
intersects?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object “spatially intersects” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 328
def intersects?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#intersects? not defined."
end
is_empty?() click to toggle source

SFS 1.1 Description

Returns true if this geometric object is the empty Geometry. If true, then this geometric object represents the empty point set for the coordinate space.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

# File lib/rgeo/feature/geometry.rb, line 234
def is_empty?
  raise Error::UnsupportedOperation, "Method Geometry#is_empty? not defined."
end
is_simple?() click to toggle source

SFS 1.1 Description

Returns true if this geometric object has no anomalous geometric points, such as self intersection or self tangency. The description of each instantiable geometric class will include the specific conditions that cause an instance of that class to be classified as not simple.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

# File lib/rgeo/feature/geometry.rb, line 252
def is_simple?
  raise Error::UnsupportedOperation, "Method Geometry#is_simple? not defined."
end
overlaps?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object “spatially overlaps” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 428
def overlaps?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#overlaps? not defined."
end
relate(another_geometry_, intersection_pattern_matrix_) click to toggle source

Deprecated alias of #relate?

# File lib/rgeo/feature/geometry.rb, line 462
def relate(another_geometry_, intersection_pattern_matrix_)
  relate?(another_geometry_, intersection_pattern_matrix_)
end
relate?(another_geometry_, intersection_pattern_matrix_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object is spatially related to another_geometry by testing for intersections between the interior, boundary and exterior of the two geometric objects as specified by the values in the intersection_pattern_matrix.

Notes

The intersection_pattern_matrix is provided as a nine-character string in row-major order, representing the dimensionalities of the different intersections in the DE-9IM. Supported characters include T, F, *, 0, 1, and 2.

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 455
def relate?(another_geometry_, intersection_pattern_matrix_)
  raise Error::UnsupportedOperation, "Method Geometry#relate not defined."
end
rep_equals?(another_geometry_) click to toggle source

Returns true if this geometric object is representationally equivalent to the given object.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 601
def rep_equals?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#rep_equals? not defined."
end
srid() click to toggle source

SFS 1.1 Description

Returns the Spatial Reference System ID for this geometric object.

Notes

Returns an integer.

This will normally be a foreign key to an index of reference systems stored in either the same or some other datastore.

# File lib/rgeo/feature/geometry.rb, line 175
def srid
  raise Error::UnsupportedOperation, "Method Geometry#srid not defined."
end
sym_difference(another_geometry_) click to toggle source

SFS 1.1 Description

Returns a geometric object that represents the Point set symmetric difference of this geometric object with another_geometry.

Notes

Returns an object that supports the Geometry interface.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of performing operations on objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 588
def sym_difference(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#sym_difference not defined."
end
touches?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object “spatially touches” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 348
def touches?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#touches? not defined."
end
union(another_geometry_) click to toggle source

SFS 1.1 Description

Returns a geometric object that represents the Point set union of this geometric object with another_geometry.

Notes

Returns an object that supports the Geometry interface.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of performing operations on objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 550
def union(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#union not defined."
end
within?(another_geometry_) click to toggle source

SFS 1.1 Description

Returns true if this geometric object is “spatially within” another_geometry.

Notes

Returns a boolean value. Note that this is different from the SFS specification, which stipulates an integer return value.

Although implementations are free to attempt to handle another_geometry values that do not share the same factory as this geometry, strictly speaking, the result of comparing objects from different factories is undefined.

# File lib/rgeo/feature/geometry.rb, line 388
def within?(another_geometry_)
  raise Error::UnsupportedOperation, "Method Geometry#within? not defined."
end