Distance measurement analysis

View inQMLC++
View on GitHub
Sample viewer app

Measure distances between two points in 3D.

screenshot

Use case

The distance measurement analysis allows you to add to your app the same interactive measuring experience found in ArcGIS Pro, City Engine, and the ArcGIS API for JavaScript. You can set the unit system of measurement (metric or imperial). The units automatically switch to one appropriate for the current scale.

How to use the sample

Choose a unit system for the measurement. Click any location in the scene to start measuring. Move the mouse to an end location, and click to complete the measurement. Click a new location to clear and start a new measurement.

How it works

  1. Create an AnalysisOverlay object and add it to the analysis overlay collection of the SceneView object.
  2. Specify the start location and end location to create a LocationDistanceMeasurement object. Initially, the start and end locations can be the same point.
  3. Add the location distance measurement analysis to the analysis overlay.
  4. The measurementChanged signal will trigger if the distances change. You can get the new values for the directDistance, horizontalDistance, and verticalDistance from the MeasurementChanged object returned by the signal.

Relevant API

  • AnalysisOverlay
  • LocationDistanceMeasurement
  • MeasurementChanged

Additional information

The LocationDistanceMeasurement analysis only performs planar distance calculations. This may not be appropriate for large distances where the Earth's curvature must be considered.

Tags

3D, analysis, distance, measure

Sample Code

DistanceMeasurementAnalysis.qmlDistanceMeasurementAnalysis.cppDistanceMeasurementAnalysis.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// [WriteFile Name=DistanceMeasurementAnalysis, Category=Analysis]
// [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.Controls 2.2
import Esri.Samples 1.0

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

    SceneView {
        objectName: "sceneView"
        anchors.fill: parent
    }

    Rectangle {
        anchors {
            fill: resultsColumn
            margins: -5
        }
        color: "black"
        opacity: 0.5
        radius: 5
    }

    Column {
        id: resultsColumn
        anchors {
            left: parent.left
            top: parent.top
            margins: 10
        }
        spacing: 5

        Row {
            spacing: 5
            Text {
                text: "Direct Distance:"
                color: "white"
            }
            Text {
                id: directDistanceText
                color: "white"
                text: directDistance
            }
        }
        Row {
            spacing: 5
            Text {
                text: "Vertical Distance:"
                color: "white"
            }
            Text {
                id: verticalDistanceText
                color: "white"
                text: verticalDistance
            }
        }
        Row {
            spacing: 5
            Text {
                text: "Horizontal Distance:"
                color: "white"
            }
            Text {
                id: horizontalDistanceText
                color: "white"
                text: horizontalDistance
            }
        }
        Row {
            spacing: 5
            Text {
                text: "Unit System:"
                color: "white"
            }
            ComboBox {
                id: comboBox
                property int modelWidth: 0
                width: modelWidth + leftPadding + rightPadding + indicator.width
                model: ["Metric", "Imperial"]
                onCurrentTextChanged: setUnits(currentText);
                Component.onCompleted : {
                    for (let i = 0; i < model.length; ++i) {
                        metrics.text = model[i];
                        modelWidth = Math.max(modelWidth, metrics.width);
                    }
                }

                TextMetrics {
                    id: metrics
                    font: comboBox.font
                }
            }
        }
    }
}

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