Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Viewshed for location

This code sample is available for these platforms:
View Sample on GitHub

Perform a viewshed analysis from a defined vantage point. Viewshed analyses have several configuration options that are demonstrated in this sample.


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

Use the sliders to change the properties (heading, pitch, etc.), of the viewshed and see them updated in real time.

How it works

  1. Create a LocationViewshed passing in the observer location, heading, pitch, horizontal/vertical angles, and min/max distances.
  2. Set the property values on the viewshed instance for location, direction, range, and visibility properties.

Relevant API

  • AnalysisOverlay
  • ArcGISSceneLayer
  • ArcGISTiledElevationSource
  • LocationViewshed
  • Viewshed

About the data

The scene in this sample shows a buildings layer in Brest, France.


3D, AnalysisOverlay, LocationViewshed, Scene, frustum, viewshed, visibility analysis

Sample Code

        <Style TargetType="TextBlock">
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="0,0,5,10" />
        <Style TargetType="Slider">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="SnapsTo" Value="StepValues" />
            <Setter Property="StepFrequency" Value="1" />
        <esriUI:SceneView x:Name="MySceneView" />
        <Border Style="{StaticResource BorderStyle}">
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                <TextBlock Text="Heading"
                           Grid.Row="0" Grid.Column="0" />
                <TextBlock Text="Pitch"
                           Grid.Row="1" Grid.Column="0" />
                <TextBlock Text="Horizontal angle"
                           Grid.Row="2" Grid.Column="0" />
                <TextBlock Text="Vertical angle"
                           Grid.Row="3" Grid.Column="0" />
                <TextBlock Text="Height"
                           Grid.Row="4" Grid.Column="0" />
                <TextBlock Text="Minimum distance"
                           Grid.Row="5" Grid.Column="0" />
                <TextBlock Text="Maximum distance"
                           Grid.Row="6" Grid.Column="0" />
                <TextBlock Text="Frustum visibility"
                           Grid.Row="7" Grid.Column="0" />
                <TextBlock Text="Analysis visibility"
                           Grid.Row="8" Grid.Column="0" />

                <Slider x:Name="HeadingSlider"
                        Grid.Row="0" Grid.Column="1"
                        Value="0" Maximum="360"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="PitchSlider"
                        Grid.Row="1" Grid.Column="1"
                        Value="60" Maximum="180"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="HorizontalAngleSlider"
                        Grid.Row="2" Grid.Column="1"
                        Value="75" Maximum="120" Minimum="1"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="VerticalAngleSlider"
                        Grid.Row="3" Grid.Column="1"
                        Value="90" Maximum="120" Minimum="1"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="HeightSlider"
                        Grid.Row="4" Grid.Column="1"
                        Value="10" Maximum="200" Minimum="0"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="MinimumDistanceSlider"
                        Grid.Row="5" Grid.Column="1"
                        Value="5" Maximum="8999" Minimum="5"
                        ValueChanged="HandleSettingsChange" />
                <Slider x:Name="MaximumDistanceSlider"
                        Grid.Row="6" Grid.Column="1"
                        Value="1500" Minimum="1" Maximum="9999"
                        ValueChanged="HandleSettingsChange" />
                <CheckBox x:Name="FrustumVisibilityCheck"
                          Grid.Row="7" Grid.Column="1"
                          Unchecked="HandleSettingsChange" />
                <CheckBox x:Name="AnalysisVisibilityCheck"
                          Grid.Row="8" Grid.Column="1"
                          Unchecked="HandleSettingsChange" IsChecked="True" />

                <TextBlock Text="Tap to change the viewshed location."
                           Grid.Row="9" Grid.Column="0" Grid.ColumnSpan="2"
                           FontWeight="SemiBold" HorizontalAlignment="Center"
// 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:
// 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.

using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using System;
using System.Drawing;
using Windows.UI.Xaml;

