View inMAUIWinUIWPF View on GitHub Sample viewer app

Sample field function values at a given position from a field analysis.

Get field function value from a point

Use case

Many spatial workflows depend on sampling a specific location and keeping the result current as information changes. In flight planning for an aircraft flying over uneven terrain, elevation and ground clearance at a location provide useful context, especially when readings reflect updates to the planned altitude of the aircraft.

How to use the sample

The sample opens displaying both an elevation field (purple-gray tones) and a boolean field that shows where an aircraft flying with an altitude of 2000m above sea level would not have ground clearance (red). The ground clearance field is determined by comparing the elevation field with an altitude value. A callout in the centre of the data displays the values of each field, which have been sampled from the callout’s position. Tap the map, or drag the sampling point, to sample the values of each field across the data extent. Use the control panel to adjust the altitude value and see the ground clearance’s spatial extent update across the map. The tapped position’s sampled value of the ground clearance boolean field will update automatically.

Red areas indicate terrain that would have no ground clearance given the set altitude value.

How it works

  1. Create a Map and set it on a MapView.
  2. Add a GraphicsOverlay to the map view to draw the point for sampling.
  3. Add an AnalysisOverlay to the map view to display field analyses.
  4. Create a ContinuousField from a raster file containing elevation data using ContinuousField.CreateAsync.
  5. Create a ContinuousFieldFunction from the continuous field, using ContinuousFieldSupplier.
  6. Create a ContinuousFieldSampleFunction from the continuous field function.
  7. Create a FloatSupplier from a float. Update its value with FloatSupplier.Value when new values are required for updating analyses.
  8. Create a new BooleanFieldFunction with map algebra using IsLessThan(altitudeSupplier).
  9. Create a BooleanFieldSampleFunction from the boolean field function.
  10. Load the map with Map.LoadAsync, then create a FieldAnalysis each for the continuous field function and boolean field function using appropriate renderers. Add both field analyses to the AnalysisOverlay.
  11. Set the Position of the field sample functions using a MapPoint and evaluate both field sample functions with EvaluateAsync. Then, use the returned sample’s Value to get the sampled value.
  12. Display the sampled values in a callout using MapView.ShowCalloutAt.
  13. As the float supplier value changes, the boolean field analysis automatically recalculates and redraws in the analysis overlay. Reevaluate the boolean field sample function to update its sampled value in the callout.

Relevant API

  • AnalysisOverlay
  • BooleanFieldFunction
  • BooleanFieldSampleFunction
  • ContinuousField
  • ContinuousFieldFunction
  • ContinuousFieldSampleFunction
  • ContinuousFieldSupplier
  • FieldAnalysis
  • FloatSupplier

About the data

The sample uses a 1m resolution digital terrain elevation raster of the area over Méribel, in the French Alps.

Tags

analysis overlay, elevation, field analysis, interactive, map algebra, raster, sample, spatial analysis, terrain

Sample code

