Perform a line of sight analysis in a map view between fixed observer and target positions.

Use case
Line of sight analysis determines whether a target can be seen from one or more observer locations based on elevation data. This can support planning workflows such as siting communication equipment, assessing observation coverage, or evaluating potential obstructions between known locations. In this sample, several predefined observer points are evaluated against a single fixed target to compare visibility outcomes side by side.
Note: This analysis is a form of “data-driven analysis”, which means the analysis is calculated at the resolution of the data rather than the resolution of the display.
How to use the sample
The sample loads with a map centered on the Isle of Arran, Scotland, and runs a line of sight analysis from multiple observer points (triangles) to a fixed target point (beacon icon) located at the highest point of the island. Solid green line segments represent visible portions of each line of sight result, and dashed gray segments represent not visible portions. Tap on each observer to see a callout that reports whether the target is visible and over what distance the line remains unobstructed. Use the toggle to show only results where the target is visible from the observer.
How it works
- Create a
Mapand pass it to aMapView. - Create a
GraphicsOverlayand add target and observer points to it, along with an appropriate symbol. Create anotherGraphicsOverlaythat will display the line of sight result graphics. - Create a
ContinuousFieldfrom a raster file containing elevation data. - Create a list of
LineOfSightPositionfrom target and observerPoints and aHeightOrigin.relative. - Configure
LineOfSightParameterswithObserverTargetPairs, using the list of observer and target line of sight positions. - Create a
LineOfSightFunctionfrom the continuous field and line of sight parameters. - Evaluate the function to get
LineOfSightresults. - Create a
Graphicfrom each result, using the geometry of the result’svisibleLineornotVisibleLineresult, and an appropriate symbol. - Use
LineOfSight.targetVisibilityto determine if the observer position has a direct line of sight to the target position. - Get the length of the visible line result with
GeometryEngine.geodeticLength(of:lengthUnit:curveType:)to report results.
Relevant API
- ContinuousField
- GeometryEngine
- GraphicsOverlay
- LineOfSight
- LineOfSightFunction
- LineOfSightParameters
- LineOfSightPosition
- ObserverTargetPairs
About the data
The sample uses a 10m resolution digital terrain elevation raster of the Isle of Arran, Scotland (Raster data Copyright Scottish Government and SEPA (2014)).
Tags
analysis, elevation, line of sight, map view, spatial analysis, terrain, visibility