namespace ArcGISRuntime.UWP.Samples.ViewshedLocation
        "Viewshed (Location)",
        "This sample demonstrates the configurable properties of viewshed analysis, including frustum color, heading, pitch, distances, angles, and location.",
        "Click anywhere in the scene to change the viewshed observer location."
    public partial class ViewshedLocation
        // Hold the URL to the elevation source.
        private readonly Uri _localElevationImageService = new Uri("");

        // Hold the URL to the buildings scene layer.
        private readonly Uri _buildingsUrl = new Uri("");

        // Hold a reference to the viewshed analysis.
        private LocationViewshed _viewshed;

        // Hold a reference to the analysis overlay that will hold the viewshed analysis.
        private AnalysisOverlay _analysisOverlay;

        // Graphics overlay for viewpoint symbol.
        private GraphicsOverlay _viewpointOverlay;

        // Symbol for viewpoint.
        private SimpleMarkerSceneSymbol _viewpointSymbol;

        // Height of the viewpoint above the ground.
        private double _viewHeight;

        public ViewshedLocation()

            // Initialize the sample.

        private void Initialize()
            _viewHeight = HeightSlider.Value;

            // Create the scene with the imagery basemap.
            Scene myScene = new Scene(Basemap.CreateImagery());
            MySceneView.Scene = myScene;

            // Add the surface elevation.
            Surface mySurface = new Surface();
            mySurface.ElevationSources.Add(new ArcGISTiledElevationSource(_localElevationImageService));
            myScene.BaseSurface = mySurface;

            // Add the scene layer.
            ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer(_buildingsUrl);

            // Create the MapPoint representing the initial location.
            MapPoint initialLocation = new MapPoint(-4.5, 48.4, 46 + _viewHeight);

            // Create the location viewshed analysis.
            _viewshed = new LocationViewshed(

            // Create a camera based on the initial location.
            Camera camera = new Camera(initialLocation, 200.0, 20.0, 70.0, 0.0);

            // Create a symbol for the viewpoint.
            _viewpointSymbol = SimpleMarkerSceneSymbol.CreateSphere(Color.Blue, 10, SceneSymbolAnchorPosition.Center);

            // Add the symbol to the viewpoint overlay.
            _viewpointOverlay = new GraphicsOverlay
                SceneProperties = new LayerSceneProperties(SurfacePlacement.Absolute)
            _viewpointOverlay.Graphics.Add(new Graphic(initialLocation, _viewpointSymbol));

            // Apply the camera to the scene view.

            // Create an analysis overlay for showing the viewshed analysis.
            _analysisOverlay = new AnalysisOverlay();

            // Add the viewshed analysis to the overlay.

            // Add the analysis overlay to the SceneView.

            // Add the graphics overlay

            // Update the frustum outline Color.
            // The frustum outline shows the volume in which the viewshed analysis is performed.
            Viewshed.FrustumOutlineColor = Color.Blue;

            // Subscribe to tap events. This enables the 'pick up' and 'drop' workflow for moving the viewpoint.
            MySceneView.GeoViewTapped += MySceneViewOnGeoViewTapped;

        private void MySceneViewOnGeoViewTapped(object sender, GeoViewInputEventArgs geoViewInputEventArgs)
            if (geoViewInputEventArgs.Location == null)
                // User clicked on the sky - don't update the location with invalid value.

            // Update the viewshed location.
            _viewshed.Location = geoViewInputEventArgs.Location;

            // Update the viewshed.
            _viewshed.Location = new MapPoint(_viewshed.Location.X, _viewshed.Location.Y, _viewshed.Location.Z + _viewHeight); ;

            // Update the viewpoint symbol.
            _viewpointOverlay.Graphics.Add(new Graphic(_viewshed.Location, _viewpointSymbol));

        private void HandleSettingsChange(object sender, RoutedEventArgs e)
            // Return if viewshed hasn't been created yet. This happens when the sample is starting.
            if (_viewshed == null)
            // Calculate the difference between the old and new height.
            double difference = HeightSlider.Value - _viewHeight;

            // Update the view height value to the new value.
            _viewHeight = HeightSlider.Value;

            // Move the viewshed to the new height.
            _viewshed.Location = new MapPoint(_viewshed.Location.X, _viewshed.Location.Y, _viewshed.Location.Z + difference);

            // Update the viewshed settings.
            _viewshed.Heading = HeadingSlider.Value;
            _viewshed.Pitch = PitchSlider.Value;
            _viewshed.HorizontalAngle = HorizontalAngleSlider.Value;
            _viewshed.VerticalAngle = VerticalAngleSlider.Value;
            _viewshed.MinDistance = MinimumDistanceSlider.Value;
            _viewshed.MaxDistance = MaximumDistanceSlider.Value;

            // Update visibility of the viewshed analysis.
            _viewshed.IsVisible = (bool)AnalysisVisibilityCheck.IsChecked;

            // Update visibility of the frustum. Note that the frustum will be invisible
            //     regardless of this setting if the viewshed analysis is not visible.
            _viewshed.IsFrustumOutlineVisible = (bool)FrustumVisibilityCheck.IsChecked;

            // Update the viewpoint graphic.
            _viewpointOverlay.Graphics.Add(new Graphic(_viewshed.Location, _viewpointSymbol));