Skip to content

Commit

Permalink
ArcGIS Pro 3.3 SDK for .NET
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolf-K committed May 6, 2024
1 parent 70f8c0c commit 4f3f355
Show file tree
Hide file tree
Showing 1,402 changed files with 18,840 additions and 2,804 deletions.
72 changes: 72 additions & 0 deletions 3DAnalyst/CreateLineOfSight/Config.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 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
https://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.
-->
<ArcGIS defaultAssembly="CreateLineOfSight.dll" defaultNamespace="CreateLineOfSight" xmlns="http://schemas.esri.com/DADF/Registry" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.esri.com/DADF/Registry file:///C:/Program%20Files/ArcGIS/Pro/bin/ArcGIS.Desktop.Framework.xsd">
<AddInInfo id="{bfc11bd9-b385-40eb-85e4-4821b118ad9a}" version="1.0" desktopVersion="3.2.51163" Pro="ArcGISPro">
<Name>CreateLineOfSight</Name>
<Description>CreateLineOfSight description</Description>
<Image>Images\AddinDesktop32.png</Image>
<Author>ArcGIS Pro SDK Team, [email protected]</Author>
<Company>esri, https://www.esri.com</Company>
<Date>1/18/2024 11:31:30 AM</Date>
<Subject>3DAnalyst</Subject>
<!-- Note subject can be one or more of these topics:
Content, Framework, Editing, Geodatabase, Geometry, Geoprocessing, Layouts, Map Authoring, Map Exploration -->
</AddInInfo>
<modules>
<insertModule id="CreateLineOfSight_Module" className="Module1" autoLoad="false" caption="Module1">
<!-- uncomment to have the control hosted on a separate tab-->
<tabs>
<tab id="CreateLineOfSight_Tab1" caption="LoS Demo" keytip="T0">
<group refID="CreateLineOfSight_Group1" />
</tab>
</tabs>
<groups>
<!-- comment this out if you have no controls on the Addin tab to avoid
an empty group-->
<group id="CreateLineOfSight_Group1" caption="Line of Sight" appearsOnAddInTab="false" keytip="G1">
<!-- host controls within groups -->
<!--<button refID="CreateLineOfSight_StartDemo" size="large" />-->
<button refID="CreateLineOfSight_LineOfSight" size="large" />
<!--<button refID="CreateLineOfSight_Reset" size="large" />-->

