I would like to create with code something similar to this: https://pro.arcgis.com/en/pro-app/latest/help/mapping/exploratory-analysis/interactive-viewshed.htm
Using code I can read parameters from file and control the process beter.
I found the Viewshed class that looks like the class I need.
There are no examples I could find.
I could set the Camera properties and the Viewshed properties, but I cannot connect it to any MapView.
The MapView property is read-only. It is null when I run my code and no viewshed is created on screen.
There should be a way to define it but I cannot find it.
I connect my camera into the map (Camera camera = MapView.Active.Camera) then I just updated the properties (x,y, etc) but it did not help.
Thanks
Solved! Go to Solution.
Hi,
MapView has method AddExploratoryAnalysisAsync. Viewshed is derived from ExploratoryAnalysis. Code below:
protected override async void OnClick()
{
var mapView = MapView.Active;
if (mapView == null)
return;
var observerPointLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("ObserverPoint"));
if (observerPointLayer == null)
return;
ExploratoryAnalysis item0 = await QueuedTask.Run(() => {
#region Get the observer point
var observerPtCursor = observerPointLayer.Search();
MapPoint observerPoint = null; MapPoint targetPoint = null;
MapPoint observerPointProjected = null;
while (observerPtCursor.MoveNext())
{
var observerPtFeature = observerPtCursor.Current as Feature;
observerPoint = observerPtFeature.GetShape() as MapPoint;
observerPointProjected = GeometryEngine.Instance.
Project(observerPoint, mapView.Map.SpatialReference) as MapPoint;
}
#endregion
Camera camera = new Camera(observerPointProjected.X, observerPointProjected.Y, 10.0, 0, 0);
Viewshed viewshed = new Viewshed(camera, 0, 180, 100, 1000);
return viewshed;
});
await mapView.AddExploratoryAnalysisAsync(item0);
}
Hi,
MapView has method AddExploratoryAnalysisAsync. Viewshed is derived from ExploratoryAnalysis. Code below:
protected override async void OnClick()
{
var mapView = MapView.Active;
if (mapView == null)
return;
var observerPointLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("ObserverPoint"));
if (observerPointLayer == null)
return;
ExploratoryAnalysis item0 = await QueuedTask.Run(() => {
#region Get the observer point
var observerPtCursor = observerPointLayer.Search();
MapPoint observerPoint = null; MapPoint targetPoint = null;
MapPoint observerPointProjected = null;
while (observerPtCursor.MoveNext())
{
var observerPtFeature = observerPtCursor.Current as Feature;
observerPoint = observerPtFeature.GetShape() as MapPoint;
observerPointProjected = GeometryEngine.Instance.
Project(observerPoint, mapView.Map.SpatialReference) as MapPoint;
}
#endregion
Camera camera = new Camera(observerPointProjected.X, observerPointProjected.Y, 10.0, 0, 0);
Viewshed viewshed = new Viewshed(camera, 0, 180, 100, 1000);
return viewshed;
});
await mapView.AddExploratoryAnalysisAsync(item0);
}
Hi
It is working great - thanks.
There should be a sample or a snippet or at least a line in the help for Viewshed class or ExploratoryAnalysis class.
Thanks again
Mody