Spatial relationships

Create and move geometries to determine the spatial relationships that are satisfied.

What is a spatial relationship analysis?

A spatial relationship analysis is the process of determining the topological association between two geometries. For example, you can determine if two geometries contain, cross, overlap, cross, intersect, or touch one another. To execute the analysis, you can use ArcGIS Maps SDK for JavaScript, ArcGIS Maps SDKs for Native Apps, or ArcGIS API for Python. See the code examples below.

How to determine the spatial relationship

To determine if a spatial relationship exists between two shapes, you have to create the geometries and test for a specific type of relationship. Most client APIs have specific methods for each operation. All operations return true or false.

To determine if a spatial relationship exists:

  1. Create two geometries with the same spatial reference.
  2. Use an operation to test for a specific type of spatial relationship. For example, intersects.
  3. Evaluate the return value (true or false).

Types of spatial relationship operations

The table below includes operations for determining common spatial relationships between two geometries. They return true or false indicating if the geometries satisfy the relation or not.

OperationDescription
Relation (yellow = true)
ContainsReturns true if one geometry contains another geometry.
The left geometry contains the top geometry.
DisjointReturns true if one geometry does not intersect another geometry.
The left geometry is disjoint from the top geometry.
IntersectsReturns true if one geometry intersects another geometry.
The left geometry intersects the top geometry.
OverlapsReturns true if one geometry overlaps another geometry. NOTE: Only valid for geometries of the same type or dimension.
The left geometry overlaps the top geometry.
TouchesReturns true if one geometry touches another geometry.
The left geometry touches the top geometry.
WithinReturns true if one geometry is fully within another geometry.
The left geometry is within the top geometry.
RelateReturns true if input geometries satisfy the specified DE-9IM spatial relation. You can provide any combination of the supported DE-9IM operations.

Custom spatial relationships

You can test for a custom spatial relationship by defining your own relation. For example, you can create a relation that tests if two geometries intersect and touch. To do so, see the Relate example below.

Code examples

Contains

Determine if one geometry contains another geometry.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
      const contains = geometryEngine.contains(squareOutside, squareInside);
      if (contains) {
        console.log("The outer square contains the inner square.");
      }

Disjoint

Determine if two geometries are disjoint.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
      const disjoint = geometryEngine.disjoint(leftSquare, rightSquare);
      if (disjoint) {
        console.log("The squares are disjoint.");
      }

Intersects

Determine if two geometries intersect.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      const intersects = geometryEngine.intersects(line, square);
      if (intersects) {
        console.log("The line intersects the square.");
      }

Overlaps

Determine if two geometries overlap.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      const overlaps = geometryEngine.overlaps(rectangle, square);
      if (overlaps) {
        console.log("The rectangle and square overlap.");
      }

Touches

Determine if two geometries touch.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      const touches = geometryEngine.touches(triangle, square);
      if (touches) {
        console.log("The triangle touches the square.");
      }

Within

Determine if one geometry is fully within another.


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
      const within = geometryEngine.within(square, rectangle);
      if (within) {
        console.log("The square is within the rectangle.");
      }

Relate

Determine if the geometries satisfy a custom DE-9IM relation. The test below is for a polyline that intersects and touches the a part of the square. The test is: "FFT****".


ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)Python
Expand
Use dark colors for code blocksCopy
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      // Default DE-91M relations
      //   touches FF*FT****
      //   intersects ****T****
      // Custom relation: touches + intersects = *F*FT****
      const related = geometryEngine.relate(polyline, square, "*F*FT****");
      if (related) {
        console.log("The line touches and intersects the square.");
      }

Tutorials

API support

Spatial relationshipGeometric calculationLength and areaProjection
ArcGIS Maps SDK for JavaScript
ArcGIS Maps SDK for .NET
ArcGIS Maps SDK for Kotlin
ArcGIS Maps SDK for Swift
ArcGIS Maps SDK for Java
ArcGIS Maps SDK for Qt
ArcGIS API for Python
ArcGIS REST JS
Esri Leaflet
MapBox GL JS
OpenLayers
Full supportPartial supportNo support

    Tools

    Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.