</group>
</groups>
<controls>
<!-- add your controls here -->
<button id="CreateLineOfSight_LineOfSight" caption="Sight Lines"
className="LineOfSight" loadOnClick="true" keytip="B1"
smallImage="BexDog16" largeImage="BexDog32">
<tooltip heading="Sight Lines">
Creates the Sight Lines<disabledText /></tooltip>
</button>
<button id="CreateLineOfSight_Reset" caption="Reset" className="Reset"
loadOnClick="true" keytip="B2"
smallImage="GenericReset16" largeImage="GenericReset32">
<tooltip heading="Reset">
Resets the created Sight Lines<disabledText /></tooltip>
</button>
<button id="CreateLineOfSight_StartDemo" caption="Start Demo" className="StartDemo"
loadOnClick="true" keytip="B3" smallImage="Play16" largeImage="Play32">
<tooltip heading="Start Demo">Prepare demo with required settings<disabledText /></tooltip>
</button>
</controls>
</insertModule>
</modules>
</ArcGIS>
48 changes: 48 additions & 0 deletions 3DAnalyst/CreateLineOfSight/CreateLineOfSight (C#).md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## CreateLineOfSight

<!-- TODO: Write a brief abstract explaining this sample -->
This sample demonstrates how to perform a line of sight analysis between an observer and a target point on a TIN surface.



<a href="https://pro.arcgis.com/en/pro-app/sdk/" target="_blank">View it live</a>

<!-- TODO: Fill this section below with metadata about this sample-->
```
Language: C#
Subject: 3DAnalyst
Contributor: ArcGIS Pro SDK Team <[email protected]>
Organization: Esri, https://www.esri.com
Date: 04/04/2024
ArcGIS Pro: 3.3
Visual Studio: 2022
.NET Target Framework: net8.0-windows
```

## Resources

[Community Sample Resources](https://github.com/Esri/arcgis-pro-sdk-community-samples#resources)

### Samples Data

* Sample data for ArcGIS Pro SDK Community Samples can be downloaded from the [Releases](https://github.com/Esri/arcgis-pro-sdk-community-samples/releases) page.

## How to use the sample
<!-- TODO: Explain how this sample can be used. To use images in this section, create the image file in your sample project's screenshots folder. Use relative url to link to this image using this syntax: ![My sample Image](FacePage/SampleImage.png) -->
1. In Visual Studio click the Build menu. Then select Build Solution.
2. Click Start button to open ArcGIS Pro.
3. ArcGIS Pro will open.
4. Open CreateLineOfSight.aprx from the Sample Data
5. Activate the "Line of Sight Demo" map if it is not already active.
6. Observe the green observer point push pin and the 3 red target point push pins on the map.
7. Click the Los Demo tab on the ribbon.
8. Click the "Sight Lines" button. This will run the Line of sight analysis between the observer and target points.
9. Three sight lines will be drawn from the observer point to the 3 target points. Each sight line will have a green visible section, a red invisible section and an optional purple Obstruction point (if any).
![UI](screenshots/screen1.png)


<!-- End -->

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://esri.github.io/arcgis-pro-sdk/images/ArcGISPro.png" alt="ArcGIS Pro SDK for Microsoft .NET Framework" height = "20" width = "20" align="top" >
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
[Home](https://github.com/Esri/arcgis-pro-sdk/wiki) | <a href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference" target="_blank">API Reference</a> | [Requirements](https://github.com/Esri/arcgis-pro-sdk/wiki#requirements) | [Download](https://github.com/Esri/arcgis-pro-sdk/wiki#installing-arcgis-pro-sdk-for-net) | <a href="https://github.com/esri/arcgis-pro-sdk-community-samples" target="_blank">Samples</a>
25 changes: 25 additions & 0 deletions 3DAnalyst/CreateLineOfSight/CreateLineOfSight.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34511.84
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CreateLineOfSight", "CreateLineOfSight.csproj", "{EC4E2934-86CC-4D1D-97F4-3C55EEEF1A4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EC4E2934-86CC-4D1D-97F4-3C55EEEF1A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC4E2934-86CC-4D1D-97F4-3C55EEEF1A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC4E2934-86CC-4D1D-97F4-3C55EEEF1A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC4E2934-86CC-4D1D-97F4-3C55EEEF1A4F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {87D65B6A-73EE-42D4-B004-AE91AF2CC186}
EndGlobalSection
EndGlobal
201 changes: 201 additions & 0 deletions 3DAnalyst/CreateLineOfSight/LineOfSight.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
Copyright 2024 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
https://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.
*/
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Editing.Attributes;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Internal.Mapping;
using ArcGIS.Desktop.Layouts;
using ArcGIS.Desktop.Mapping;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CreateLineOfSight
{
internal class LineOfSight : Button
{
protected override async void OnClick()
{
#region Get the active map view and the layers.
var mapView = MapView.Active;
if (mapView == null)
return;
var observerPointLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("ObserverPoint"));
var targetPointLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("TargetPoints"));
var lineOfSightLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("LineOfSights"));
var obstructionPtsLayer = mapView.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(layer => layer.Name.Equals("Obstructions"));
var editOpTargetPointVisibility = new EditOperation();
if (observerPointLayer == null || targetPointLayer == null || lineOfSightLayer == null || obstructionPtsLayer == null )
return;
//Set the environment for the Line of Sight analysis
//Delete the old Line of Sight results and select the observer point and target points
Module1.CallButtonClick("CreateLineOfSight_Reset");
Module1.CallButtonClick("CreateLineOfSight_StartDemo");
#endregion
//Initialize this to store the Line of sight analysis result.
IDictionary<long, LineOfSightResult> targetPtlineOfSightResultsMapping = new Dictionary<long, LineOfSightResult>();
var tinLayer = mapView.Map.GetLayersAsFlattenedList().
OfType<TinLayer>().FirstOrDefault();
await QueuedTask.Run(() => {
#region Get the observer point and the 3 target points from the feature layers in the map
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;
}
IDictionary<MapPoint, long> targetPoints = new Dictionary<MapPoint, long>();
var targetPtCursor = targetPointLayer.Search();
while (targetPtCursor.MoveNext())
{
var targetPtFeature = targetPtCursor.Current as Feature;
targetPoint = targetPtFeature.GetShape() as MapPoint;
var TargetPointProjected = GeometryEngine.Instance.Project(targetPoint, mapView.Map.SpatialReference) as MapPoint;
targetPoints.Add(TargetPointProjected, targetPtFeature.GetObjectID());
}
#endregion
//Run the Line of Sight analysis for each target point and the single observer point
foreach (var kvp in targetPoints)
{
var targetPt = kvp.Key;
var targetPtOID = kvp.Value;
//Step 1: Set the input values for the Line of Sight analysis
LineOfSightParams lineOfSightParams = new LineOfSightParams();
lineOfSightParams.TargetPoint = targetPt;
lineOfSightParams.ObserverPoint = observerPoint;
lineOfSightParams.OutputSpatialReference = mapView.Map.SpatialReference;
lineOfSightParams.ObserverHeightOffset = 0; //optional
lineOfSightParams.TargetHeightOffset = 0; //optional
#region Advanced settings for the Line of Sight analysis
//lineOfSightParams.ApplyCurvature = true;
//lineOfSightParams.RefractionFactor = 0.13;
//lineOfSightParams.ApplyRefraction = true;
#endregion
//Step 2: Check if the input parameters are valid
if (tinLayer.CanGetLineOfSight(lineOfSightParams))
{
//Step 3: Run the analysis
LineOfSightResult lineOfSightResult = tinLayer.GetLineOfSight(lineOfSightParams);
targetPtlineOfSightResultsMapping.Add(targetPtOID, lineOfSightResult); //store the result
}
}
#region Target Point Visibility - for labeling purpose only

editOpTargetPointVisibility.Name = "Target Point Visibility";
editOpTargetPointVisibility.SelectNewFeatures = false;
//use an inspector to modify the target feature with the visibility attribute
var modifyTargetPtsLyrInspector = new Inspector();
foreach (var kvp in targetPtlineOfSightResultsMapping)
{
var targetPointOID = kvp.Key;
var lineOfSighResults = kvp.Value;
var targetPointVisibility = lineOfSighResults.IsTargetVisibleFromObserverPoint ? 1 : 0;
modifyTargetPtsLyrInspector.Load(targetPointLayer, targetPointOID);//base attributes on an existing feature
modifyTargetPtsLyrInspector["TargetVisibleFromObserver"] = targetPointVisibility;
editOpTargetPointVisibility.Modify(modifyTargetPtsLyrInspector);
}
#endregion
});
#region Setup the Edit Operation to create the Line of Sight results and Obstruction Points
bool obstructionPointsExist = false;
var editOp = new EditOperation();
editOp.Name = "Line Of Sight results";
editOp.SelectNewFeatures = false;

var editOpObsPts = new EditOperation();
editOpObsPts.Name = "Obstruction Points";
editOpObsPts.SelectNewFeatures = false;

await QueuedTask.Run( () =>targetPointLayer.SetLabelVisibility(true)); //label target points
#endregion

//Analyze the "get Line of Sight" results and create the visible and invisible line features
foreach (var kvp in targetPtlineOfSightResultsMapping)
{
var lineOfSightResult = kvp.Value;
Polyline visibleLine = lineOfSightResult.VisibleLine;
Polyline invisibleLine = lineOfSightResult.InvisibleLine;
bool isTargetVisibleFromObserverPoint = lineOfSightResult.IsTargetVisibleFromObserverPoint;
if (!isTargetVisibleFromObserverPoint)
{
MapPoint obstructionPoint = lineOfSightResult.ObstructionPoint;
}
#region Create the visible, invisible lines and the obstruction points to visualize on the map.
var targetPointVisibility = isTargetVisibleFromObserverPoint ? 1 : 0;
//Is there a Visible line?
if (visibleLine != null)
{
//Define the attribute values for the visible line segment of the Line of Sight result
Dictionary<string, object> attrVisibleLineOfSight = new Dictionary<string, object>();
attrVisibleLineOfSight["SHAPE"] = lineOfSightResult.VisibleLine;//Geometry
attrVisibleLineOfSight["VIS_CODE"] = string.Format("1");
attrVisibleLineOfSight["TargetVisibleFromObserver"] = string.Format($"{targetPointVisibility}");
editOp.Create(lineOfSightLayer, attrVisibleLineOfSight);
}
//Is there an Invisible line?
if (invisibleLine != null)
{
//Define the attribute values for the invisible line segment of the Line of Sight result
Dictionary<string, object> attrInVisibleLineOfSight = new Dictionary<string, object>();
attrInVisibleLineOfSight["SHAPE"] = lineOfSightResult.InvisibleLine;//Geometry
attrInVisibleLineOfSight["VIS_CODE"] = string.Format("2");
attrInVisibleLineOfSight["TargetVisibleFromObserver"] = string.Format($"{targetPointVisibility}");
editOp.Create(lineOfSightLayer, attrInVisibleLineOfSight);
//obstruction point
if (lineOfSightResult.ObstructionPoint != null)
{
obstructionPointsExist = true;
editOpObsPts.Create(obstructionPtsLayer, lineOfSightResult.ObstructionPoint);
}
}
#endregion
}
#region Execute the edit operations
// Execute the operation
await editOp.ExecuteAsync();

if (obstructionPointsExist)
await editOpObsPts.ExecuteAsync();

if (!editOpTargetPointVisibility.IsEmpty)
await editOpTargetPointVisibility.ExecuteAsync();

await Project.Current.SaveEditsAsync();


#endregion
}
}
}
Loading

0 comments on commit 4f3f355

Please sign in to comment.