diff --git a/source/addins/ArcMapAddinVisibility/ArcMapAddinVisibility.csproj b/source/addins/ArcMapAddinVisibility/ArcMapAddinVisibility.csproj
index 571029a..ab997c4 100644
--- a/source/addins/ArcMapAddinVisibility/ArcMapAddinVisibility.csproj
+++ b/source/addins/ArcMapAddinVisibility/ArcMapAddinVisibility.csproj
@@ -146,6 +146,9 @@
Config.esriaddinx
+
+ Code
+
diff --git a/source/addins/ArcMapAddinVisibility/Models/AddInPointObject.cs b/source/addins/ArcMapAddinVisibility/Models/AddInPointObject.cs
new file mode 100644
index 0000000..4b05ee4
--- /dev/null
+++ b/source/addins/ArcMapAddinVisibility/Models/AddInPointObject.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ArcMapAddinVisibility.Models
+{
+ public class AddInPointObject
+ {
+ private int _id;
+
+ public int ID
+ {
+ get { return _id; }
+ set { _id = value; }
+ }
+ private AddInPoint _addInPoint;
+
+ public AddInPoint AddInPoint
+ {
+ get { return _addInPoint; }
+ set { _addInPoint = value; }
+ }
+
+ }
+}
diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs
index ceb57e5..24456ce 100644
--- a/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs
+++ b/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs
@@ -36,17 +36,29 @@ public class LLOSViewModel : LOSBaseViewModel
{
public LLOSViewModel()
{
- TargetAddInPoints = new ObservableCollection();
-
+ DisplayProgressBarLLOS = Visibility.Hidden;
// commands
SubmitCommand = new RelayCommand(OnSubmitCommand);
ClearGraphicsVisible = true;
+
}
#region Properties
- public ObservableCollection TargetAddInPoints { get; set; }
+ private Visibility _displayProgressBarLLOS;
+ public Visibility DisplayProgressBarLLOS
+ {
+ get
+ {
+ return _displayProgressBarLLOS;
+ }
+ set
+ {
+ _displayProgressBarLLOS = value;
+ RaisePropertyChanged(() => DisplayProgressBarLLOS);
+ }
+ }
#endregion
@@ -97,7 +109,11 @@ private void DeleteTargetPoints(List targets)
foreach (var obj in targets)
{
TargetAddInPoints.Remove(obj);
+ TargetInExtentPoints.Remove(obj);
+ TargetOutExtentPoints.Remove(obj);
}
+
+ ValidateLLOS_LayerSelection();
}
internal override void OnDeleteAllPointsCommand(object obj)
@@ -111,6 +127,8 @@ internal override void OnDeleteAllPointsCommand(object obj)
base.OnDeleteAllPointsCommand(obj);
else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget)
DeleteTargetPoints(TargetAddInPoints.ToList());
+
+ ValidateLLOS_LayerSelection();
}
#endregion
@@ -124,16 +142,36 @@ internal override void OnNewMapPointEvent(object obj)
var point = obj as IPoint;
- if (point == null || !IsValidPoint(point))
- return;
- if (ToolMode == MapPointToolMode.Target)
+ if (point != null && ToolMode == MapPointToolMode.Target)
{
+ if (IsMapClick)
+ {
+ if (!(IsValidPoint(point, true)))
+ {
+ IsMapClick = false;
+ return;
+ }
+ }
+
var color = new RgbColorClass() { Red = 255 } as IColor;
var guid = AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSSquare);
var addInPoint = new AddInPoint() { Point = point, GUID = guid };
+ bool isValid = IsValidPoint(point, false);
+ if (!isValid)
+ {
+ TargetOutExtentPoints.Insert(0, addInPoint);
+ }
+ else
+ {
+ TargetInExtentPoints.Insert(0, addInPoint);
+ }
+
TargetAddInPoints.Insert(0, addInPoint);
+ IsMapClick = false;
}
+
+ ValidateLLOS_LayerSelection();
}
internal override void Reset(bool toolReset)
@@ -145,15 +183,17 @@ internal override void Reset(bool toolReset)
// reset target points
TargetAddInPoints.Clear();
+ TargetInExtentPoints.Clear();
+ TargetOutExtentPoints.Clear();
}
public override bool CanCreateElement
{
get
{
- return (!string.IsNullOrWhiteSpace(SelectedSurfaceName)
- && ObserverAddInPoints.Any()
- && TargetAddInPoints.Any()
+ return (!string.IsNullOrWhiteSpace(SelectedSurfaceName)
+ && (ObserverAddInPoints.Any() || LLOS_ObserversInExtent.Any() || LLOS_ObserversOutOfExtent.Any())
+ && (TargetAddInPoints.Any() || LLOS_TargetsInExtent.Any() || LLOS_TargetsOutOfExtent.Any())
&& TargetOffset.HasValue);
}
}
@@ -173,160 +213,195 @@ internal override void CreateMapElement()
IsRunning = true;
IPolyline longestLine = new PolylineClass();
+ ReadSelectedLayerPoints();
if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
return;
- // take your observer and target points and get lines of sight
- var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ if ((LLOS_ObserversInExtent.Any() || ObserverAddInPoints.Any())
+ && LLOS_TargetsInExtent.Any() || TargetAddInPoints.Any())
+ {
+ // take your observer and target points and get lines of sight
+ var observerPoints = new ObservableCollection(LLOS_ObserversInExtent.Select(x => x.AddInPoint).Union(ObserverInExtentPoints));
+ var targetPoints = new ObservableCollection(LLOS_TargetsInExtent.Select(x => x.AddInPoint).Union(TargetInExtentPoints));
+ var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
- if (surface == null)
- return;
+ if (surface == null)
+ return;
- ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
- // Issue warning if layer is ImageServerLayer
- if (surfaceLayer is IImageServerLayer)
- {
- MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
- VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);
+ // Issue warning if layer is ImageServerLayer
+ if (surfaceLayer is IImageServerLayer)
+ {
+ MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
+ VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);
- if (mbr == MessageBoxResult.No)
+ if (mbr == MessageBoxResult.No)
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ return;
+ }
+ }
+
+ // Determine if selected surface is projected or geographic
+ var geoDataset = surfaceLayer as IGeoDataset;
+ if (geoDataset == null)
{
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}
- }
-
- // Determine if selected surface is projected or geographic
- var geoDataset = surfaceLayer as IGeoDataset;
- if (geoDataset == null)
- {
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
- return;
- }
-
- SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
-
- if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
- {
- MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
- return;
- }
- if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
- {
- MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
- return;
- }
+ SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
- SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
+ if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
+ {
+ MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
+ return;
+ }
- var geoBridge = (IGeoDatabaseBridge2)new GeoDatabaseHelperClass();
+ if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
+ {
+ MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
+ return;
+ }
- IPoint pointObstruction = null;
- IPolyline polyVisible = null;
- IPolyline polyInvisible = null;
- bool targetIsVisible = false;
+ SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
- double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
- double finalTargetOffset = GetOffsetInZUnits(TargetOffset.Value, surface.ZFactor, OffsetUnitType);
+ var geoBridge = (IGeoDatabaseBridge2)new GeoDatabaseHelperClass();
- var DictionaryTargetObserverCount = new Dictionary();
+ IPoint pointObstruction = null;
+ IPolyline polyVisible = null;
+ IPolyline polyInvisible = null;
+ bool targetIsVisible = false;
- foreach (var observerPoint in ObserverAddInPoints)
- {
- // keep track of visible targets for this observer
- var CanSeeAtLeastOneTarget = false;
+ double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
+ double finalTargetOffset = GetOffsetInZUnits(TargetOffset.Value, surface.ZFactor, OffsetUnitType);
- var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;
+ var DictionaryTargetObserverCount = new Dictionary();
- if (double.IsNaN(z1))
+ foreach (var observerPoint in observerPoints)
{
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
- return;
- }
-
- foreach (var targetPoint in TargetAddInPoints)
- {
- var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;
+ // keep track of visible targets for this observer
+ var CanSeeAtLeastOneTarget = false;
+
+ var z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;
- if (double.IsNaN(z2))
+ if (double.IsNaN(z1))
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
return;
}
- var fromPoint = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true } as IPoint;
- var toPoint = new PointClass() { Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true } as IPoint;
+ foreach (var targetPoint in targetPoints)
+ {
+ var z2 = surface.GetElevation(targetPoint.Point) + finalTargetOffset;
- geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
- out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);
+ if (double.IsNaN(z2))
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ return;
+ }
- var pcol = new PolylineClass() as IPointCollection;
- pcol.AddPoint(fromPoint);
- pcol.AddPoint(toPoint);
- IPolyline pcolPolyline = pcol as IPolyline;
+ var fromPoint = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true } as IPoint;
+ var toPoint = new PointClass() { Z = z2, X = targetPoint.Point.X, Y = targetPoint.Point.Y, ZAware = true } as IPoint;
- longestLine = (longestLine != null && longestLine.Length < pcolPolyline.Length) ? pcolPolyline : longestLine;
+ geoBridge.GetLineOfSight(surface, fromPoint, toPoint,
+ out pointObstruction, out polyVisible, out polyInvisible, out targetIsVisible, false, false);
- // set the flag if we can see at least one target
- if (targetIsVisible)
- {
- CanSeeAtLeastOneTarget = true;
+ var pcol = new PolylineClass() as IPointCollection;
+ pcol.AddPoint(fromPoint);
+ pcol.AddPoint(toPoint);
+ IPolyline pcolPolyline = pcol as IPolyline;
- // update target observer count
- UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
- }
+ longestLine = (longestLine != null && longestLine.Length < pcolPolyline.Length) ? pcolPolyline : longestLine;
- // First Add "SightLine" so it appears behind others
- // Black = Not visible -or- White = Visible
- if (targetIsVisible)
- AddGraphicToMap(pcolPolyline, new RgbColorClass() { RGB = 0xFFFFFF }, false,
- size: 6); // white line
- else
- AddGraphicToMap(pcolPolyline, new RgbColorClass() { RGB = 0x000000 }, false,
- size: 6); // black line
+ // set the flag if we can see at least one target
+ if (targetIsVisible)
+ {
+ CanSeeAtLeastOneTarget = true;
- if (polyVisible != null)
- {
- AddGraphicToMap(polyVisible, new RgbColorClass() { Green = 255 }, size: 5);
+ // update target observer count
+ UpdateTargetObserverCount(DictionaryTargetObserverCount, targetPoint.Point);
+ }
+
+ // First Add "SightLine" so it appears behind others
+ // Black = Not visible -or- White = Visible
+ if (targetIsVisible)
+ AddGraphicToMap(pcolPolyline, new RgbColorClass() { RGB = 0xFFFFFF }, false,
+ size: 6); // white line
+ else
+ AddGraphicToMap(pcolPolyline, new RgbColorClass() { RGB = 0x000000 }, false,
+ size: 6); // black line
+
+ if (polyVisible != null)
+ {
+ AddGraphicToMap(polyVisible, new RgbColorClass() { Green = 255 }, size: 5);
+ }
+
+ if (polyInvisible != null)
+ {
+ AddGraphicToMap(polyInvisible, new RgbColorClass() { Red = 255 }, size: 3);
+ }
+
+ if (polyVisible == null && polyInvisible == null)
+ {
+ if (targetIsVisible)
+ AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Green = 255 }, size: 3);
+ else
+ AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Red = 255 }, size: 3);
+ }
}
- if (polyInvisible != null)
+ // visualize observer
+
+ // add blue dot
+ AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Blue = 255 }, size: 10);
+
+ if (CanSeeAtLeastOneTarget)
{
- AddGraphicToMap(polyInvisible, new RgbColorClass() { Red = 255 }, size: 3);
+ // add green dot
+ AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Green = 255 });
}
-
- if (polyVisible == null && polyInvisible == null)
- {
- if (targetIsVisible)
- AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Green = 255 }, size: 3);
- else
- AddGraphicToMap(pcol as IPolyline, new RgbColorClass() { Red = 255 }, size: 3);
+ else
+ {
+ // add red dot
+ AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Red = 255 });
}
}
- // visualize observer
+ VisualizeTargets(DictionaryTargetObserverCount, targetPoints);
+
+ if ((ObserverInExtentPoints.Any() || LLOS_ObserversInExtent.Any())
+ && (TargetInExtentPoints.Any() || LLOS_TargetsInExtent.Any()))
+ {
+ ZoomToExtent(longestLine);
+ }
- // add blue dot
- AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Blue = 255 }, size: 10);
+ DisplayOutOfExtentMsg();
- if (CanSeeAtLeastOneTarget)
+ //display points present out of extent
+ var colorObserver = new RgbColorClass() { Blue = 255 };
+ var colorTarget = new RgbColorClass() { Red = 255 };
+ var colorObserverBorder = new RgbColorClass() { Red = 255, Blue = 255, Green = 255 };
+ var colorTargetBorder = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };
+ var observerOutOfExtent = new ObservableCollection(LLOS_ObserversOutOfExtent.Select(x => x.AddInPoint).Union(ObserverOutExtentPoints));
+ foreach (var point in observerOutOfExtent)
{
- // add green dot
- AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Green = 255 });
+ AddGraphicToMap(point.Point, colorObserver, markerStyle: esriSimpleMarkerStyle.esriSMSX, size: 10, borderColor: colorObserverBorder);
}
- else
+ var targetOutOfExtent = new ObservableCollection(LLOS_TargetsOutOfExtent.Select(x => x.AddInPoint).Union(TargetOutExtentPoints));
+ foreach (var point in targetOutOfExtent)
{
- // add red dot
- AddGraphicToMap(observerPoint.Point, new RgbColorClass() { Red = 255 });
+ AddGraphicToMap(point.Point, colorTarget, markerStyle: esriSimpleMarkerStyle.esriSMSX, size: 10, borderColor: colorTargetBorder);
}
- }
- VisualizeTargets(DictionaryTargetObserverCount);
- ZoomToExtent(longestLine);
+ }
+ else
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.OutOfExtentMsg, VisibilityLibrary.Properties.Resources.OutOfExtentHeader);
+ }
}
- catch(Exception ex)
+ catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.ExceptionSomethingWentWrong,
@@ -335,13 +410,62 @@ internal override void CreateMapElement()
finally
{
IsRunning = false;
+ ClearLLOSCollections();
+ ValidateLLOS_LayerSelection();
+ }
+ }
+
+ private void DisplayOutOfExtentMsg()
+ {
+ var observerIDCollection = LLOS_ObserversOutOfExtent.Select(x => x.ID).ToList();
+ var targetIDCollection = LLOS_TargetsOutOfExtent.Select(x => x.ID).ToList();
+ var observerString = string.Empty;
+ var targetString = string.Empty;
+ foreach (var item in observerIDCollection)
+ {
+ if (observerString == "")
+ observerString = item.ToString();
+ else
+ observerString = observerString + "," + item.ToString();
+ }
+ foreach (var item in targetIDCollection)
+ {
+ if (targetString == "")
+ targetString = item.ToString();
+ else
+ targetString = targetString + "," + item.ToString();
+ }
+ if (observerIDCollection.Any() || targetIDCollection.Any())
+ {
+ if ((observerIDCollection.Count + targetIDCollection.Count) <= 10)
+ {
+ var msgString = string.Empty;
+ if (observerIDCollection.Any())
+ {
+ msgString = "Observers lying outside the extent of elevation surface are: " + observerString;
+ }
+ if (targetIDCollection.Any())
+ {
+ if (msgString != "")
+ msgString = msgString + "\n";
+ msgString = msgString + "Targets lying outside the extent of elevation surface are: " + targetString;
+ }
+ System.Windows.MessageBox.Show(msgString,
+ "Unable To Process For Few Locations");
+ }
+ else
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent,
+ VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ }
+
}
}
- private void VisualizeTargets(Dictionary dict)
+ private void VisualizeTargets(Dictionary dict, ObservableCollection targetPoints)
{
// visualize targets
- foreach (var targetPoint in TargetAddInPoints)
+ foreach (var targetPoint in targetPoints)
{
if (dict.ContainsKey(targetPoint.Point))
{
@@ -373,12 +497,38 @@ private void UpdateTargetObserverCount(Dictionary dict, IPoint targ
internal override void OnDisplayCoordinateTypeChanged(object obj)
{
var list = TargetAddInPoints.ToList();
+ var inExtentList = TargetInExtentPoints.ToList();
+ var outExtentList = TargetOutExtentPoints.ToList();
+
TargetAddInPoints.Clear();
+ TargetInExtentPoints.Clear();
+ TargetOutExtentPoints.Clear();
+
foreach (var item in list)
TargetAddInPoints.Add(item);
+ foreach (var item in inExtentList)
+ TargetInExtentPoints.Add(item);
+
+ foreach (var item in outExtentList)
+ TargetOutExtentPoints.Add(item);
+
// and update observers
base.OnDisplayCoordinateTypeChanged(obj);
}
+
+ private void ReadSelectedLayerPoints()
+ {
+ LLOS_ObserversInExtent.Clear();
+ LLOS_ObserversOutOfExtent.Clear();
+ LLOS_TargetsInExtent.Clear();
+ LLOS_TargetsOutOfExtent.Clear();
+
+ var observerColor = new RgbColor() { Blue = 255 } as IColor;
+ ReadSelectedLyrPoints(LLOS_ObserversInExtent, LLOS_ObserversOutOfExtent, SelectedLLOS_ObserverLyrName, observerColor);
+
+ var targetColor = new RgbColor() { Red = 255 } as IColor;
+ ReadSelectedLyrPoints(LLOS_TargetsInExtent, LLOS_TargetsOutOfExtent, SelectedLLOS_TargetLyrName, observerColor);
+ }
}
}
diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs
index bd9ab39..9656ed6 100644
--- a/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs
+++ b/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs
@@ -1,4 +1,4 @@
-// Copyright 2016 Esri
+// Copyright 2016 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -12,21 +12,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Collections.ObjectModel;
-using System.Collections;
+using ArcMapAddinVisibility.Models;
+using CoordinateConversionLibrary.Models;
+using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Carto;
+using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
-using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Geometry;
-using ESRI.ArcGIS.Display;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows;
+using System.Windows.Threading;
using VisibilityLibrary;
using VisibilityLibrary.Helpers;
-using VisibilityLibrary.Views;
using VisibilityLibrary.ViewModels;
-using ArcMapAddinVisibility.Models;
+using VisibilityLibrary.Views;
namespace ArcMapAddinVisibility.ViewModels
{
@@ -37,19 +43,40 @@ public LOSBaseViewModel()
ObserverOffset = 2.0;
TargetOffset = 0.0;
OffsetUnitType = DistanceTypes.Meters;
+ DistanceUnitType = DistanceTypes.Meters;
AngularUnitType = AngularTypes.DEGREES;
ObserverAddInPoints = new ObservableCollection();
+ ObserverInExtentPoints = new ObservableCollection();
+ ObserverOutExtentPoints = new ObservableCollection();
+ TargetAddInPoints = new ObservableCollection();
+ TargetInExtentPoints = new ObservableCollection();
+ TargetOutExtentPoints = new ObservableCollection();
+ LLOS_ObserversInExtent = new ObservableCollection();
+ LLOS_ObserversOutOfExtent = new ObservableCollection();
+ LLOS_TargetsInExtent = new ObservableCollection();
+ LLOS_TargetsOutOfExtent = new ObservableCollection();
+ RLOS_ObserversInExtent = new ObservableCollection();
+ RLOS_ObserversOutOfExtent = new ObservableCollection();
+ EnterManullyOption = VisibilityLibrary.Properties.Resources.EnterManuallyOption;
toolMode = MapPointToolMode.Unknown;
SurfaceLayerNames = new ObservableCollection();
+ LLOS_ObserverLyrNames = new ObservableCollection();
+ LLOS_TargetLyrNames = new ObservableCollection();
+ RLOS_ObserverLyrNames = new ObservableCollection();
SelectedSurfaceName = string.Empty;
+ SelectedLLOS_ObserverLyrName = string.Empty;
+ SelectedLLOS_TargetLyrName = string.Empty;
+ SelectedRLOS_ObserverLyrName = string.Empty;
Mediator.Register(Constants.MAP_TOC_UPDATED, OnMapTocUpdated);
Mediator.Register(Constants.DISPLAY_COORDINATE_TYPE_CHANGED, OnDisplayCoordinateTypeChanged);
DeletePointCommand = new RelayCommand(OnDeletePointCommand);
DeleteAllPointsCommand = new RelayCommand(OnDeleteAllPointsCommand);
+ PasteCoordinatesCommand = new RelayCommand(OnPasteCommand);
+ ImportCSVFileCommand = new RelayCommand(OnImportCSVFileCommand);
EditPropertiesDialogCommand = new RelayCommand(OnEditPropertiesDialogCommand);
}
@@ -101,6 +128,7 @@ public double? ObserverOffset
throw new ArgumentException(VisibilityLibrary.Properties.Resources.AEInvalidInput);
}
}
+
private double? targetOffset;
public double? TargetOffset
{
@@ -142,12 +170,103 @@ public MapPointToolMode ToolMode
}
}
+ private string _selectedLLOS_TargetLyrName;
+ public string SelectedLLOS_TargetLyrName
+ {
+ get
+ {
+ return _selectedLLOS_TargetLyrName;
+ }
+ set
+ {
+ _selectedLLOS_TargetLyrName = value;
+ ValidateLLOS_LayerSelection();
+ RaisePropertyChanged(() => SelectedLLOS_TargetLyrName);
+ }
+ }
+
+ private string _selectedLLOS_ObserverLyrName;
+ public string SelectedLLOS_ObserverLyrName
+ {
+ get
+ {
+ return _selectedLLOS_ObserverLyrName;
+ }
+ set
+ {
+ _selectedLLOS_ObserverLyrName = value;
+ ValidateLLOS_LayerSelection();
+ RaisePropertyChanged(() => SelectedLLOS_ObserverLyrName);
+ }
+ }
+
+ private string _selectedRLOS_ObserverLyrName;
+ public string SelectedRLOS_ObserverLyrName
+ {
+ get
+ {
+ return _selectedRLOS_ObserverLyrName;
+ }
+ set
+ {
+ _selectedRLOS_ObserverLyrName = value;
+ ValidateRLOS_LayerSelection();
+ RaisePropertyChanged(() => SelectedRLOS_ObserverLyrName);
+ }
+ }
+
+ public ObservableCollection LLOS_ObserverLyrNames { get; set; }
+ public ObservableCollection LLOS_TargetLyrNames { get; set; }
+ public ObservableCollection RLOS_ObserverLyrNames { get; set; }
+
+ private bool _isLLOSValidSelection { get; set; }
+ public bool IsLLOSValidSelection
+ {
+ get
+ {
+ return _isLLOSValidSelection;
+ }
+ set
+ {
+ _isLLOSValidSelection = value;
+ RaisePropertyChanged(() => IsLLOSValidSelection);
+ }
+ }
+
+ private bool _isRLOSValidSelection { get; set; }
+ public bool IsRLOSValidSelection
+ {
+ get
+ {
+ return _isRLOSValidSelection;
+ }
+ set
+ {
+ _isRLOSValidSelection = value;
+ RaisePropertyChanged(() => IsRLOSValidSelection);
+ }
+ }
+
+ public string EnterManullyOption { get; set; }
+ public ObservableCollection LLOS_ObserversInExtent { get; set; }
+ public ObservableCollection LLOS_ObserversOutOfExtent { get; set; }
+ public ObservableCollection LLOS_TargetsInExtent { get; set; }
+ public ObservableCollection LLOS_TargetsOutOfExtent { get; set; }
+ public ObservableCollection RLOS_ObserversInExtent { get; set; }
+ public ObservableCollection RLOS_ObserversOutOfExtent { get; set; }
+
public ObservableCollection ObserverAddInPoints { get; set; }
+ public ObservableCollection ObserverInExtentPoints { get; set; }
+ public ObservableCollection ObserverOutExtentPoints { get; set; }
+ public ObservableCollection TargetAddInPoints { get; set; }
+ public ObservableCollection TargetInExtentPoints { get; set; }
+ public ObservableCollection TargetOutExtentPoints { get; set; }
public ObservableCollection SurfaceLayerNames { get; set; }
public string SelectedSurfaceName { get; set; }
public DistanceTypes OffsetUnitType { get; set; }
+ public DistanceTypes DistanceUnitType { get; set; }
public AngularTypes AngularUnitType { get; set; }
-
+
#endregion
#region Commands
@@ -155,6 +274,8 @@ public MapPointToolMode ToolMode
public RelayCommand DeletePointCommand { get; set; }
public RelayCommand DeleteAllPointsCommand { get; set; }
public RelayCommand EditPropertiesDialogCommand { get; set; }
+ public RelayCommand PasteCoordinatesCommand { get; set; }
+ public RelayCommand ImportCSVFileCommand { get; set; }
///
/// Command method to delete points
@@ -189,6 +310,7 @@ private void OnEditPropertiesDialogCommand(object obj)
dlg.ShowDialog();
}
+
private void DeletePoints(List observers)
{
if (observers == null || !observers.Any())
@@ -201,6 +323,148 @@ private void DeletePoints(List observers)
foreach (var point in observers)
{
ObserverAddInPoints.Remove(point);
+ ObserverInExtentPoints.Remove(point);
+ ObserverOutExtentPoints.Remove(point);
+ }
+ }
+
+ ///
+ /// Command method to import points from csv file.
+ ///
+ ///
+ public virtual void OnImportCSVFileCommand(object obj)
+ {
+ var mode = obj.ToString();
+ CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false;
+
+ var fileDialog = new Microsoft.Win32.OpenFileDialog();
+ fileDialog.CheckFileExists = true;
+ fileDialog.CheckPathExists = true;
+ fileDialog.Filter = "csv files|*.csv";
+
+ // attemp to import
+ var fieldVM = new CoordinateConversionLibrary.ViewModels.SelectCoordinateFieldsViewModel();
+ var result = fileDialog.ShowDialog();
+ if (result.HasValue && result.Value == true)
+ {
+ var dlg = new CoordinateConversionLibrary.Views.SelectCoordinateFieldsView();
+ using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ {
+ var headers = CoordinateConversionLibrary.Helpers.ImportCSV.GetHeaders(s);
+ if (headers != null)
+ {
+ foreach (var header in headers)
+ {
+ fieldVM.AvailableFields.Add(header);
+ System.Diagnostics.Debug.WriteLine("header : {0}", header);
+ }
+ dlg.DataContext = fieldVM;
+ }
+ else
+ {
+ System.Windows.Forms.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgNoDataFound);
+ return;
+ }
+ }
+ if (dlg.ShowDialog() == true)
+ {
+ using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
+ {
+ var lists = CoordinateConversionLibrary.Helpers.ImportCSV.Import(s, fieldVM.SelectedFields.ToArray());
+
+ foreach (var item in lists)
+ {
+ string outFormattedString = string.Empty;
+ var sb = new StringBuilder();
+ sb.Append(item.lat.Trim());
+ if (fieldVM.UseTwoFields)
+ sb.Append(string.Format(" {0}", item.lon.Trim()));
+
+ string coordinate = sb.ToString();
+ CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString);
+ if (ccType == CoordinateConversionLibrary.Models.CoordinateType.Unknown)
+ {
+ Regex regexMercator = new Regex(@"^(?\-?\d+\.?\d*)[+,;:\s]*(?\-?\d+\.?\d*)");
+ var matchMercator = regexMercator.Match(coordinate);
+ if (matchMercator.Success && matchMercator.Length == coordinate.Length)
+ {
+ ccType = CoordinateType.DD;
+ }
+ }
+ IPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetPointFromString(outFormattedString) : null;
+ if (point != null)
+ {
+ if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver)
+ {
+ ToolMode = MapPointToolMode.Observer;
+ Point1 = point;
+ if ((ArcMap.Document != null) && (ArcMap.Document.FocusMap != null))
+ point.Project(ArcMap.Document.FocusMap.SpatialReference);
+ OnNewMapPointEvent(Point1);
+ }
+ else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget)
+ {
+ ToolMode = MapPointToolMode.Target;
+ Point2 = point;
+ if ((ArcMap.Document != null) && (ArcMap.Document.FocusMap != null))
+ point.Project(ArcMap.Document.FocusMap.SpatialReference);
+ OnNewMapPointEvent(Point2);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ///
+ /// Command method to paste points from clipboard.
+ ///
+ ///
+ internal virtual void OnPasteCommand(object obj)
+ {
+ var mode = obj.ToString();
+
+ if (string.IsNullOrWhiteSpace(mode))
+ return;
+
+ var input = Clipboard.GetText().Trim();
+ string[] lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
+ var coordinates = new List();
+ foreach (var item in lines)
+ {
+ string outFormattedString = string.Empty;
+ string coordinate = item.Trim().ToString();
+ CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString);
+ if (ccType == CoordinateConversionLibrary.Models.CoordinateType.Unknown)
+ {
+ Regex regexMercator = new Regex(@"^(?\-?\d+\.?\d*)[+,;:\s]*(?\-?\d+\.?\d*)");
+ var matchMercator = regexMercator.Match(coordinate);
+ if (matchMercator.Success && matchMercator.Length == coordinate.Length)
+ {
+ ccType = CoordinateType.DD;
+ }
+ }
+ IPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetPointFromString(outFormattedString) : null;
+ if (point != null)
+ {
+ if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver)
+ {
+ ToolMode = MapPointToolMode.Observer;
+ Point1 = point;
+ if ((ArcMap.Document != null) && (ArcMap.Document.FocusMap != null))
+ point.Project(ArcMap.Document.FocusMap.SpatialReference);
+ OnNewMapPointEvent(Point1);
+ }
+ else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget)
+ {
+ ToolMode = MapPointToolMode.Target;
+ Point2 = point;
+ if ((ArcMap.Document != null) && (ArcMap.Document.FocusMap != null))
+ point.Project(ArcMap.Document.FocusMap.SpatialReference);
+ OnNewMapPointEvent(Point2);
+ }
+ }
}
}
@@ -267,23 +531,41 @@ internal override void OnNewMapPointEvent(object obj)
if (!IsActiveTab)
return;
- var point = obj as IPoint;
-
- if (point == null || !IsValidPoint(point, true))
- return;
+ var point = obj as IPoint;
// ok, we have a point
if (ToolMode == MapPointToolMode.Observer)
{
+ if (IsMapClick)
+ {
+ if (!(IsValidPoint(point, true)))
+ {
+ IsMapClick = false;
+ return;
+ }
+ }
// in tool mode "Observer" we add observer points
// otherwise ignore
-
+
var color = new RgbColorClass() { Blue = 255 } as IColor;
var guid = AddGraphicToMap(point, color, true);
var addInPoint = new AddInPoint() { Point = point, GUID = guid };
+ bool isValid = IsValidPoint(point, false);
+ if (!isValid)
+ {
+
+ ObserverOutExtentPoints.Insert(0, addInPoint);
+ }
+ else
+ {
+ ObserverInExtentPoints.Insert(0, addInPoint);
+ }
+
ObserverAddInPoints.Insert(0, addInPoint);
+ IsMapClick = false;
}
}
+
internal override void OnMouseMoveEvent(object obj)
{
if (!IsActiveTab)
@@ -294,17 +576,18 @@ internal override void OnMouseMoveEvent(object obj)
if (point == null)
return;
- if(ToolMode == MapPointToolMode.Observer)
+ if (ToolMode == MapPointToolMode.Observer)
{
Point1Formatted = string.Empty;
Point1 = point;
}
- else if(ToolMode == MapPointToolMode.Target)
+ else if (ToolMode == MapPointToolMode.Target)
{
Point2Formatted = string.Empty;
Point2 = point;
}
}
+
///
/// Handler for "Enter" key press
/// If pressed when input textbox for observer or target is focused
@@ -316,13 +599,19 @@ internal override void OnEnterKeyCommand(object obj)
{
var keyCommandMode = obj as string;
- if(keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver)
+ if (keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver)
{
+ if (!IsValidPoint(Point1, true))
+ return;
+
ToolMode = MapPointToolMode.Observer;
OnNewMapPointEvent(Point1);
}
else if (keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeTarget)
{
+ if (!IsValidPoint(Point2, true))
+ return;
+
ToolMode = MapPointToolMode.Target;
OnNewMapPointEvent(Point2);
}
@@ -332,6 +621,7 @@ internal override void OnEnterKeyCommand(object obj)
base.OnEnterKeyCommand(obj);
}
}
+
///
/// Method to check to see point is withing the currently selected surface
/// returns true if there is no surface selected or point is contained by layer AOI
@@ -452,7 +742,7 @@ public ISurface GetSurfaceFromMapByName(IMap map, string name)
var mosaicLayer = layer as IMosaicLayer;
var rasterLayer = layer as IRasterLayer;
- if ((mosaicLayer != null) && (mosaicLayer.PreviewLayer != null) &&
+ if ((mosaicLayer != null) && (mosaicLayer.PreviewLayer != null) &&
(mosaicLayer.PreviewLayer.Raster != null))
{
rasterSurface.PutRaster(mosaicLayer.PreviewLayer.Raster, 0);
@@ -520,7 +810,7 @@ public List GetSurfaceNamesFromMap(IMap map, bool IncludeTinLayers = fal
var layer = layers.Next();
- while(layer != null)
+ while (layer != null)
{
try
{
@@ -595,12 +885,14 @@ internal override void Reset(bool toolReset)
// reset observer points
ObserverAddInPoints.Clear();
+ ObserverInExtentPoints.Clear();
+ ObserverOutExtentPoints.Clear();
ClearTempGraphics();
}
///
- /// Method used to reset the currently selected surfacename
+ /// Method used to reset the currently selected surfacename
/// Use when toc items or map changes, on tab selection changed, etc
///
/// IMap
@@ -621,9 +913,65 @@ internal void ResetSurfaceNames(IMap map)
else
SelectedSurfaceName = string.Empty;
+ ResetLayerNames(map);
+
RaisePropertyChanged(() => SelectedSurfaceName);
+ RaisePropertyChanged(() => SelectedLLOS_ObserverLyrName);
+ RaisePropertyChanged(() => SelectedLLOS_TargetLyrName);
+ RaisePropertyChanged(() => SelectedRLOS_ObserverLyrName);
+ }
+
+ private void ResetLayerNames(IMap map)
+ {
+ var layerNames = new ObservableCollection();
+ Dispatcher.CurrentDispatcher.Invoke(() =>
+ {
+ layerNames = GetLayerNames(map);
+ });
+
+ var tempSelectedLLOS_Observer = SelectedLLOS_ObserverLyrName;
+ var tempSelectedLLOS_Target = SelectedLLOS_TargetLyrName;
+ var tempSelectedRLOS_Observer = SelectedRLOS_ObserverLyrName;
+
+
+ Dispatcher.CurrentDispatcher.Invoke(() =>
+ {
+ ResetLayerCollectionNames(layerNames);
+ });
+ Dispatcher.CurrentDispatcher.Invoke(() =>
+ {
+ ResetSelectedLyrName(tempSelectedLLOS_Observer, tempSelectedLLOS_Target, tempSelectedRLOS_Observer);
+ });
+
}
+ private void ResetSelectedLyrName(string tempSelectedLLOS_Observer, string tempSelectedLLOS_Target, string tempSelectedRLOS_Observer)
+ {
+ if (SurfaceLayerNames.Contains(tempSelectedLLOS_Observer))
+ SelectedLLOS_ObserverLyrName = tempSelectedLLOS_Observer;
+ else if (SurfaceLayerNames.Any())
+ SelectedLLOS_ObserverLyrName = LLOS_ObserverLyrNames[0];
+ else
+ SelectedLLOS_ObserverLyrName = string.Empty;
+
+
+ if (SurfaceLayerNames.Contains(tempSelectedLLOS_Target))
+ SelectedLLOS_TargetLyrName = tempSelectedLLOS_Target;
+ else if (SurfaceLayerNames.Any())
+ SelectedLLOS_TargetLyrName = LLOS_TargetLyrNames[0];
+ else
+ SelectedLLOS_TargetLyrName = string.Empty;
+
+ if (SurfaceLayerNames.Contains(tempSelectedRLOS_Observer))
+ SelectedRLOS_ObserverLyrName = tempSelectedRLOS_Observer;
+ else if (SurfaceLayerNames.Any())
+ SelectedRLOS_ObserverLyrName = RLOS_ObserverLyrNames[0];
+ else
+ SelectedRLOS_ObserverLyrName = string.Empty;
+ }
+
+
+
///
/// Method to handle the display coordinate type change
/// Need to update the list boxes
@@ -632,10 +980,175 @@ internal void ResetSurfaceNames(IMap map)
internal virtual void OnDisplayCoordinateTypeChanged(object obj)
{
var list = ObserverAddInPoints.ToList();
+ var inExtentList = ObserverInExtentPoints.ToList();
+ var outExtentList = ObserverOutExtentPoints.ToList();
+
ObserverAddInPoints.Clear();
+ ObserverInExtentPoints.Clear();
+ ObserverOutExtentPoints.Clear();
+
foreach (var item in list)
ObserverAddInPoints.Add(item);
+
+ foreach (var item in inExtentList)
+ ObserverInExtentPoints.Add(item);
+
+ foreach (var item in outExtentList)
+ ObserverOutExtentPoints.Add(item);
RaisePropertyChanged(() => HasMapGraphics);
}
+
+ private void ResetLayerCollectionNames(ObservableCollection layerNames)
+ {
+ LLOS_ObserverLyrNames.Clear();
+ LLOS_TargetLyrNames.Clear();
+ RLOS_ObserverLyrNames.Clear();
+
+ if (!LLOS_ObserverLyrNames.Contains(EnterManullyOption))
+ {
+ LLOS_ObserverLyrNames.Add(EnterManullyOption);
+ LLOS_TargetLyrNames.Add(EnterManullyOption);
+ RLOS_ObserverLyrNames.Add(EnterManullyOption);
+ }
+
+ foreach (var layerName in layerNames)
+ {
+ if (!LLOS_ObserverLyrNames.Contains(layerName))
+ {
+ LLOS_ObserverLyrNames.Add(layerName);
+ LLOS_TargetLyrNames.Add(layerName);
+ RLOS_ObserverLyrNames.Add(layerName);
+ }
+ }
+ }
+
+ private ObservableCollection GetLayerNames(IMap map)
+ {
+ var layerNames = new ObservableCollection();
+
+ if (map == null)
+ return layerNames;
+
+ var layers = map.get_Layers();
+
+ if (layers == null)
+ return layerNames;
+ var layer = layers.Next();
+ while (layer != null)
+ {
+ var lyr = layer as FeatureClass;
+ if (lyr != null && lyr.Type == esriDatasetType.esriDTFeatureClass)
+ {
+ IFeatureLayer FLayer = (IFeatureLayer)lyr;
+ var geomertyType = FLayer.FeatureClass.ShapeType;
+ if (geomertyType == esriGeometryType.esriGeometryPoint)
+ layerNames.Add(layer.Name);
+ }
+ layer = layers.Next();
+ }
+ return layerNames;
+ }
+
+ internal void ValidateLLOS_LayerSelection()
+ {
+ if (SelectedLLOS_ObserverLyrName == EnterManullyOption)
+ {
+ LLOS_ObserversInExtent.Clear();
+ LLOS_ObserversOutOfExtent.Clear();
+ }
+ if (SelectedLLOS_TargetLyrName == EnterManullyOption)
+ {
+ LLOS_TargetsInExtent.Clear();
+ LLOS_TargetsOutOfExtent.Clear();
+ }
+
+ IsLLOSValidSelection = (
+ ((SelectedLLOS_ObserverLyrName == EnterManullyOption || string.IsNullOrWhiteSpace(SelectedLLOS_ObserverLyrName))
+ && LLOS_ObserversInExtent.Count == 0 && LLOS_ObserversOutOfExtent.Count == 0 && ObserverAddInPoints.Count == 0)
+ ||
+ ((SelectedLLOS_TargetLyrName == EnterManullyOption || string.IsNullOrWhiteSpace(SelectedLLOS_TargetLyrName))
+ && LLOS_TargetsInExtent.Count == 0 && LLOS_TargetsOutOfExtent.Count == 0 && TargetAddInPoints.Count == 0)
+ ) ? false : true;
+ }
+
+ internal void ValidateRLOS_LayerSelection()
+ {
+ IsRLOSValidSelection =
+ ((SelectedRLOS_ObserverLyrName == EnterManullyOption || string.IsNullOrWhiteSpace(SelectedRLOS_ObserverLyrName))
+ && RLOS_ObserversInExtent.Count == 0 && RLOS_ObserversOutOfExtent.Count == 0) ? false : true;
+ }
+
+ internal void ReadSelectedLyrPoints(ObservableCollection inExtentPoints, ObservableCollection outOfExtentPoints, string selectedLyrName, IColor color)
+ {
+ var map = ArcMap.Document.FocusMap;
+ if (map == null)
+ return;
+ var layers = map.get_Layers();
+ if (layers == null)
+ return;
+ var layer = layers.Next();
+ while (layer != null)
+ {
+ if (layer.Name == selectedLyrName)
+ {
+ IFeature feature = null;
+ IFeatureLayer FLayer = (IFeatureLayer)layer;
+ var cursor = FLayer.FeatureClass.Search(null, false);
+ var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
+ var selectedFeaturesCollections = GetSelectedFeaturesCollections(layer);
+ while ((feature = cursor.NextFeature()) != null)
+ {
+ var value = feature.get_Value(FLayer.FeatureClass.FindField("Shape"));
+ var point = (IPoint)value;
+ var guid = AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSSquare);
+ var objectId = FLayer.FeatureClass.FindField("ObjectId");
+ var FID = FLayer.FeatureClass.FindField("FID");
+ var idIndex = objectId != -1 ? objectId : FID;
+ var id = Convert.ToInt32(feature.get_Value(idIndex));
+ var z1 = surface.GetElevation(point) + finalObserverOffset;
+ var addInPoint = new AddInPoint() { Point = point, GUID = guid };
+ if (selectedFeaturesCollections == null || !selectedFeaturesCollections.Any() ||
+ (selectedFeaturesCollections.Any() && selectedFeaturesCollections.Where(x => x == id).Any()))
+ {
+ if (double.IsNaN(z1))
+ outOfExtentPoints.Add(new AddInPointObject() { AddInPoint = addInPoint, ID = id });
+ else
+ inExtentPoints.Add(new AddInPointObject() { AddInPoint = addInPoint, ID = id });
+ }
+ }
+ }
+ layer = layers.Next();
+ }
+ }
+
+ private static List GetSelectedFeaturesCollections(ILayer layer)
+ {
+ var selectedFeatureCollections = new List();
+ var selectedFeature = ((IFeatureSelection)layer).SelectionSet;
+ var enumFeature = ((IEnumIDs)(((ISelectionSet)(selectedFeature)).IDs));
+ enumFeature.Reset();
+ int selfeature = enumFeature.Next();
+ while (selfeature != -1)
+ {
+ selectedFeatureCollections.Add(selfeature);
+ selfeature = enumFeature.Next();
+ }
+ return selectedFeatureCollections;
+ }
+
+ internal void ClearLLOSCollections()
+ {
+ LLOS_TargetsInExtent.Clear();
+ LLOS_TargetsOutOfExtent.Clear();
+ LLOS_ObserversInExtent.Clear();
+ LLOS_ObserversOutOfExtent.Clear();
+ }
+
+ internal void ClearRLOSCollections()
+ {
+ RLOS_ObserversInExtent.Clear();
+ RLOS_ObserversOutOfExtent.Clear();
+ }
}
-}
+}
\ No newline at end of file
diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs
index d277fa9..35bbe2e 100644
--- a/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs
+++ b/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs
@@ -32,6 +32,8 @@
// Solution
using VisibilityLibrary.Helpers;
using VisibilityLibrary;
+using System.Collections.ObjectModel;
+using ArcMapAddinVisibility.Models;
namespace ArcMapAddinVisibility.ViewModels
{
@@ -215,11 +217,13 @@ public RLOSViewModel()
internal override void OnDeletePointCommand(object obj)
{
base.OnDeletePointCommand(obj);
+ ValidateRLOS_LayerSelection();
}
internal override void OnDeleteAllPointsCommand(object obj)
{
base.OnDeleteAllPointsCommand(obj);
+ ValidateRLOS_LayerSelection();
}
public override bool CanCreateElement
@@ -227,7 +231,7 @@ public override bool CanCreateElement
get
{
return (!string.IsNullOrWhiteSpace(SelectedSurfaceName)
- && ObserverAddInPoints.Any());
+ && (ObserverAddInPoints.Any() || RLOS_ObserversInExtent.Any() || RLOS_ObserversOutOfExtent.Any()));
}
}
@@ -344,252 +348,271 @@ internal override void CreateMapElement()
try
{
IsRunning = true;
-
- if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null
+ var selectedLayer = SelectedRLOS_ObserverLyrName;
+ ReadSelectedLayerPoints();
+ if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null
|| string.IsNullOrWhiteSpace(SelectedSurfaceName))
return;
-
- var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
- if (surface == null)
+ if (RLOS_ObserversInExtent.Any() || ObserverAddInPoints.Any())
{
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
- return;
- }
- bool spatialAnalystAvailable = IsSpatialAnalystAvailable();
- if (!spatialAnalystAvailable)
- {
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
- return;
- }
-
- ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
- // Issue warning if layer is ImageServerLayer
- if (surfaceLayer is IImageServerLayer)
- {
- MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
- VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);
-
- if (mbr == MessageBoxResult.No)
+ var observerPoints = RLOS_ObserversInExtent.Select(x => x.AddInPoint).Union(ObserverInExtentPoints);
+ var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ if (surface == null)
{
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}
- }
-
- // Determine if selected surface is projected or geographic
- var geoDataset = surfaceLayer as IGeoDataset;
- if (geoDataset == null)
- {
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
- return;
- }
- SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
+ bool spatialAnalystAvailable = IsSpatialAnalystAvailable();
+ if (!spatialAnalystAvailable)
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSSpatialAnalystLicenseInvalid, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ return;
+ }
- if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
- {
- MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption);
- return;
- }
+ ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ // Issue warning if layer is ImageServerLayer
+ if (surfaceLayer is IImageServerLayer)
+ {
+ MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
+ VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);
- if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
- {
- MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
- return;
- }
+ if (mbr == MessageBoxResult.No)
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ return;
+ }
+ }
- using (ComReleaser oComReleaser = new ComReleaser())
- {
- // Create feature workspace
- IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace");
- if (workspace == null)
+ // Determine if selected surface is projected or geographic
+ var geoDataset = surfaceLayer as IGeoDataset;
+ if (geoDataset == null)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}
- StartEditOperation((IWorkspace)workspace);
+ SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
- // Create feature class
- IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString());
- if (pointFc == null)
+ if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
{
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
+ MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSUserPrompt, VisibilityLibrary.Properties.Resources.RLOSUserPromptCaption);
return;
}
- double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
- double finalSurfaceOffset = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType);
-
- double conversionFactor = GetConversionFactor(SelectedSurfaceSpatialRef);
- string unitString = GetUnitString(SelectedSurfaceSpatialRef);
- //unit of raster
- DistanceTypes srUnit = GetMTUnitFromEsriUnit(unitString);
- //get distance in map units
- double muMaxDist = GetDistanceFromTo(OffsetUnitType, srUnit, MaxDistance);
- double muMinDist = GetDistanceFromTo(OffsetUnitType, srUnit, MinDistance);
- //Distance in meters
- double convertedMinDistance = MinDistance * conversionFactor;
- double convertedMaxDistance = MaxDistance * conversionFactor;
-
- double finalMinDistance;
- double finalMaxDistance;
- if (srUnit.ToString() != OffsetUnitType.ToString())
+ if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
{
- finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType);
- finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType);
+ MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
+ return;
}
- else
+
+ using (ComReleaser oComReleaser = new ComReleaser())
{
- finalMinDistance = GetDistanceFromTo(DistanceTypes.Meters, srUnit, convertedMinDistance);
- finalMaxDistance = GetDistanceFromTo(DistanceTypes.Meters, srUnit, convertedMaxDistance);
- }
+ // Create feature workspace
+ IFeatureWorkspace workspace = CreateFeatureWorkspace("tempWorkspace");
+ if (workspace == null)
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
+ return;
+ }
- double finalLeftHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType);
- double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType);
- double finalBottomVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType);
- double finalTopVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType);
+ StartEditOperation((IWorkspace)workspace);
- // Output radius geometries
- List maxRangeBufferGeomList = new List();
- List rangeFanGeomList = new List();
+ // Create feature class
+ IFeatureClass pointFc = CreateObserversFeatureClass(workspace, SelectedSurfaceSpatialRef, "Output" + RunCount.ToString());
+ if (pointFc == null)
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
+ return;
+ }
- foreach (var observerPoint in ObserverAddInPoints)
- {
- if ((observerPoint == null) || (observerPoint.Point == null))
- continue;
+ double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
+ double finalSurfaceOffset = GetOffsetInZUnits(SurfaceOffset, surface.ZFactor, OffsetUnitType);
+
+ double conversionFactor = GetConversionFactor(SelectedSurfaceSpatialRef);
+ string unitString = GetUnitString(SelectedSurfaceSpatialRef);
+ //unit of raster
+ DistanceTypes srUnit = GetMTUnitFromEsriUnit(unitString);
+ //get distance in map units
+ double muMaxDist = GetDistanceFromTo(DistanceUnitType, srUnit, MaxDistance);
+ double muMinDist = GetDistanceFromTo(DistanceUnitType, srUnit, MinDistance);
+ //Distance in meters
+ double convertedMinDistance = MinDistance * conversionFactor;
+ double convertedMaxDistance = MaxDistance * conversionFactor;
+
+ double finalMinDistance;
+ double finalMaxDistance;
+ if (srUnit.ToString() != DistanceUnitType.ToString())
+ {
+ finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, DistanceUnitType);
+ finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, DistanceUnitType);
+ }
+ else
+ {
+ finalMinDistance = GetDistanceFromTo(DistanceTypes.Meters, srUnit, convertedMinDistance);
+ finalMaxDistance = GetDistanceFromTo(DistanceTypes.Meters, srUnit, convertedMaxDistance);
+ }
- // Create 2 clipping geometries:
- // 1. maxRangeBufferGeomList - is used to clip the viz GP output because 2. doesn't work directly
- // 2. rangeFanGeomList - this is the range fan input by the user
- ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator;
- if (topologicalOperator == null)
- continue;
+ double finalLeftHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, LeftHorizontalFOV, AngularUnitType);
+ double finalRightHorizontalFOV = GetAngularDistance(ArcMap.Document.FocusMap, RightHorizontalFOV, AngularUnitType);
+ double finalBottomVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, BottomVerticalFOV, AngularUnitType);
+ double finalTopVerticalFOV = GetAngularDistance(ArcMap.Document.FocusMap, TopVerticalFOV, AngularUnitType);
- IGeometry geomBuffer = topologicalOperator.Buffer(muMaxDist);
+ // Output radius geometries
+ List maxRangeBufferGeomList = new List();
+ List rangeFanGeomList = new List();
- maxRangeBufferGeomList.Add(geomBuffer);
+ foreach (var observerPoint in observerPoints)
+ {
+ if ((observerPoint == null) || (observerPoint.Point == null))
+ continue;
- IGeometry geomRangeFan = ConstructRangeFan(observerPoint.Point, muMinDist, muMaxDist,
- finalLeftHorizontalFOV, finalRightHorizontalFOV, SelectedSurfaceSpatialRef);
- if (geomRangeFan != null)
- rangeFanGeomList.Add(geomRangeFan);
+ // Create 2 clipping geometries:
+ // 1. maxRangeBufferGeomList - is used to clip the viz GP output because 2. doesn't work directly
+ // 2. rangeFanGeomList - this is the range fan input by the user
+ ITopologicalOperator topologicalOperator = observerPoint.Point as ITopologicalOperator;
+ if (topologicalOperator == null)
+ continue;
- double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;
+ IGeometry geomBuffer = topologicalOperator.Buffer(muMaxDist);
- //create a new point feature
- IFeature ipFeature = pointFc.CreateFeature();
+ maxRangeBufferGeomList.Add(geomBuffer);
- // Set the field values for the feature
- SetFieldValues(finalObserverOffset, finalSurfaceOffset,muMinDist, muMaxDist, finalLeftHorizontalFOV,
- finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature);
+ IGeometry geomRangeFan = ConstructRangeFan(observerPoint.Point, muMinDist, muMaxDist,
+ finalLeftHorizontalFOV, finalRightHorizontalFOV, SelectedSurfaceSpatialRef);
+ if (geomRangeFan != null)
+ rangeFanGeomList.Add(geomRangeFan);
- if (double.IsNaN(z1))
- {
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
- return;
- }
+ double z1 = surface.GetElevation(observerPoint.Point) + finalObserverOffset;
- //Create shape
- IPoint point = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true };
- ipFeature.Shape = point;
- ipFeature.Store();
- }
+ //create a new point feature
+ IFeature ipFeature = pointFc.CreateFeature();
- IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
- fd.Create(pointFc, null, "OBJECTID");
+ // Set the field values for the feature
+ SetFieldValues(finalObserverOffset, finalSurfaceOffset, muMinDist, muMaxDist, finalLeftHorizontalFOV,
+ finalRightHorizontalFOV, finalBottomVerticalFOV, finalTopVerticalFOV, ipFeature);
- StopEditOperation((IWorkspace)workspace);
+ if (double.IsNaN(z1))
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.RLOSPointsOutsideOfSurfaceExtent, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ return;
+ }
- try
- {
- ILayer layer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
- string layerPath = GetLayerPath(layer);
+ //Create shape
+ IPoint point = new PointClass() { Z = z1, X = observerPoint.Point.X, Y = observerPoint.Point.Y, ZAware = true };
+ ipFeature.Shape = point;
+ ipFeature.Store();
+ }
+
+ IFeatureClassDescriptor fd = new FeatureClassDescriptorClass();
+ fd.Create(pointFc, null, "OBJECTID");
- if (string.IsNullOrEmpty(layerPath))
+ StopEditOperation((IWorkspace)workspace);
+
+ try
{
- // if layer path didn't resolve, issue error and stop
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound, VisibilityLibrary.Properties.Resources.AEInvalidInput);
- throw new Exception(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound);
- }
+ ILayer layer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ string layerPath = GetLayerPath(layer);
- IFeatureLayer ipFeatureLayer = new FeatureLayerClass();
- ipFeatureLayer.FeatureClass = pointFc;
+ if (string.IsNullOrEmpty(layerPath))
+ {
+ // if layer path didn't resolve, issue error and stop
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound, VisibilityLibrary.Properties.Resources.AEInvalidInput);
+ throw new Exception(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound);
+ }
- IDataset ipDataset = (IDataset)pointFc;
- string outputFcName = ipDataset.BrowseName + "_output";
- string strPath = ipDataset.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + ipDataset.BrowseName;
- string outPath = ipDataset.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + outputFcName;
+ IFeatureLayer ipFeatureLayer = new FeatureLayerClass();
+ ipFeatureLayer.FeatureClass = pointFc;
- IVariantArray parameters = new VarArrayClass();
- parameters.Add(layerPath);
- parameters.Add(strPath);
- parameters.Add(outPath);
+ IDataset ipDataset = (IDataset)pointFc;
+ string outputFcName = ipDataset.BrowseName + "_output";
+ string strPath = ipDataset.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + ipDataset.BrowseName;
+ string outPath = ipDataset.Workspace.PathName + System.IO.Path.DirectorySeparatorChar + outputFcName;
- IGeoProcessor2 gp = new GeoProcessorClass();
+ IVariantArray parameters = new VarArrayClass();
+ parameters.Add(layerPath);
+ parameters.Add(strPath);
+ parameters.Add(outPath);
- gp.AddOutputsToMap = false;
+ IGeoProcessor2 gp = new GeoProcessorClass();
- // Add a mask to buffer the output to selected distance
- SetGPMask(workspace, maxRangeBufferGeomList, gp, "radiusMask");
+ gp.AddOutputsToMap = false;
- object oResult = gp.Execute("Visibility_sa", parameters, null);
- IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;
+ // Add a mask to buffer the output to selected distance
+ SetGPMask(workspace, maxRangeBufferGeomList, gp, "radiusMask");
- ComReleaser.ReleaseCOMObject(gp);
- gp = null;
- GC.Collect();
+ object oResult = gp.Execute("Visibility_sa", parameters, null);
+ IGeoProcessorResult ipResult = (IGeoProcessorResult)oResult;
- // Add the range fan geometries to the map
- foreach (IGeometry geom in rangeFanGeomList)
- {
- var color = new RgbColorClass() { Blue = 255 } as IColor;
- AddGraphicToMap(geom, color, true);
- }
+ ComReleaser.ReleaseCOMObject(gp);
+ gp = null;
+ GC.Collect();
+
+ // Add the range fan geometries to the map
+ foreach (IGeometry geom in rangeFanGeomList)
+ {
+ var color = new RgbColorClass() { Blue = 255 } as IColor;
+ AddGraphicToMap(geom, color, true);
+ }
- IRasterLayer outputRasterLayer = new RasterLayerClass();
- outputRasterLayer.CreateFromFilePath(outPath);
+ IRasterLayer outputRasterLayer = new RasterLayerClass();
+ outputRasterLayer.CreateFromFilePath(outPath);
- string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, rangeFanGeomList);
+ string fcName = IntersectOutput(outputRasterLayer, ipDataset, workspace, rangeFanGeomList);
- IFeatureClass finalFc = workspace.OpenFeatureClass(fcName);
+ IFeatureClass finalFc = workspace.OpenFeatureClass(fcName);
- IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
- outputFeatureLayer.FeatureClass = finalFc;
+ IFeatureLayer outputFeatureLayer = new FeatureLayerClass();
+ outputFeatureLayer.FeatureClass = finalFc;
- //Add it to a map if the layer is valid.
- if (outputFeatureLayer != null)
+ //Add it to a map if the layer is valid.
+ if (outputFeatureLayer != null)
+ {
+ // set the renderer
+ IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc);
+ IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)outputFeatureLayer;
+ geoLayer.Renderer = featRend;
+ geoLayer.Name = "RLOS_Visibility_" + RunCount.ToString();
+
+ // Set the layer transparency
+ IDisplayFilterManager filterManager = (IDisplayFilterManager)outputFeatureLayer;
+ ITransparencyDisplayFilter filter = new TransparencyDisplayFilter();
+ filter.Transparency = 80;
+ filterManager.DisplayFilter = filter;
+
+ ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
+ map.AddLayer((ILayer)outputFeatureLayer);
+
+ IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope;
+ ZoomToExtent(envelope);
+ }
+
+ RunCount += 1;
+ }
+ catch (Exception ex)
{
- // set the renderer
- IFeatureRenderer featRend = UniqueValueRenderer(workspace, finalFc);
- IGeoFeatureLayer geoLayer = (IGeoFeatureLayer)outputFeatureLayer;
- geoLayer.Renderer = featRend;
- geoLayer.Name = "RLOS_Visibility_" + RunCount.ToString();
-
- // Set the layer transparency
- IDisplayFilterManager filterManager = (IDisplayFilterManager)outputFeatureLayer;
- ITransparencyDisplayFilter filter = new TransparencyDisplayFilter();
- filter.Transparency = 80;
- filterManager.DisplayFilter = filter;
-
- ESRI.ArcGIS.Carto.IMap map = ArcMap.Document.FocusMap;
- map.AddLayer((ILayer)outputFeatureLayer);
-
- IEnvelope envelope = outputFeatureLayer.AreaOfInterest.Envelope;
- ZoomToExtent(envelope);
+ System.Diagnostics.Debug.WriteLine(ex.Message);
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
}
- RunCount += 1;
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ DisplayOutOfExtentMsg(selectedLayer);
+ //display point present out of extent
+ var colorObserver = new RgbColorClass() { Red = 255 };
+ var colorBorder = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 };
+ var observerOutOfExtent = new ObservableCollection(RLOS_ObserversOutOfExtent.Select(x => x.AddInPoint).Union(ObserverOutExtentPoints));
+ foreach (var point in observerOutOfExtent)
+ {
+ AddGraphicToMap(point.Point, colorObserver, markerStyle: esriSimpleMarkerStyle.esriSMSX, size: 10, borderColor: colorBorder);
+ }
}
}
+ else
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.OutOfExtentMsg, VisibilityLibrary.Properties.Resources.OutOfExtentHeader);
+ }
}
- catch(Exception ex)
+ catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
@@ -597,6 +620,9 @@ internal override void CreateMapElement()
finally
{
IsRunning = false;
+ IsRLOSValidSelection = false;
+ ClearRLOSCollections();
+ ValidateRLOS_LayerSelection();
}
}
@@ -650,29 +676,29 @@ public IFeatureRenderer UniqueValueRenderer(IFeatureWorkspace workspace, IFeatur
outlineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
if (ShowNonVisibleData == true)
- {
+ {
fillSymbol.Color = new RgbColorClass() { Red = 255 } as IColor;
fillSymbol.Outline = outlineSymbol;
uvRenderer.AddValue("0", "", fillSymbol as ISymbol);
- uvRenderer.set_Label("0", "Non-Visible");
+ uvRenderer.set_Label("0", "Non-Visible");
}
- fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor;
- fillSymbol2.Outline = outlineSymbol;
- uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol);
- uvRenderer.set_Label("1", "Visible by 1 Observer");
+ fillSymbol2.Color = new RgbColorClass() { Green = 255 } as IColor;
+ fillSymbol2.Outline = outlineSymbol;
+ uvRenderer.AddValue("1", "", fillSymbol2 as ISymbol);
+ uvRenderer.set_Label("1", "Visible by 1 Observer");
- int field = ipTable.FindField("gridcode");
- uvRenderer.set_Field(0, "gridcode");
+ int field = ipTable.FindField("gridcode");
+ uvRenderer.set_Field(0, "gridcode");
- for (int i = 2; i < uniqueValues; i++)
- {
- ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass();
- newFillSymbol.Color = colorRamp.get_Color(i);
- newFillSymbol.Outline = outlineSymbol;
- uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol);
- string label = "Visible by " + i.ToString() + " Observers";
- uvRenderer.set_Label(i.ToString(), label);
- }
+ for (int i = 2; i < uniqueValues; i++)
+ {
+ ISimpleFillSymbol newFillSymbol = new SimpleFillSymbolClass();
+ newFillSymbol.Color = colorRamp.get_Color(i);
+ newFillSymbol.Outline = outlineSymbol;
+ uvRenderer.AddValue(i.ToString(), "", newFillSymbol as ISymbol);
+ string label = "Visible by " + i.ToString() + " Observers";
+ uvRenderer.set_Label(i.ToString(), label);
+ }
return featRenderer;
}
@@ -716,7 +742,7 @@ public static bool StartEditOperation(IWorkspace ipWorkspace)
throw (ex);
}
}
-
+
return blnWasSuccessful;
}
@@ -1119,7 +1145,7 @@ private static double GetConversionFactor(ISpatialReference ipSpatialReference)
if (ipSpatialReference is IGeographicCoordinateSystem)
{
IAngularUnit ipAngularUnit = ((IGeographicCoordinateSystem)ipSpatialReference).CoordinateUnit;
- String name= ipAngularUnit.Name;
+ String name = ipAngularUnit.Name;
dConversionFactor = ipAngularUnit.ConversionFactor;
}
else
@@ -1138,13 +1164,13 @@ private static String GetUnitString(ISpatialReference ipSpatialReference)
{
IAngularUnit ipAngularUnit = ((IGeographicCoordinateSystem)ipSpatialReference).CoordinateUnit;
name = ipAngularUnit.Name;
-
+
}
else
{
ILinearUnit ipLinearUnit = ((IProjectedCoordinateSystem)ipSpatialReference).CoordinateUnit;
name = ipLinearUnit.Name;
-
+
}
return name;
}
@@ -1152,9 +1178,9 @@ private static String GetUnitString(ISpatialReference ipSpatialReference)
private static DistanceTypes GetMTUnitFromEsriUnit(String esriUnit)
{
DistanceTypes outUnit = DistanceTypes.Meters; ;
- switch(esriUnit)
+ switch (esriUnit)
{
-
+
case "Foot_US":
case "Foot":
outUnit = DistanceTypes.Feet;
@@ -1279,7 +1305,7 @@ private static string GetLayerPath(ILayer layer)
{
IImageServerLayer mlayer = layer as IImageServerLayer;
return mlayer.Name;
- }
+ }
else if (layer is IRasterLayer)
{
IRasterLayer rlayer = layer as IRasterLayer;
@@ -1294,6 +1320,50 @@ private static string GetLayerPath(ILayer layer)
return null;
}
+ private void ReadSelectedLayerPoints()
+ {
+
+ var surface = GetSurfaceFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
+ double finalObserverOffset = GetOffsetInZUnits(ObserverOffset.Value, surface.ZFactor, OffsetUnitType);
+
+ var observerColor = new RgbColor() { Blue = 255 } as IColor;
+ ReadSelectedLyrPoints(RLOS_ObserversInExtent, RLOS_ObserversOutOfExtent, SelectedRLOS_ObserverLyrName, observerColor);
+ }
+
+
+ private void DisplayOutOfExtentMsg(string selectedLayer)
+ {
+ var observerIDCollection = RLOS_ObserversOutOfExtent.Select(x => x.ID).ToList();
+ var observerString = string.Empty;
+ var targetString = string.Empty;
+ foreach (var item in observerIDCollection)
+ {
+ if (observerString == "")
+ observerString = item.ToString();
+ else
+ observerString = observerString + "," + item.ToString();
+ }
+ if (observerIDCollection.Any())
+ {
+ if (observerIDCollection.Count <= 10)
+ {
+ var msgString = string.Empty;
+ if (observerIDCollection.Any())
+ {
+ msgString = "Observers lying outside the extent of elevation surface are: " + observerString;
+ }
+ System.Windows.MessageBox.Show(msgString,
+ "Unable To Process For Few Locations");
+ }
+ else
+ {
+ System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSPointsOutsideOfSurfaceExtent,
+ VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
+ }
+
+ }
+ }
+
#endregion
}
}
diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/TabBaseViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/TabBaseViewModel.cs
index 73a9584..3af72f4 100644
--- a/source/addins/ArcMapAddinVisibility/ViewModels/TabBaseViewModel.cs
+++ b/source/addins/ArcMapAddinVisibility/ViewModels/TabBaseViewModel.cs
@@ -42,6 +42,7 @@ public TabBaseViewModel()
CancelCommand = new RelayCommand(OnCancelCommand);
// Mediator
+ Mediator.Register(Constants.NEW_MAP_POINT, OnMapClickEvent);
Mediator.Register(Constants.NEW_MAP_POINT, OnNewMapPointEvent);
Mediator.Register(Constants.MOUSE_MOVE_POINT, OnMouseMoveEvent);
Mediator.Register(Constants.TAB_ITEM_SELECTED, OnTabItemSelected);
@@ -68,7 +69,7 @@ protected virtual void OnActiveToolChanged(object obj)
{
string currentActiveToolName = obj as string;
- if ((currentActiveToolName == ThisAddIn.IDs.MapPointTool))
+ if ((currentActiveToolName == ThisAddIn.IDs.MapPointTool))
return;
lastActiveToolName = currentActiveToolName;
@@ -292,6 +293,7 @@ public virtual bool CanCreateElement
public VisibilityLibrary.Helpers.RelayCommand ActivateToolCommand { get; set; }
public VisibilityLibrary.Helpers.RelayCommand EnterKeyCommand { get; set; }
public VisibilityLibrary.Helpers.RelayCommand CancelCommand { get; set; }
+ public bool IsMapClick { get; set; }
internal void OnCancelCommand(object obj)
{
@@ -411,7 +413,7 @@ internal void RemoveGraphics(IGraphicsContainer gc, List list)
}
}
elementList.Clear();
-
+
RaisePropertyChanged(() => HasMapGraphics);
}
@@ -474,7 +476,13 @@ internal virtual void OnNewMapPointEvent(object obj)
// do nothing
}
+ internal virtual void OnMapClickEvent(object obj)
+ {
+ IsMapClick = true;
+ }
+
#endregion
+
#region Public Functions
///
/// Method used to deactivate tool
@@ -502,11 +510,11 @@ public void SetToolActiveInToolBar(string toolName)
return;
}
- if ((ArcMap.Application.CurrentTool != null) &&
+ if ((ArcMap.Application.CurrentTool != null) &&
(ArcMap.Application.CurrentTool.Name.Equals(toolName)))
- // Tricky: Check if tool already active - because setting CurrentTool again will
- // cause Activate/Deactive to be called by ArcGIS framework
- return;
+ // Tricky: Check if tool already active - because setting CurrentTool again will
+ // cause Activate/Deactive to be called by ArcGIS framework
+ return;
ESRI.ArcGIS.Framework.ICommandBars commandBars = ArcMap.Application.Document.CommandBars;
ESRI.ArcGIS.esriSystem.UID commandID = new ESRI.ArcGIS.esriSystem.UIDClass();
@@ -530,37 +538,37 @@ private string GetFormattedPoint(IPoint point)
try
{
- var cn = point as IConversionNotation;
- if (cn != null)
- {
- switch (VisibilityConfig.AddInConfig.DisplayCoordinateType)
+ var cn = point as IConversionNotation;
+ if (cn != null)
{
- case CoordinateTypes.DD:
- result = cn.GetDDFromCoords(6);
- break;
- case CoordinateTypes.DDM:
- result = cn.GetDDMFromCoords(4);
- break;
- case CoordinateTypes.DMS:
- result = cn.GetDMSFromCoords(2);
- break;
- //case CoordinateTypes.GARS:
- // result = cn.GetGARSFromCoords();
- // break;
- case CoordinateTypes.MGRS:
- result = cn.CreateMGRS(5, true, esriMGRSModeEnum.esriMGRSMode_Automatic);
- break;
- case CoordinateTypes.USNG:
- result = cn.GetUSNGFromCoords(5, true, true);
- break;
- case CoordinateTypes.UTM:
- result = cn.GetUTMFromCoords(esriUTMConversionOptionsEnum.esriUTMAddSpaces | esriUTMConversionOptionsEnum.esriUTMUseNS);
- break;
- default:
- break;
+ switch (VisibilityConfig.AddInConfig.DisplayCoordinateType)
+ {
+ case CoordinateTypes.DD:
+ result = cn.GetDDFromCoords(6);
+ break;
+ case CoordinateTypes.DDM:
+ result = cn.GetDDMFromCoords(4);
+ break;
+ case CoordinateTypes.DMS:
+ result = cn.GetDMSFromCoords(2);
+ break;
+ //case CoordinateTypes.GARS:
+ // result = cn.GetGARSFromCoords();
+ // break;
+ case CoordinateTypes.MGRS:
+ result = cn.CreateMGRS(5, true, esriMGRSModeEnum.esriMGRSMode_Automatic);
+ break;
+ case CoordinateTypes.USNG:
+ result = cn.GetUSNGFromCoords(5, true, true);
+ break;
+ case CoordinateTypes.UTM:
+ result = cn.GetUTMFromCoords(esriUTMConversionOptionsEnum.esriUTMAddSpaces | esriUTMConversionOptionsEnum.esriUTMUseNS);
+ break;
+ default:
+ break;
+ }
}
}
- }
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
@@ -600,6 +608,7 @@ private void OnTabItemSelected(object obj)
return;
IsActiveTab = (obj == this);
+ IsMapClick = false;
}
internal string AddTextToMap(string text, IGeometry geom, IColor color, bool IsTempGraphic = false, int size = 12)
@@ -653,9 +662,12 @@ internal string AddTextToMap(string text, IGeometry geom, IColor color, bool IsT
/// Adds a graphic element to the map graphics container
///
/// IGeometry
- internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic = false,
- esriSimpleMarkerStyle markerStyle = esriSimpleMarkerStyle.esriSMSCircle, int size = 5)
+ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic = false,
+ esriSimpleMarkerStyle markerStyle = esriSimpleMarkerStyle.esriSMSCircle, int size = 5, IColor borderColor = null)
{
+ if (borderColor == null)
+ borderColor = color;
+
if (geom == null || ArcMap.Document == null || ArcMap.Document.FocusMap == null)
return string.Empty;
@@ -669,7 +681,7 @@ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic
var simpleMarkerSymbol = (ISimpleMarkerSymbol)new SimpleMarkerSymbol();
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Outline = true;
- simpleMarkerSymbol.OutlineColor = color;
+ simpleMarkerSymbol.OutlineColor = borderColor;
simpleMarkerSymbol.Size = size;
simpleMarkerSymbol.Style = markerStyle;
@@ -695,7 +707,7 @@ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic
IPolygonElement pe = (IPolygonElement)new PolygonElementClass();
element = pe as IElement;
IFillShapeElement fe = (IFillShapeElement)pe;
-
+
var fillSymbol = new SimpleFillSymbolClass();
RgbColor selectedColor = new RgbColorClass();
selectedColor.Red = 0;
@@ -703,8 +715,8 @@ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic
selectedColor.Blue = 0;
selectedColor.Transparency = (byte)0;
- fillSymbol.Color = selectedColor;
-
+ fillSymbol.Color = selectedColor;
+
fe.Symbol = fillSymbol;
}
@@ -720,7 +732,7 @@ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic
var eprop = (IElementProperties)element;
eprop.Name = Guid.NewGuid().ToString();
- GraphicsList.Add(new AMGraphic(eprop.Name, geom, IsTempGraphic));
+ GraphicsList.Add(new AMGraphic(eprop.Name, geom, IsTempGraphic));
gc.AddElement(element, 0);
@@ -732,7 +744,7 @@ internal string AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic
}
internal DistanceTypes GetDistanceType(int linearUnitFactoryCode)
- {
+ {
DistanceTypes distanceType = DistanceTypes.Meters;
switch (linearUnitFactoryCode)
{
@@ -826,7 +838,7 @@ internal void ZoomToExtent(IGeometry geom)
var av = (IActiveView)ArcMap.Document.FocusMap;
IEnvelope env = geom.Envelope;
-
+
double extentPercent = (env.XMax - env.XMin) > (env.YMax - env.YMin) ? (env.XMax - env.XMin) * .3 : (env.YMax - env.YMin) * .3;
env.XMax = env.XMax + extentPercent;
env.XMin = env.XMin - extentPercent;
diff --git a/source/addins/ProAppVisibilityModule/Helpers/FeatureClassHelper.cs b/source/addins/ProAppVisibilityModule/Helpers/FeatureClassHelper.cs
index 1105b4f..ca9ae27 100644
--- a/source/addins/ProAppVisibilityModule/Helpers/FeatureClassHelper.cs
+++ b/source/addins/ProAppVisibilityModule/Helpers/FeatureClassHelper.cs
@@ -43,11 +43,11 @@ public class FeatureClassHelper
/// - POLYLINE
/// - POLYGON
///
- public static async Task CreateLayer(string featureclassName, string featureclassType, bool zEnabled, bool addToMap)
+ public static async Task CreateLayer(string featureDatasetName, string featureclassName, string featureclassType, bool zEnabled, bool addToMap)
{
List