ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / SurfaceLayer Class / GetLineOfSight Method
The object which contains all input values.
Example

In This Topic
    GetLineOfSight Method (SurfaceLayer)
    In This Topic
    Performs a line of sight analysis for an observer and target point on the surface. Determines if the target point is visible from a given observer point. This method requires a 3D Analyst license. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public virtual LineOfSightResult GetLineOfSight( 
       LineOfSightParams lineOfSightParams
    )
    Public Overridable Function GetLineOfSight( _
       ByVal lineOfSightParams As LineOfSightParams _
    ) As LineOfSightResult

    Parameters

    lineOfSightParams
    The object which contains all input values.

    Return Value

    A LineOfSightResult instance.
    Exceptions
    ExceptionDescription
    lineOfSightParams cannot be null.
    GetLineOfSight is only supported on TIN layers.
    A 3D Analyst license is required.
    The set of parameters is invalid for this surface. See CanGetLineOfSight.
    An exception occurred within the Line of Sight calculation.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    See the following links for more information about Line of Sight analysis - https://pro.arcgis.com/en/pro-app/latest/tool-reference/3d-analyst/line-of-sight.htm and https://pro.arcgis.com/en/pro-app/latest/tool-reference/3d-analyst/how-line-of-sight-works.htm. Note that the geoprocessing tool uses a feature class of lines for the observer and target inputs whereas this method performs the calculation on a single pair of MapPoints only.

    Use CanGetLineOfSight to determine if the set of input parameters is valid prior to calling this method.

    The elevation of the observer point (let's call it observerZ) is derived as follows. If you provide a Z-aware (3D) observer point, observerZ will be set to its Z value; if you provide a 2D observer point, then observerZ will be set to the Z value of the surface at the XY of the observer point. If you specify an observer height offset, it will be added to observerZ. Similarly with the target point for calculating targetZ.

    GetLineOfSight doesn't always produce all possible results. Internally the function generates an imaginary straight 3D line (the sight line) from the observer point (at observerZ) to the target point (at targetZ). It then interpolates (drapes) this line onto the surface, creating an imaginary profile line. The typical results consist of a "visible" line (possibly a multipart line) representing the portion of the profile line which is visible from the observer point (at observerZ), and an "invisible" line (possibly a multipart line) representing the portion of the profile line which is not visible from the observer point (at observerZ). If the sight line intersects the surface at least once, then an obstruction point is created at the first intersection point which is closest to the observer point.The obstruction point, if one is created, will always lie along the profile line, but will typically not occur at the end of the first visible line part.
    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