18 #include <geos/geom/Location.h>
19 #include <geos/operation/relateng/BasicPredicate.h>
20 #include <geos/operation/relateng/IMPatternMatcher.h>
21 #include <geos/operation/relateng/IMPredicate.h>
22 #include <geos/operation/relateng/RelateGeometry.h>
23 #include <geos/geom/Envelope.h>
24 #include <geos/export.h>
36 class GEOS_DLL RelatePredicate {
62 class IntersectsPredicate :
public BasicPredicate {
66 std::string name()
const override {
67 return std::string(
"intersects");
70 bool requireSelfNoding()
const override {
75 bool requireExteriorCheck(
bool isSourceA)
const override {
85 void updateDimension(Location locA, Location locB,
int dimension)
override {
87 setValueIf(
true, isIntersection(locA, locB));
90 void finish()
override {
97 static std::unique_ptr<BasicPredicate> intersects();
115 class DisjointPredicate :
public BasicPredicate {
117 std::string name()
const override {
118 return std::string(
"disjoint");
121 bool requireSelfNoding()
const override {
126 bool requireInteraction()
const override {
131 bool requireExteriorCheck(
bool isSourceA)
const override {
138 setValueIf(
true, envA.
disjoint(envB));
141 void updateDimension(Location locA, Location locB,
int dimension)
override {
143 setValueIf(
false, isIntersection(locA, locB));
146 void finish()
override {
152 static std::unique_ptr<BasicPredicate> disjoint();
178 class ContainsPredicate :
public IMPredicate {
180 std::string name()
const override {
181 return std::string(
"contains");
184 bool requireCovers(
bool isSourceA)
override {
185 return isSourceA == RelateGeometry::GEOM_A;
188 bool requireExteriorCheck(
bool isSourceA)
const override {
190 return isSourceA == RelateGeometry::GEOM_B;
193 void init(
int _dimA,
int _dimB)
override {
194 IMPredicate::init(_dimA, _dimB);
195 require(isDimsCompatibleWithCovers(dimA, dimB));
199 BasicPredicate::requireCovers(envA, envB);
202 bool isDetermined()
const override {
203 return intersectsExteriorOf(RelateGeometry::GEOM_A);
206 bool valueIM()
override {
207 return intMatrix.isContains();
211 static std::unique_ptr<IMPredicate> contains();
239 class WithinPredicate :
public IMPredicate {
241 std::string name()
const override {
242 return std::string(
"within");
245 bool requireCovers(
bool isSourceA)
override {
246 return isSourceA == RelateGeometry::GEOM_B;
249 bool requireExteriorCheck(
bool isSourceA)
const override {
251 return isSourceA == RelateGeometry::GEOM_A;
254 void init(
int _dimA,
int _dimB)
override {
255 IMPredicate::init(_dimA, _dimB);
256 require(isDimsCompatibleWithCovers(dimB, dimA));
260 BasicPredicate::requireCovers(envB, envA);
263 bool isDetermined()
const override {
264 return intersectsExteriorOf(RelateGeometry::GEOM_B);
267 bool valueIM()
override {
268 return intMatrix.isWithin();
272 static std::unique_ptr<IMPredicate> within();
307 class CoversPredicate :
public IMPredicate {
309 std::string name()
const override {
310 return std::string(
"covers");
313 bool requireCovers(
bool isSourceA)
override {
314 return isSourceA == RelateGeometry::GEOM_A;
317 bool requireExteriorCheck(
bool isSourceA)
const override {
319 return isSourceA == RelateGeometry::GEOM_B;
322 void init(
int _dimA,
int _dimB)
override {
323 IMPredicate::init(_dimA, _dimB);
324 require(isDimsCompatibleWithCovers(dimA, dimB));
328 BasicPredicate::requireCovers(envA, envB);
332 bool isDetermined()
const override {
333 return intersectsExteriorOf(RelateGeometry::GEOM_A);
336 bool valueIM()
override {
337 return intMatrix.isCovers();
341 static std::unique_ptr<IMPredicate> covers();
371 class CoveredByPredicate :
public IMPredicate {
373 std::string name()
const override {
374 return std::string(
"coveredBy");
377 bool requireCovers(
bool isSourceA)
override {
378 return isSourceA == RelateGeometry::GEOM_B;
381 bool requireExteriorCheck(
bool isSourceA)
const override {
383 return isSourceA == RelateGeometry::GEOM_A;
386 void init(
int _dimA,
int _dimB)
override {
387 IMPredicate::init(_dimA, _dimB);
388 require(isDimsCompatibleWithCovers(dimB, dimA));
392 BasicPredicate::requireCovers(envB, envA);
395 bool isDetermined()
const override {
396 return intersectsExteriorOf(RelateGeometry::GEOM_B);
399 bool valueIM()
override {
400 return intMatrix.isCoveredBy();
405 static std::unique_ptr<IMPredicate> coveredBy();
431 class CrossesPredicate :
public IMPredicate {
433 std::string name()
const override {
434 return std::string(
"crosses");
437 void init(
int _dimA,
int _dimB)
override {
438 IMPredicate::init(_dimA, _dimB);
439 bool isBothPointsOrAreas =
442 require(!isBothPointsOrAreas);
445 bool isDetermined()
const override {
448 if (getDimension(Location::INTERIOR, Location::INTERIOR) >
Dimension::P)
451 else if (dimA < dimB) {
452 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
457 else if (dimA > dimB) {
458 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
466 bool valueIM()
override {
467 return intMatrix.isCrosses(dimA, dimB);
471 static std::unique_ptr<IMPredicate> crosses();
487 class EqualsTopoPredicate :
public IMPredicate {
489 std::string name()
const override {
490 return std::string(
"equals");
493 bool requireInteraction()
const override {
498 void init(
int _dimA,
int _dimB)
override {
499 IMPredicate::init(_dimA, _dimB);
507 require(envA.
equals(&envB));
510 bool isDetermined()
const override {
511 bool isEitherExteriorIntersects =
517 return isEitherExteriorIntersects;
520 bool valueIM()
override {
521 return intMatrix.isEquals(dimA, dimB);
526 static std::unique_ptr<IMPredicate> equalsTopo();
548 class OverlapsPredicate :
public IMPredicate {
550 std::string name()
const override {
551 return std::string(
"overlaps");
554 void init(
int _dimA,
int _dimB)
override {
555 IMPredicate::init(_dimA, _dimB);
556 require(dimA == dimB);
559 bool isDetermined()
const override {
561 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
567 if (isDimension(Location::INTERIOR, Location::INTERIOR,
Dimension::L) &&
575 bool valueIM()
override {
576 return intMatrix.isOverlaps(dimA, dimB);
580 static std::unique_ptr<IMPredicate> overlaps();
607 class TouchesPredicate :
public IMPredicate {
609 std::string name()
const override {
610 return std::string(
"touches");
613 void init(
int _dimA,
int _dimB)
override {
614 IMPredicate::init(_dimA, _dimB);
615 bool isBothPoints = (dimA == 0 && dimB == 0);
616 require(! isBothPoints);
619 bool isDetermined()
const override {
620 bool isInteriorsIntersects = isIntersects(Location::INTERIOR, Location::INTERIOR);
621 return isInteriorsIntersects;
624 bool valueIM()
override {
625 return intMatrix.isTouches(dimA, dimB);
629 static std::unique_ptr<IMPredicate> touches();
639 static std::unique_ptr<TopologyPredicate> matches(
const std::string& imPattern)
641 return std::unique_ptr<TopologyPredicate>(
new IMPatternMatcher(imPattern));
@ A
Dimension value of a surface (2).
Definition: Dimension.h:46
@ L
Dimension value of a curve (1).
Definition: Dimension.h:43
@ P
Dimension value of a point (0).
Definition: Dimension.h:40
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
bool equals(const Envelope *other) const
Returns true if the Envelope other spatially equals this Envelope.
static bool intersects(const CoordinateXY &p1, const CoordinateXY &p2, const CoordinateXY &q)
Test the point q to see whether it intersects the Envelope defined by p1-p2.
bool isNull(void) const
Returns true if this Envelope is a "null" envelope.
Definition: Envelope.h:252
bool disjoint(const Envelope &other) const
Definition: Envelope.h:596
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:32
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25