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>
31class GEOS_DLL RelatePredicate {
59class IntersectsPredicate :
public BasicPredicate {
63 std::string name()
const override {
64 return std::string(
"intersects");
67 bool requireSelfNoding()
const override {
72 bool requireExteriorCheck(
bool isSourceA)
const override {
78 void init(
const Envelope& envA,
const Envelope& envB)
override {
79 require(envA.intersects(envB));
82 void updateDimension(Location locA, Location locB,
int dimension)
override {
84 setValueIf(
true, isIntersection(locA, locB));
87 void finish()
override {
94static std::unique_ptr<BasicPredicate> intersects();
112class DisjointPredicate :
public BasicPredicate {
114 std::string name()
const override {
115 return std::string(
"disjoint");
118 bool requireSelfNoding()
const override {
123 bool requireInteraction()
const override {
128 bool requireExteriorCheck(
bool isSourceA)
const override {
134 void init(
const Envelope& envA,
const Envelope& envB)
override {
135 setValueIf(
true, envA.disjoint(envB));
138 void updateDimension(Location locA, Location locB,
int dimension)
override {
140 setValueIf(
false, isIntersection(locA, locB));
143 void finish()
override {
149static std::unique_ptr<BasicPredicate> disjoint();
175class ContainsPredicate :
public IMPredicate {
177 std::string name()
const override {
178 return std::string(
"contains");
181 bool requireCovers(
bool isSourceA)
override {
182 return isSourceA == RelateGeometry::GEOM_A;
185 bool requireExteriorCheck(
bool isSourceA)
const override {
187 return isSourceA == RelateGeometry::GEOM_B;
190 void init(
int _dimA,
int _dimB)
override {
191 IMPredicate::init(_dimA, _dimB);
192 require(isDimsCompatibleWithCovers(dimA, dimB));
195 void init(
const Envelope& envA,
const Envelope& envB)
override {
196 BasicPredicate::requireCovers(envA, envB);
199 bool isDetermined()
const override {
200 return intersectsExteriorOf(RelateGeometry::GEOM_A);
203 bool valueIM()
override {
204 return intMatrix.isContains();
208static std::unique_ptr<IMPredicate> contains();
236class WithinPredicate :
public IMPredicate {
238 std::string name()
const override {
239 return std::string(
"within");
242 bool requireCovers(
bool isSourceA)
override {
243 return isSourceA == RelateGeometry::GEOM_B;
246 bool requireExteriorCheck(
bool isSourceA)
const override {
248 return isSourceA == RelateGeometry::GEOM_A;
251 void init(
int _dimA,
int _dimB)
override {
252 IMPredicate::init(_dimA, _dimB);
253 require(isDimsCompatibleWithCovers(dimB, dimA));
256 void init(
const Envelope& envA,
const Envelope& envB)
override {
257 BasicPredicate::requireCovers(envB, envA);
260 bool isDetermined()
const override {
261 return intersectsExteriorOf(RelateGeometry::GEOM_B);
264 bool valueIM()
override {
265 return intMatrix.isWithin();
269static std::unique_ptr<IMPredicate> within();
304class CoversPredicate :
public IMPredicate {
306 std::string name()
const override {
307 return std::string(
"covers");
310 bool requireCovers(
bool isSourceA)
override {
311 return isSourceA == RelateGeometry::GEOM_A;
314 bool requireExteriorCheck(
bool isSourceA)
const override {
316 return isSourceA == RelateGeometry::GEOM_B;
319 void init(
int _dimA,
int _dimB)
override {
320 IMPredicate::init(_dimA, _dimB);
321 require(isDimsCompatibleWithCovers(dimA, dimB));
324 void init(
const Envelope& envA,
const Envelope& envB)
override {
325 BasicPredicate::requireCovers(envA, envB);
329 bool isDetermined()
const override {
330 return intersectsExteriorOf(RelateGeometry::GEOM_A);
333 bool valueIM()
override {
334 return intMatrix.isCovers();
338static std::unique_ptr<IMPredicate> covers();
368class CoveredByPredicate :
public IMPredicate {
370 std::string name()
const override {
371 return std::string(
"coveredBy");
374 bool requireCovers(
bool isSourceA)
override {
375 return isSourceA == RelateGeometry::GEOM_B;
378 bool requireExteriorCheck(
bool isSourceA)
const override {
380 return isSourceA == RelateGeometry::GEOM_A;
383 void init(
int _dimA,
int _dimB)
override {
384 IMPredicate::init(_dimA, _dimB);
385 require(isDimsCompatibleWithCovers(dimB, dimA));
388 void init(
const Envelope& envA,
const Envelope& envB)
override {
389 BasicPredicate::requireCovers(envB, envA);
392 bool isDetermined()
const override {
393 return intersectsExteriorOf(RelateGeometry::GEOM_B);
396 bool valueIM()
override {
397 return intMatrix.isCoveredBy();
402static std::unique_ptr<IMPredicate> coveredBy();
428class CrossesPredicate :
public IMPredicate {
430 std::string name()
const override {
431 return std::string(
"crosses");
434 void init(
int _dimA,
int _dimB)
override {
435 IMPredicate::init(_dimA, _dimB);
436 bool isBothPointsOrAreas =
437 (dimA == Dimension::P && dimB == Dimension::P) ||
438 (dimA == Dimension::A && dimB == Dimension::A);
439 require(!isBothPointsOrAreas);
442 bool isDetermined()
const override {
443 if (dimA == Dimension::L && dimB == Dimension::L) {
445 if (getDimension(Location::INTERIOR, Location::INTERIOR) > Dimension::P)
448 else if (dimA < dimB) {
449 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
450 isIntersects(Location::INTERIOR, Location::EXTERIOR)) {
454 else if (dimA > dimB) {
455 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
456 isIntersects(Location::EXTERIOR, Location::INTERIOR)) {
463 bool valueIM()
override {
464 return intMatrix.isCrosses(dimA, dimB);
468static std::unique_ptr<IMPredicate> crosses();
484class EqualsTopoPredicate :
public IMPredicate {
486 std::string name()
const override {
487 return std::string(
"equals");
490 bool requireInteraction()
const override {
495 void init(
int _dimA,
int _dimB)
override {
496 IMPredicate::init(_dimA, _dimB);
500 void init(
const Envelope& envA,
const Envelope& envB)
override {
502 setValueIf(
true, envA.isNull() && envB.isNull());
504 require(envA.equals(&envB));
507 bool isDetermined()
const override {
508 bool isEitherExteriorIntersects =
509 isIntersects(Location::INTERIOR, Location::EXTERIOR) ||
510 isIntersects(Location::BOUNDARY, Location::EXTERIOR) ||
511 isIntersects(Location::EXTERIOR, Location::INTERIOR) ||
512 isIntersects(Location::EXTERIOR, Location::BOUNDARY);
514 return isEitherExteriorIntersects;
517 bool valueIM()
override {
518 return intMatrix.isEquals(dimA, dimB);
523static std::unique_ptr<IMPredicate> equalsTopo();
545class OverlapsPredicate :
public IMPredicate {
547 std::string name()
const override {
548 return std::string(
"overlaps");
551 void init(
int _dimA,
int _dimB)
override {
552 IMPredicate::init(_dimA, _dimB);
553 require(dimA == dimB);
556 bool isDetermined()
const override {
557 if (dimA == Dimension::A || dimA == Dimension::P) {
558 if (isIntersects(Location::INTERIOR, Location::INTERIOR) &&
559 isIntersects(Location::INTERIOR, Location::EXTERIOR) &&
560 isIntersects(Location::EXTERIOR, Location::INTERIOR))
563 if (dimA == Dimension::L) {
564 if (isDimension(Location::INTERIOR, Location::INTERIOR, Dimension::L) &&
565 isIntersects(Location::INTERIOR, Location::EXTERIOR) &&
566 isIntersects(Location::EXTERIOR, Location::INTERIOR))
572 bool valueIM()
override {
573 return intMatrix.isOverlaps(dimA, dimB);
577static std::unique_ptr<IMPredicate> overlaps();
604class TouchesPredicate :
public IMPredicate {
606 std::string name()
const override {
607 return std::string(
"touches");
610 void init(
int _dimA,
int _dimB)
override {
611 IMPredicate::init(_dimA, _dimB);
612 bool isBothPoints = (dimA == 0 && dimB == 0);
613 require(! isBothPoints);
616 bool isDetermined()
const override {
617 bool isInteriorsIntersects = isIntersects(Location::INTERIOR, Location::INTERIOR);
618 return isInteriorsIntersects;
621 bool valueIM()
override {
622 return intMatrix.isTouches(dimA, dimB);
626static std::unique_ptr<IMPredicate> touches();
636static std::unique_ptr<TopologyPredicate> matches(
const std::string& imPattern)
638 return std::unique_ptr<TopologyPredicate>(
new IMPatternMatcher(imPattern));
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:39