Web API Reference | MapGuide Open Source

- Overview
- Modules
- Classes

# Spatial Relationships
[Spatial Relationships]

The spatial relationship predicates are implemented in this API in two ways:

- as methods on the MgGeometry class and
- as an element in a spatial filter passed to either the MgFeatureService::SelectFeatures() or the MgFeatureService::SelectAggregate() method.

MgGeometry is the base class for all of the geometry classes in this API. The call pattern is "$bool = $geometry1->predicate($geometry2)". You can use the methods on this class to analyze geometries locally.

The MgFeatureService::SelectFeatures() and MgFeatureService::SelectAggregate() methods select features from a data store somewhere in the network. The underlying implementation of this functionality is the Autodesk FDO. The filter elements are class name, geometry property name, a geometry argument, and a spatial relationship predicate name. The filter says "Select the geometries stored in <geometry property name> in <class name> which are related to the <geometry argument> by the <spatial relationship predicate>. That is, "<geometry property>.<spatial relationship predicate>(<geometry argument>)" is true.

## Egenhofer Spatial Relations

The Oracle Spatial Users Guide and Reference ([OSUGR]) bases its definitions of spatial operators on [Egenhofer91]. It defines the operators as follows:

Operator | Definition
--- | ---
disjoint | The boundaries and interiors do not intersect.
touch | The boundaries intersect but the interiors do not intersect.
overlapbdydisjoint | the interior of one object intersects the boundary and exterior of the other object but the two boundaries do not intersect.
overlapbdyintersect | The boundaries and interiors of the two objects intersect.
equal | The two objects have the same boundary and interior.
contains | The interior and boundary of one object is completely contained in the interior of the other object.
covers | The interior of one objects is completely contained in the interior or boundary of the other object and their boundaries intersect.
inside | The opposite of contains. A inside B implies B contains A.
coveredby | The opposite of covers. A converedby B implies B covers A.

## Base Definitions

The definitions of the spatial relationship predicates are implicitly or explicitly based on the definitions of the interior, boundary, and exterior of a geometry. In section 2.1.13.1, [OGC99-049] states:

"The domain of geometric objects considered is those that are spatial relationships. The interior of a geometry consists of those points that are left when the boundary points are removed. The exterior of a geometry consists of points not in the interior or boundary."

See the description of the MgGeometry::Boundary Method for a specification of the boundary for each geometry type.

## The Common Predicates

Section 2.1.13 of [OGC99-049] defines 8 spatial relationship predicates: Contains, Crosses, Disjoint, Equals, Intersects, Overlaps, Touches, and Within. Click on the predicate names to see the description of the MgGeometry method, which includes the definition.

You can use the Disjoint, Equals, and Intersects predicates on any pair of geometries in any order and you may get a return value of true as well as false.

The following table identifies the cases where the Contains, Overlaps, Touches, and Crosses predicates always return false. Blank cells in the table indicate that it is possible for the predicate to return a true value.

In the table, P stands for Point, MP for MultiPoint, L for 1-dimensional geometries (LineString, CurveString, MultiLineString and MultiCurveString), and A for 2-dimensional geometries (Polygon, MultiPolygon, CurvePolygon, and MultiCurvePolygon).

Asterisks indicate cases where switching the order of the geometries produces a result of false for the Within predicate, but may produce a result of true for the Contains predicate.

For example, a point cannot contain a line: P.Contains(L) == false. A line, however, can contain a point. Also, a point may be within a line, but a line cannot be within a point.

| P/P | MP/MP | P/L* | MP/L* | P/A* | MP/A* | L/L | L/A* | A/A
--- | --- | --- | --- | --- | --- | --- | --- | --- | ---
Contains |  |  | F | F | F | F |  | F |
Overlaps | F |  | F | F | F | F |  | F |
Touches | F | F |  |  |  |  |  |  |
Within |  |  |  |  |  |  |  |  |
Crosses | F | F | F |  | F |  |  |  | F

## Predicates Specific to MgGeometry

These are Boundary, Buffer, ConvexHull, Distance, Intersection, Symmetric Difference, and Union. Click on the predicate to see the method description, which includes a definition.

## Predicates Specific to MgFeatureService Select Methods

These predicates are Covered By, Inside, and Envelope Intersects. Click on the predicate to see the definition.

Comments or suggestions? Send us feedback.