ArcGIS Pro 3.2 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

In This Topic
    CanGetLineOfSight Method (SurfaceLayer)
    In This Topic
    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
    )
    Public Function CanGetLineOfSight( _
       ByVal lineOfSightParams As LineOfSightParams _
    ) As Boolean

    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;
      bool targetVisibleFromVisibleLine = results.IsTargetVisibleFromVisibleLine;
      bool targetVisibleFromInVisibleLine = 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