Perform an exploratory viewshed analysis from a defined vantage point.
Use case
An exploratory viewshed analysis is a type of visual analysis you can perform at the current rendered resolution of a scene. The exploratory viewshed shows what can be seen 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).
Note: This analysis is a form of "exploratory analysis", which means the results are calculated on the current scale of the data, and the results are generated very quickly but not persisted. If persisted analysis performed at the full resolution of the data is required, consider using a ViewshedFunction to perform a viewshed calculation instead.
How to use the sample
Use the sliders to change the properties (heading, pitch, etc.), of the exploratory viewshed and see them updated in real time. To move the exploratory viewshed, double touch and drag your finger across the screen. Lift your finger to stop moving the exploratory viewshed.
How it works
- Create a
ExploratoryLocationViewshedpassing in the observer location, heading, pitch, horizontal/vertical angles, and min/max distances. - Set the property values on the exploratory viewshed instance for location, direction, range, and visibility properties.
Relevant API
- AnalysisOverlay
- ArcGISSceneLayer
- ArcGISTiledElevationSource
- ExploratoryLocationViewshed
About the data
The scene shows a buildings layer in Brest, France hosted on ArcGIS Online.
Tags
3D, exploratory viewshed, frustum, scene, visibility analysis
Sample Code
// [WriteFile Name=ShowExploratoryViewshedFromPointInScene, Category=Analysis]
// [Legal]
// Copyright 2017 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]
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
// sample headers
#include "ShowExploratoryViewshedFromPointInScene.h"
// ArcGIS Maps SDK headers
#include "AnalysisListModel.h"
#include "AnalysisOverlay.h"
#include "AnalysisOverlayListModel.h"
#include "ArcGISTiledElevationSource.h"
#include "Camera.h"
#include "ElevationSourceListModel.h"
#include "ExploratoryLocationViewshed.h"
#include "MapTypes.h"
#include "Point.h"
#include "Scene.h"
#include "SceneQuickView.h"
#include "SpatialReference.h"
#include "Surface.h"
// Qt headers
#include <QFuture>
using namespace Esri::ArcGISRuntime;
ShowExploratoryViewshedFromPointInScene::ShowExploratoryViewshedFromPointInScene(QQuickItem* parent /* = nullptr */) :
QQuickItem(parent)
{
}
void ShowExploratoryViewshedFromPointInScene::init()
{
// Register classes for QML
qmlRegisterType<SceneQuickView>("Esri.Samples", 1, 0, "SceneView");
qmlRegisterType<ShowExploratoryViewshedFromPointInScene>("Esri.Samples", 1, 0, "ShowExploratoryViewshedFromPointInSceneSample");
}
void ShowExploratoryViewshedFromPointInScene::componentComplete()
{
QQuickItem::componentComplete();
// Create a scene and give it to the SceneView
m_sceneView = findChild<SceneQuickView*>("sceneView");
Scene* scene = new Scene(BasemapStyle::ArcGISTopographic, this);
Surface* surface = new Surface(this);
surface->elevationSources()->append(
new ArcGISTiledElevationSource(QUrl("https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer"), this));
scene->setBaseSurface(surface);
m_sceneView->setArcGISScene(scene);
// Add an Analysis Overlay
m_analysisOverlay = new AnalysisOverlay(this);
m_sceneView->analysisOverlays()->append(m_analysisOverlay);
// set initial viewpoint
setInitialViewpoint();
// connect signals
connectSignals();
}
void ShowExploratoryViewshedFromPointInScene::setInitialViewpoint()
{
// Set a viewpoint
double x = 6.86088;
double y = 45.3604;
double z = 3582.55;
Point point(x, y, z, SpatialReference(4326));
double heading = 345;
double pitch = 70;
double roll = 0;
Camera camera(point, heading, pitch, roll);
m_sceneView->setViewpointCameraAsync(camera);
}
void ShowExploratoryViewshedFromPointInScene::connectSignals()
{
// on mouse click perform the location viewshed
connect(m_sceneView, &SceneQuickView::mouseClicked, this, [this](QMouseEvent& event)
{
if (!m_locationViewshed)
{
createViewshed(event.position().x(), event.position().y());
}
else
{
const Point pt = m_sceneView->screenToBaseSurface(event.position().x(), event.position().y());
m_locationViewshed->setLocation(pt);
}
});
connect(m_sceneView, &SceneQuickView::mousePressedAndHeld, this, [this](QMouseEvent& event)
{
if (!m_locationViewshed)
{
createViewshed(event.position().x(), event.position().y());
}
m_calculating = true;
});
connect(m_sceneView, &SceneQuickView::mouseMoved, this, [this](QMouseEvent& event)
{
if (m_calculating)
{
const Point pt = m_sceneView->screenToBaseSurface(event.position().x(), event.position().y());
m_locationViewshed->setLocation(pt);
}
});
connect(m_sceneView, &SceneQuickView::mouseReleased, this, [this]
{
m_calculating = false;
});
}
void ShowExploratoryViewshedFromPointInScene::createViewshed(double x, double y)
{
const Point pt = m_sceneView->screenToBaseSurface(x, y);
// Create the Location Viewshed
m_locationViewshed =
new ExploratoryLocationViewshed(pt, m_heading, m_pitch, m_horizontalAngle, m_veriticalAngle, m_minDistance, m_maxDistance, this);
m_locationViewshed->setVisible(m_viewshedVisible);
// Add the Viewshed to the Analysis Overlay
m_analysisOverlay->analyses()->append(m_locationViewshed);
return;
}
// Getters/Setters for each Q_PROPERTY
bool ShowExploratoryViewshedFromPointInScene::isViewshedVisible() const
{
return m_viewshedVisible;
}
void ShowExploratoryViewshedFromPointInScene::setViewshedVisible(bool viewshedVisible)
{
if (m_locationViewshed)
{
if (m_locationViewshed->isVisible() == viewshedVisible)
{
return;
}
m_viewshedVisible = viewshedVisible;
m_locationViewshed->setVisible(viewshedVisible);
}
else
{
if (m_viewshedVisible == viewshedVisible)
{
return;
}
m_viewshedVisible = viewshedVisible;
}
emit viewshedVisibleChanged();
}
bool ShowExploratoryViewshedFromPointInScene::isFrustumOutlineVisible() const
{
return m_locationViewshed ? m_locationViewshed->isFrustumOutlineVisible() : m_frustumVisible;
}
void ShowExploratoryViewshedFromPointInScene::setFrustumOutlineVisible(bool frustumVisible)
{
if (m_locationViewshed)
{
if (m_locationViewshed->isFrustumOutlineVisible() == frustumVisible)
{
return;
}
m_frustumVisible = frustumVisible;
m_locationViewshed->setFrustumOutlineVisible(frustumVisible);
}
else
{
if (m_frustumVisible == frustumVisible)
{
return;
}
m_frustumVisible = frustumVisible;
}
emit frustumVisibleChanged();
}
double ShowExploratoryViewshedFromPointInScene::minDistance() const
{
return m_locationViewshed ? m_locationViewshed->minDistance() : m_minDistance;
}
void ShowExploratoryViewshedFromPointInScene::setMinDistance(double minDistance)
{
if (m_locationViewshed)
{
if (m_locationViewshed->minDistance() == minDistance)
{
return;
}
m_minDistance = minDistance;
m_locationViewshed->setMinDistance(minDistance);
}
else
{
if (m_minDistance == minDistance)
{
return;
}
m_minDistance = minDistance;
}
emit minDistanceChanged();
}
double ShowExploratoryViewshedFromPointInScene::maxDistance() const
{
return m_locationViewshed ? m_locationViewshed->maxDistance() : m_maxDistance;
}
void ShowExploratoryViewshedFromPointInScene::setMaxDistance(double maxDistance)
{
m_maxDistance = maxDistance;
if (m_locationViewshed)
{
if (m_locationViewshed->maxDistance() == maxDistance)
{
return;
}
m_maxDistance = maxDistance;
m_locationViewshed->setMaxDistance(maxDistance);
}
else
{
if (m_maxDistance == maxDistance)
{
return;
}
m_maxDistance = maxDistance;
}
emit maxDistanceChanged();
}
double ShowExploratoryViewshedFromPointInScene::horizontalAngle() const
{
return m_locationViewshed ? m_locationViewshed->horizontalAngle() : m_horizontalAngle;
}
void ShowExploratoryViewshedFromPointInScene::setHorizontalAngle(double horizontalAngle)
{
if (m_locationViewshed)
{
if (m_locationViewshed->horizontalAngle() == horizontalAngle)
{
return;
}
m_horizontalAngle = horizontalAngle;
m_locationViewshed->setHorizontalAngle(horizontalAngle);
}
else
{
if (m_horizontalAngle == horizontalAngle)
{
return;
}
m_horizontalAngle = horizontalAngle;
}
emit horizontalAngleChanged();
}
double ShowExploratoryViewshedFromPointInScene::verticalAngle() const
{
return m_locationViewshed ? m_locationViewshed->verticalAngle() : m_veriticalAngle;
}
void ShowExploratoryViewshedFromPointInScene::setVerticalAngle(double verticalAngle)
{
if (m_locationViewshed)
{
if (m_locationViewshed->verticalAngle() == verticalAngle)
{
return;
}
m_veriticalAngle = verticalAngle;
m_locationViewshed->setVerticalAngle(verticalAngle);
}
else
{
if (m_veriticalAngle == verticalAngle)
{
return;
}
m_veriticalAngle = verticalAngle;
}
emit verticalAngleChanged();
}
double ShowExploratoryViewshedFromPointInScene::heading() const
{
return m_locationViewshed ? m_locationViewshed->heading() : m_heading;
}
void ShowExploratoryViewshedFromPointInScene::setHeading(double heading)
{
if (m_locationViewshed)
{
if (m_locationViewshed->heading() == heading)
{
return;
}
m_heading = heading;
m_locationViewshed->setHeading(heading);
}
else
{
if (m_heading == heading)
{
return;
}
m_heading = heading;
}
emit headingChanged();
}
double ShowExploratoryViewshedFromPointInScene::pitch() const
{
return m_locationViewshed ? m_locationViewshed->pitch() : m_pitch;
}
void ShowExploratoryViewshedFromPointInScene::setPitch(double pitch)
{
if (m_locationViewshed)
{
if (m_locationViewshed->pitch() == pitch)
{
return;
}
m_pitch = pitch;
m_locationViewshed->setPitch(pitch);
}
else
{
if (m_pitch == pitch)
{
return;
}
m_pitch = pitch;
}
emit pitchChanged();
}
QColor ShowExploratoryViewshedFromPointInScene::visibleColor() const
{
return ExploratoryLocationViewshed::visibleColor();
}
void ShowExploratoryViewshedFromPointInScene::setVisibleColor(const QColor& visibleColor)
{
if (ExploratoryLocationViewshed::visibleColor() == visibleColor)
{
return;
}
ExploratoryLocationViewshed::setVisibleColor(visibleColor);
emit visibleColorChanged();
}
QColor ShowExploratoryViewshedFromPointInScene::obstructedColor() const
{
return ExploratoryLocationViewshed::obstructedColor();
}
void ShowExploratoryViewshedFromPointInScene::setObstructedColor(const QColor& obstructedColor)
{
if (ExploratoryLocationViewshed::obstructedColor() == obstructedColor)
{
return;
}
ExploratoryLocationViewshed::setObstructedColor(obstructedColor);
emit obstructedColorChanged();
}