Spatial relationships

View inQMLC++
View on GitHub
Sample viewer app

Determine spatial relationships between two geometries.

screenshot

Use case

In case of a natural disaster, emergency services can represent the affected areas using polygons. By determining the spatial relationships between these and any other existing features such as populated areas, infrastructure, or natural resources, it is possible to quickly determine which of the existing features might be affected or is in further danger, helping to assess risk and define further action.

How to use the sample

Select one of the three graphics. The tree view will list the relationships the selected graphic has to the other graphic geometries.

How it works

  1. Get the geometry from two different graphics. In this example the geometry of the selected graphic is compared to the geometry of each unselected graphic.
  2. Use the methods in GeometryEngine to check the relationship between the geometries, e.g. contains, disjoint, intersects, etc. If the method returns true, the relationship exists.

Relevant API

  • Geometry
  • GeometryEngine
  • GeometryEngine::contains
  • GeometryEngine::crosses
  • GeometryEngine::disjoint
  • GeometryEngine::intersects
  • GeometryEngine::overlaps
  • GeometryEngine::touches
  • GeometryEngine::within
  • GeometryType
  • Graphic
  • Point
  • Polygon
  • Polyline

Tags

geometries, relationship, spatial analysis

Sample Code

SpatialRelationships.qmlSpatialRelationships.cppSpatialRelationships.h
                                                                                         
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
// [WriteFile Name=SpatialRelationships, Category=Geometry]
// [Legal]
// Copyright 2018 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import Esri.Samples 1.0

SpatialRelationshipsSample {
    id: rootRectangle
    clip: true
    width: 800
    height: 600



    // add a mapView component
    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    Rectangle {
        anchors {
            fill: relationshipColumn
            margins: -10
        }
        opacity: 0.85
        radius: 5
        color: "#e2e2e2"
        border {
            color: "darkgray"
            width: 1
        }
    }

    Column {
        id: relationshipColumn
        anchors {
            left: parent.left
            top: parent.top
            margins: 15
        }
        spacing: 5

        Text {
            text: "Relationships:"
            font {
                pixelSize: 16
                bold: true
                family: "helvetica"
            }
        }

        Text {
            id: pointText
            visible: text.length > 0
            font.family: "helvetica"
            text: pointRelationships
        }

        Text {
            id: lineText
            visible: text.length > 0
            font.family: "helvetica"
            text: polylineRelationships
        }

        Text {
            id: polygonText
            visible: text.length > 0
            font.family: "helvetica"
            text: polygonRelationships
        }
    }
}

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