Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Viewshed (camera)

Sample Viewer View Sample on GitHub

This sample demonstrates how to calculate a Viewshed from a SceneView's current Camera Viewpoint.

Use case

A viewshed analysis is a type of visual analysis you can perform on a scene. The viewshed aims to answer the question 'What can I see from a given location?'. The output is an overlay with two different colors - one representing the visible areas (green) and the other representing the obstructed areas (red).

How to use the sample

The sample will start with a viewshed created from the initial camera location, so only the visible (green) portion of the viewshed will be visible. Move around the scene to see the obstructed (red) portions. Click the 'Update from Camera' button to update the viewshed to the current camera position.

How it works

  1. Get the current camera from the scene with SceneView.currentViewpointCamera.
  2. Create a LocationViewshed, passing in the Camera and a min/max distance.
  3. Update the viewshed from a camera.

Relevant API

  • AnalysisOverlay
  • ArcGISScene
  • ArcGISSceneLayer
  • ArcGISTiledElevationSource
  • Camera
  • LocationViewshed
  • SceneView

About the data

The scene shows a buildings layer in Brest, France with a local elevation source image service both hosted on ArcGIS Online.

Tags

3D, Scene, viewshed, visibility analysis

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.9

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

    

    SceneView {
        id: sceneView
        anchors.fill: parent

        Scene {
            id: scene
            BasemapImagery {}

            // Set the Scene's Surface
            Surface {
                ArcGISTiledElevationSource {
                    url: "https://scene.arcgis.com/arcgis/rest/services/BREST_DTM_1M/ImageServer"
                }
            }

            // Add a Scene Layer
            ArcGISSceneLayer {
                url: "https://tiles.arcgis.com/tiles/P3ePLMYs2RVChkJx/arcgis/rest/services/Buildings_Brest/SceneServer/layers/0"
            }

            // Set an initial viewpoint
            ViewpointCenter {
                Point {
                    id: centerPt
                    x: -4.49492
                    y: 48.3808
                    z: 48.2511
                    spatialReference: Factory.SpatialReference.createWgs84()
                }
                targetScale: 62.01

                Camera {
                    id: camera
                    location: centerPt
                    heading: 344.488
                    pitch: 74.1212
                    roll: 0
                }
            }
        }

        // Declare an Analysis Overlay
        AnalysisOverlay {
            // Create the Location Viewshed
            LocationViewshed {
                id: locationViewshed
                minDistance: 1
                maxDistance: 1000
                frustumOutlineVisible: true
            }
        }
    }

    // calculate the viewshed on clicked
    Button {
        anchors {
            left: parent.left
            top: parent.top
            margins: 10
        }
        text: "Calculate Viewshed"
        onClicked: locationViewshed.updateFromCamera(sceneView.currentViewpointCamera);
    }
}