Viewshed (Geoprocessing)

View inQMLC++
View on GitHub
Sample viewer app

Calculate a viewshed using a geoprocessing service, in this case showing which parts of a landscape are visible from points on mountainous terrain.

Image of viewshed geoprocessing

Use case

A viewshed is used to highlight what is visible from a given point. A viewshed could be created to show what a hiker might be able to see from a given point at the top of a mountain. Equally, a viewshed could also be created from a point representing the maximum height of a proposed wind turbine to see from what areas the turbine would be visible.

How to use the sample

Click the map to see all areas visible from that point within a 15km radius. Clicking on an elevated area will highlight a larger part of the surrounding landscape. It may take a few seconds for the task to run and send back the results.

How it works

  1. Create a GeoprocessingTask object with the URL set to a geoprocessing service endpoint.
  2. Create a FeatureCollectionTable object and add a new Feature object whose geometry is the viewshed's observer Point.
  3. Make a GeoprocessingParameters object passing in the observer point.
  4. Use the geoprocessing task to create a GeoprocessingJob object with the parameters.
  5. Start the job and wait for it to complete and return a GeoprocessingResult object.
  6. Get the resulting GeoprocessingFeatures object.
  7. Iterate through the viewshed features to use their geometry or display the geometry in a new Graphic object.

Relevant API

  • FeatureCollectionTable
  • GeoprocessingFeatures
  • GeoprocessingJob
  • GeoprocessingParameters
  • GeoprocessingResult
  • GeoprocessingTask

Tags

geoprocessing, heat map, heatmap, viewshed

Sample Code

AnalyzeViewshed.qmlAnalyzeViewshed.cppAnalyzeViewshed.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
// [WriteFile Name=AnalyzeViewshed, Category=Analysis]
// [Legal]
// Copyright 2016 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 QtQuick.Layouts 1.3
import Esri.Samples 1.0

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

    MapView {
        anchors.fill: parent
        objectName: "mapView"
    }

    onDisplayErrorDialog: {
        messageDialog.title = "Error";
        messageDialog.text = titleText;
        messageDialog.detailedText = detailedText;
        messageDialog.open();
    }

    // Create rectangle to display the status
    Rectangle {
        anchors {
            margins: -10
            fill: statusColumn
        }
        color: "lightgrey"
        radius: 5
        border.color: "black"
        opacity: 0.85
    }

    Column {
        id: statusColumn
        anchors {
            right: parent.right
            top: parent.top
            margins: 20
        }

        Text {
            anchors.margins: 5
            visible: !viewshedInProgress
            text: "Click map to execute viewshed analysis"
            font.pixelSize: 12
        }

        Row {
            anchors.margins: 5
            visible: viewshedInProgress
            spacing: 10

            BusyIndicator {
                anchors.verticalCenter: parent.verticalCenter
                width: 22
                height: width
            }

            Text {
                anchors.verticalCenter: parent.verticalCenter
                text: statusText
                font.pixelSize: 12
            }
        }
    }

    Dialog {
        id: messageDialog
        modal: true
        x: Math.round(parent.width - width) / 2
        y: Math.round(parent.height - height) / 2
        standardButtons: Dialog.Ok
        title: "Error"
        property alias text : textLabel.text
        property alias detailedText : detailsLabel.text
        ColumnLayout {
            Text {
                id: textLabel
                text: "Executing geoprocessing failed."
            }
            Text {
                id: detailsLabel
            }
        }
    }
}

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