/
relation.clj
71 lines (68 loc) · 2.47 KB
/
relation.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(ns cljts.relation
(:refer-clojure :exclude [contains?])
(:import [com.vividsolutions.jts.geom Geometry])
(:import [com.vividsolutions.jts.geom.prep PreparedGeometry]))
(defprotocol GeometryRelations
(equals? [this that]
"Given two (topologically closed) geometric objects \"a\" and \"b\":
a.Equals(b) ⇔ a ⊆ b ∧ b ⊆ a")
(disjoint? [this that]
"Given two (topologically closed) geometric objects \"a\" and \"b\":
a.Disjoint(b) ⇔ a ∩ b = ∅")
(intersects? [this that]
"a.Intersects(b) ⇔ ! a.Disjoint(b)")
(touches? [this that]
"The Touches relationship between two geometric objects \"a\" and \"b\" applies to the A/A, L/L, L/A, P/A and P/L groups of relationships but not to the P/P group. It is defined as
a.Touch(b) ⇔ (I(a)∩I(b)=∅)∧(a∩b)≠∅")
(crosses? [this that]
"The Crosses relationship applies to P/L, P/A, L/L and L/A situations. It is defined as
a.Cross(b) ⇔ [I(a)∩I(b)≠∅ ∧ (a ∩ b ≠a) ∧ (a ∩ b ≠b)]")
(within? [this that]
"The Within relationship is defined as: a.Within(b) ⇔ (a∩b=a) ∧ (I(a)∩E(b)=∅)")
(contains? [this that]
"a.Contains(b) ⇔ b.Within(a)")
(overlaps? [this that]
"The Overlaps relationship is defined for A/A, L/L and P/P situations. It is defined as
a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a) ∩ I(b))) ∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b)")
(relate? [this that relation]
"check relationship by DE9-IM string")
(relation [this that]
"get DE9-IM string between to objects"))
(extend-type Geometry
GeometryRelations
(equals? [this that]
(.equals this that))
(disjoint? [this that]
(.disjoint this that))
(intersects? [this that]
(.intersects this that))
(touches? [this that]
(.touches this that))
(crosses? [this that]
(.crosses this that))
(within? [this that]
(.within this that))
(contains? [this that]
(.contains this that))
(overlaps? [this that]
(.overlaps this that))
(relate? [this that de9-im]
(.relate this that de9-im))
(relation [this that]
(.toString (.relate this that))))
(extend-type PreparedGeometry
GeometryRelations
(disjoint? [this that]
(.disjoint this that))
(intersects? [this that]
(.intersects this that))
(touches? [this that]
(.touches this that))
(crosses? [this that]
(.crosses this that))
(within? [this that]
(.within this that))
(contains? [this that]
(.contains this that))
(overlaps? [this that]
(.overlaps this that)))