Predicates: full DE-9IM, public Relate, prepared geometries as a snapshot
All predicates follow the full DE-9IM model as in OGC and NTS and compute exactly on the input coordinates (ADR 0005). The core computes the intersection matrix after the pattern of JTS RelateNG with fast paths (envelope, point-in-polygon). Because this matrix is produced anyway for correct Contains/Touches, Relate is public, and all OGC predicates are merely patterns on it. DE-9IM instead of a simplified reading, because it can be checked exactly against the oracle and the hosts and their databases (PostGIS, SQL Server) compute the same way. The intuitive reading "lies inside, boundary counts" is available as Covers/CoveredBy.
German version: 0013-praedikate-de9im-relate-prepared.de.md
Consequences
- API:
Relate(a, b)returnsIntersectionMatrix,Relate(a, b, pattern)returnsbool.- Predicates:
Intersects,Disjoint,Contains,Within,Touches,Covers,CoveredBy,Crosses,Overlaps,EqualsTopo. - A consequence of DE-9IM:
polygon.Contains(lineOnTheBoundary)is false, whereasCoversis true.
- Empty geometries:
Disjointis true, all other predicates are false, andRelatereturns a matrix consisting only ofF. - Invalid input: point-in-area tests use even-odd (ADR 0003). Results are deterministic, and there is never an exception. Whether the predicates are consistent with one another is then not guaranteed.
- Boundary rule for lines: mod-2 only (OGC): end points are boundary, closed paths have no boundary, and for multi-lines only an odd number of path ends counts. An endpoint option can be added later without a break.
- Prepared geometries:
Prepare()returns a prepared geometry with a segment index and a point-in-polygon structure for repeated predicates (Intersects, Contains, Covers, Within, CoveredBy, Disjoint, Touches). For this a snapshot of the coordinates is copied, because host geometries are mutable. The open map item "performance" then concerns only a general public index.
Considered Options
- Simplified semantics ("Contains = nothing lies outside") (rejected: not OGC-conformant, not testable against NTS)
- Only the five predicates from the charter,
Relateinternal (rejected: hardly any savings) - Endpoint boundary rule or selectable rule (postponed)
- Prepared geometry with reference instead of snapshot (rejected: undefined on changes to the host object)