GetFieldFunctionValueFromAPoint.xaml.csGetFieldFunctionValueFromAPoint.xaml.csGetFieldFunctionValueFromAPoint.xaml
// Copyright 2026 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
using ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Analysis;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Rasters;
using Esri.ArcGISRuntime.Symbology;
using Esri.ArcGISRuntime.UI;
using Esri.ArcGISRuntime.UI.Controls;
using Esri.ArcGISRuntime.UI.GeoAnalysis;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
namespace ArcGIS.WPF.Samples.GetFieldFunctionValueFromAPoint
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Get field function value from a point",
category: "Analysis",
description: "Sample field function values at a given position from a field analysis.",
instructions: "The sample opens displaying both an elevation field (purple-gray tones) and a boolean field that shows where an aircraft flying with an altitude of 2000m above sea level would not have ground clearance (red). The ground clearance field is determined by comparing the elevation field with an altitude value. A callout in the centre of the data displays the values of each field, which have been sampled from the callout's position. Tap the map, or drag the sampling point, to sample the values of each field across the data extent. Use the control panel to adjust the altitude value and see the ground clearance's spatial extent update across the map. The tapped position's sampled value of the ground clearance boolean field will update automatically.",
tags: new[] { "analysis overlay", "elevation", "field analysis", "interactive", "map algebra", "raster", "sample", "spatial analysis", "terrain" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData("6bb0ad0e3bd5410fa52191184578f0b2")]
[ArcGIS.Samples.Shared.Attributes.EmbeddedResource(@"PictureMarkerSymbols\helicopter.png")]
public partial class GetFieldFunctionValueFromAPoint
{
private const double AltitudeStep = (2595.0 - 1500.0) / 100;
// Share a mutable aircraft altitude between the clearance analysis and its sampling function.
private readonly FloatSupplier _altitudeSupplier = new FloatSupplier(2000);
private readonly Graphic _sampleGraphic = new Graphic();
private readonly HashSet<FieldAnalysis> _updatingAnalyses = new HashSet<FieldAnalysis>();
private ContinuousFieldSampleFunction _elevationSampleFunction;
private BooleanFieldSampleFunction _clearanceSampleFunction;
private MapPoint _samplePoint;
private bool _isReady;
private bool _isSampling;
private bool _isDragging;
private bool _isActive = true;
public GetFieldFunctionValueFromAPoint()
{
InitializeComponent();
Unloaded += OnSampleUnloaded;
_ = Initialize();
}
private async Task Initialize()
{
// Create a map with a dark hillshade basemap to provide terrain context.
MyMapView.Map = new Map(BasemapStyle.ArcGISHillshadeDark);
// Disable panning so dragging can be used to move the sampling point.
MyMapView.InteractionOptions = new MapViewInteractionOptions { IsPanEnabled = false };
// Add a graphics overlay to display the helicopter at the sampling position.
var graphicsOverlay = new GraphicsOverlay();
graphicsOverlay.Graphics.Add(_sampleGraphic);
MyMapView.GraphicsOverlays.Add(graphicsOverlay);
// Add an analysis overlay to display the elevation and ground-clearance fields.
var analysisOverlay = new AnalysisOverlay();
MyMapView.AnalysisOverlays.Add(analysisOverlay);
try
{
// Create the helicopter marker symbol from an embedded image.
string resourceName = GetType().Assembly.GetManifestResourceNames()
.Single(name => name.EndsWith(".helicopter.png"));
using (Stream image = GetType().Assembly.GetManifestResourceStream(resourceName))
{
var symbol = await PictureMarkerSymbol.CreateAsync(image);
symbol.Width = 28;
symbol.Height = 28;
_sampleGraphic.Symbol = symbol;
}
// Get the path to the elevation raster downloaded for this sample.
string rasterPath = DataManager.GetDataFolder("6bb0ad0e3bd5410fa52191184578f0b2", "Meribel.tif");
// Create a continuous elevation field from the raster's first band (index 0).
var elevationField = await ContinuousField.CreateAsync(new[] { rasterPath }, 0);
// Load the map before creating field analyses so its spatial reference is available.
await MyMapView.Map.LoadAsync();
if (!_isActive) return;
// Wrap the field in a function shared by the rendered analysis and the elevation sampler.
var elevationFunction = new ContinuousFieldSupplier(elevationField);
// Create an elevation sampler whose position will be assigned before evaluation.
_elevationSampleFunction = new ContinuousFieldSampleFunction(elevationFunction, null);
// True means terrain is below the aircraft. Changing the supplier updates this expression in place.
var clearanceFunction = elevationFunction.IsLessThan(_altitudeSupplier);
// Create a sampler for the boolean ground-clearance result.
_clearanceSampleFunction = new BooleanFieldSampleFunction(clearanceFunction, null);
// Render elevation with fixed stretch limits and a purple-gray-to-white color ramp.
var elevationRenderer = new StretchRenderer(
new MinMaxStretchParameters(new[] { 1199.0 }, new[] { 2740.0 }),
new[] { 1.0 }, false,
ColorRamp.Create(new[] { Color.FromArgb(96, 98, 148), Color.White }, 256));
// Boolean fields use index 0 for false (no clearance) and 1 for true (clear).
// Leave clear areas transparent so the elevation analysis remains visible beneath them.
var clearanceRenderer = new ColormapRenderer(Colormap.Create(new[]
{
Color.FromArgb(255, 210, 60, 60),
Color.FromArgb(0, 50, 170, 90)
}));
// Track rendering progress and errors independently of the point-sampling results.
MyMapView.AnalysisViewStateChanged += OnAnalysisViewStateChanged;
// Field analyses evaluate and redraw automatically when their function inputs change.
// Display elevation first, then clearance, retaining hillshade detail with half opacity.
analysisOverlay.Analyses.Add(new FieldAnalysis(elevationFunction, elevationRenderer) { Opacity = 0.5f });
analysisOverlay.Analyses.Add(new FieldAnalysis(clearanceFunction, clearanceRenderer) { Opacity = 0.5f });
// Set the initial viewpoint to the center of the elevation field.
MyMapView.SetViewpoint(new Viewpoint(elevationField.Extent.GetCenter(), 50000));
// Register mouse events for point placement and dragging.
MyMapView.AddHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnPointerPressed), true);
MyMapView.AddHandler(PreviewMouseMoveEvent, new MouseEventHandler(OnPointerMoved), true);
MyMapView.AddHandler(PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(OnPointerReleased), true);
MyMapView.LostMouseCapture += OnPointerCaptureLost;
_isReady = true;
AltitudeSlider.IsEnabled = true;
// Sample both fields at the center of the data to populate the initial callout.
await SampleAtAsync(elevationField.Extent.GetCenter());
}
catch (Exception ex)
{
if (_isActive) ErrorMessage.Text = $"Unable to initialize field sampling: {ex.Message}";
}
finally
{
LoadingStatus.Visibility = Visibility.Collapsed;
}
}
private async Task SampleAtAsync(MapPoint location)
{
if (!_isReady || location == null) return;
// Move the sampling graphic to the requested location at the current aircraft altitude.
_samplePoint = new MapPoint(location.X, location.Y, _altitudeSupplier.Value.Value, location.SpatialReference);
_sampleGraphic.Geometry = _samplePoint;
if (_isSampling) return;
_isSampling = true;
try
{
// Coalesce rapid drags and slider changes, always displaying the most recently requested sample.
while (_isReady)
{
MapPoint point = _samplePoint;
float? altitude = _altitudeSupplier.Value;
// Set the position used by both sampling functions.
_elevationSampleFunction.Position = point;
_clearanceSampleFunction.Position = point;
// Evaluate the functions explicitly to retrieve elevation and the clearance criterion.
var elevationSample = await _elevationSampleFunction.EvaluateAsync();
var clearanceSample = await _clearanceSampleFunction.EvaluateAsync();
if (!_isActive || !_isReady) return;
// Discard outdated results and sample the latest position on the next iteration.
if (!ReferenceEquals(point, _samplePoint)) continue;
// A null sample is NoData, including positions outside the raster extent.
string elevation = elevationSample.Value?.ToString("F2") ?? "null";
// Calculate numeric clearance from the sampled elevation, preserving null for NoData.
string clearance = (altitude - elevationSample.Value)?.ToString("F2") ?? "null";
string status = clearanceSample.Value.HasValue
? (clearanceSample.Value.Value ? "Clear" : "Not Clear") : "null";
var callout = new CalloutDefinition("Field values",
$"Elevation (m): {elevation}\nClearance above the ground (m): {clearance}\nGround clearance status: {status}");
// Anchor the current values to the sampled map position.
MyMapView.ShowCalloutAt(point, callout);
ErrorMessage.Text = string.Empty;
break;
}
}
catch (Exception ex)
{
if (_isActive)
{
MyMapView.DismissCallout();
ErrorMessage.Text = $"Field sampling failed: {ex.Message}";
}
}
finally
{
_isSampling = false;
}
}
private void OnAltitudeChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
// Ignore value changes bubbling from the progress bar in the slider's control template.
if (!_isReady || !ReferenceEquals(e.OriginalSource, AltitudeSlider)) return;
double altitude = 1500 + Math.Round((e.NewValue - 1500) / AltitudeStep) * AltitudeStep;
// Update the supplier rather than rebuilding the clearance function or its analysis.
_altitudeSupplier.Value = (float)altitude;
AltitudeLabel.Text = $"Aircraft altitude (MSL): {altitude:F0} m";
// The overlay redraws automatically; reevaluate the sample functions to refresh the callout.
_ = SampleAtAsync(_samplePoint);
}
private void OnAnalysisViewStateChanged(object sender, AnalysisViewStateChangedEventArgs e)
{
Dispatcher.InvokeAsync(() =>
{
if (!_isActive || !(e.Analysis is FieldAnalysis analysis)) return;
// The two field analyses can finish updating at different times.
if (e.AnalysisViewState.Status == AnalysisViewStatus.Updating)
_updatingAnalyses.Add(analysis);
else
_updatingAnalyses.Remove(analysis);
// Show updating text only while analysis is active; retain the dot when idle.
bool isUpdating = _updatingAnalyses.Count > 0;
string status = isUpdating ? "Analysis updating" : "Analysis idle";
UpdatingStatus.Visibility = isUpdating ? Visibility.Visible : Visibility.Collapsed;
AnalysisStatusDot.Foreground = new System.Windows.Media.SolidColorBrush(
isUpdating ? System.Windows.Media.Color.FromRgb(105, 242, 110) : System.Windows.Media.Color.FromRgb(158, 158, 158));
AnalysisStatusDot.ToolTip = status;
System.Windows.Automation.AutomationProperties.SetName(AnalysisStatusDot, status);
if (e.AnalysisViewState.Status == AnalysisViewStatus.Error)
{
_isReady = false;
AltitudeSlider.IsEnabled = false;
MyMapView.DismissCallout();
ErrorMessage.Text = $"Field analysis failed: {e.AnalysisViewState.Error?.Message ?? "Unknown analysis error."}";
}
});
}
private void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
{
_ = SampleAtAsync(e.Location);
e.Handled = true;
}
private void OnPointerPressed(object sender, MouseButtonEventArgs e)
{
if (!_isReady) return;
_isDragging = true;
// Capture input so the drag can finish even if the pointer leaves the map.
MyMapView.CaptureMouse();
// Convert the screen position to a map location before sampling.
_ = SampleAtAsync(MyMapView.ScreenToLocation(e.GetPosition(MyMapView)));
e.Handled = true;
}
private void OnPointerMoved(object sender, MouseEventArgs e)
{
if (_isDragging && e.LeftButton == MouseButtonState.Pressed)
_ = SampleAtAsync(MyMapView.ScreenToLocation(e.GetPosition(MyMapView)));
}
private void OnPointerReleased(object sender, MouseButtonEventArgs e)
{
if (_isDragging)
_ = SampleAtAsync(MyMapView.ScreenToLocation(e.GetPosition(MyMapView)));
_isDragging = false;
MyMapView.ReleaseMouseCapture();
}
private void OnPointerCaptureLost(object sender, MouseEventArgs e)
{
_isDragging = false;
}
private void OnSampleUnloaded(object sender, RoutedEventArgs e)
{
// Stop view updates and detach input and analysis callbacks when leaving the sample.
_isActive = false;
_isReady = false;
_isDragging = false;
MyMapView.ReleaseMouseCapture();
MyMapView.AnalysisViewStateChanged -= OnAnalysisViewStateChanged;
MyMapView.RemoveHandler(PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnPointerPressed));
MyMapView.RemoveHandler(PreviewMouseMoveEvent, new MouseEventHandler(OnPointerMoved));
MyMapView.RemoveHandler(PreviewMouseLeftButtonUpEvent, new MouseButtonEventHandler(OnPointerReleased));
MyMapView.LostMouseCapture -= OnPointerCaptureLost;
}
}
}