ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / SurfaceLayer Class / CanGetLineOfSight Method
A set of parameters that will be used to calculate the Line of Sight.
Example Version

CanGetLineOfSight Method (SurfaceLayer)
Determines whether a Line of Sight analysis can be calculated for the given set of parameters. This method must be called on the MCT. Use QueuedTask.Run.
Syntax
public bool CanGetLineOfSight( 
   LineOfSightParams lineOfSightParams
)

Parameters

lineOfSightParams
A set of parameters that will be used to calculate the Line of Sight.

Return Value

True if checks pass. False otherwise.
Remarks
It is important to call this method prior to GetLineOfSight to ensure that a possible result can be found given the set of input parameters. In addition to checking for valid observer and target points (that is they have x,y coordinates) and non NaN observer height, target height and refraction factors, the observer and target points must also lie within the extent of the surface's area. this method also checks for a 3D Analyst license which is required to perform the analysis. Finally if LineOfSightParams.ApplyCurvature or LineOfSightParams.ApplyRefraction are set to true, then the spatial reference of the surface needs to be in a projected coordinate system and have Z coordinate units defined.

Note that if this method returns true it does not preclude the GetLineOfSight method from throwing an exception due to a calculation error and callers should code defensively and use appropriate exception handling.
Example
Get Line of Sight
var losParams = new LineOfSightParams();
losParams.ObserverPoint = observerPoint;
losParams.TargetPoint = targetPoint;

// add offsets if appropriate
// losParams.ObserverHeightOffset = observerOffset;
// losParams.TargetHeightOffset = targerOffset;

// set output spatial reference
losParams.OutputSpatialReference = MapView.Active.Map.SpatialReference;

LineOfSightResult results = null;
try
{
  if (tinLayer.CanGetLineOfSight(losParams))
    results = tinLayer.GetLineOfSight(losParams);
}
catch (Exception ex)
{
  // log exception message
}

if (results != null)
{
  bool targetIsVisibleFromObserverPoint = results.IsTargetVisibleFromObserverPoint;
  //These properties are not used. They will always be false
  // results.IsTargetVisibleFromVisibleLine;
  // results.IsTargetVisibleFromInvisibleLine;


  if (results.VisibleLine != null)
    MapView.Active.AddOverlay(results.VisibleLine, visibleLineSymbol.MakeSymbolReference());
  if (results.InvisibleLine != null)
    MapView.Active.AddOverlay(results.VisibleLine, invisibleLineSymbol.MakeSymbolReference());
  if (results.ObstructionPoint != null)
    MapView.Active.AddOverlay(results.ObstructionPoint, obstructionPointSymbol.MakeSymbolReference());
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3.2 or higher.
See Also