Use float suppliers to dynamically update numeric inputs to a map algebra expression and refresh analysis results as the input values change.

Use case
Adjust a slope range to explore terrain. The sample initially highlights slopes from 0 to 10 degrees over an elevation field. Change the minimum and maximum values from 0 to 85 degrees to update the displayed slope results.
How to use the sample
When the sample opens, the map shows the result of a slope analysis which displays slopes between 0 to 10 degrees. This range shows gentle hills and flatter areas such as roads and man-made structures in dark purple. Select Settings and drag the range slider handles to adjust the minimum and maximum slope values between 0 and 85 degrees (the maximum slope value of the data). The analysis updates automatically to show only slopes within the selected range. An indicator in the settings panel shows when the analysis is updating. The slope results are drawn on top of an elevation field which is rendered with a surface color ramp to provide context for the data. Green areas represent lower lying terrain, and brown to white reflects higher elevations.
How it works
- Create a
ContinuousFieldfrom an elevation raster file usingContinuousField::createFromFilesAsync. - Create a
ContinuousFieldFunctionfrom the continuous field usingContinuousFieldSupplier. - Derive a
slopefunction from the continuous field function. - Create two
FloatSupplierinstances and set theirvalueproperties to the initial minimum and maximum slope values. - Create a
BooleanFieldFunctionfor the slope range using the map algebra operationsisGreaterThanOrEqualTo,isLessThanOrEqualTo, andlogicalAnd, with the float suppliers as inputs. - Apply the boolean selection to the slope function using
maskto retain only slopes within the selected range. - Create a
FieldAnalysisfor the masked slope function usingContinuousFieldFunctionand aStretchRenderer. - Add the field analysis to an
AnalysisOverlayand add the overlay to the map view. - Update the float suppliers’
valueproperties to update the analysis result dynamically.
Relevant API
- AnalysisOverlay
- BooleanFieldFunction
- ColorRamp
- ContinuousField
- ContinuousFieldFunction
- ContinuousFieldSupplier
- FieldAnalysis
- FloatSupplier
- StretchRenderer
About the data
The sample uses a 1m resolution digital terrain elevation raster of the area over Méribel, in the French Alps. The spatial reference of the data is UTM32N.
Tags
elevation, field analysis, float supplier, map algebra, raster, slope, terrain
Sample code
// [WriteFile Name=ControlMapAlgebraInputsWithFloatSuppliers, Category=Analysis]// [Legal]// 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.// [Legal]
#ifdef PCH_BUILD#include "pch.hpp"#endif // PCH_BUILD
#include "ControlMapAlgebraInputsWithFloatSuppliers.h"
#include "AnalysisOverlay.h"#include "AnalysisOverlayListModel.h"#include "AnalysisListModel.h"#include "AnalysisViewState.h"#include "BooleanFieldFunction.h"#include "ColorRamp.h"#include "ContinuousField.h"#include "ContinuousFieldFunction.h"#include "ContinuousFieldSupplier.h"#include "Envelope.h"#include "Error.h"#include "FieldAnalysis.h"#include "FloatSupplier.h"#include "Map.h"#include "MapQuickView.h"#include "MapViewTypes.h"#include "MinMaxStretchParameters.h"#include "Point.h"#include "RasterTypes.h"#include "SpatialReference.h"#include "StretchRenderer.h"
#include <QFileInfo>#include <QFuture>#include <QList>#include <QStandardPaths>#include <QQmlEngine>
using namespace Esri::ArcGISRuntime;
namespace{ const SpatialReference utm32NSpatialReference(32632);
QString elevationRasterPath() { QString dataPath;#ifdef Q_OS_IOS dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);#else dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);#endif return dataPath + QStringLiteral("/ArcGIS/Runtime/Data/raster/Meribel_32N.tif"); }} // namespace
ControlMapAlgebraInputsWithFloatSuppliers::ControlMapAlgebraInputsWithFloatSuppliers(QObject* parent) : QObject(parent){}
ControlMapAlgebraInputsWithFloatSuppliers::~ControlMapAlgebraInputsWithFloatSuppliers() = default;
void ControlMapAlgebraInputsWithFloatSuppliers::init(){ qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<ControlMapAlgebraInputsWithFloatSuppliers>("Esri.Samples", 1, 0, "ControlMapAlgebraInputsWithFloatSuppliersSample");}
MapQuickView* ControlMapAlgebraInputsWithFloatSuppliers::mapView() const{ return m_mapView;}
void ControlMapAlgebraInputsWithFloatSuppliers::setMapView(MapQuickView* mapView){ if (!mapView || m_mapView) { return; }
m_mapView = mapView; m_map = new Map(utm32NSpatialReference, this); m_mapView->setMap(m_map); loadElevationField(); emit mapViewChanged();}
// 5. Slider changes update the suppliers used by the existing analysis function.void ControlMapAlgebraInputsWithFloatSuppliers::setSlopeRange(float minimum, float maximum){ if (minimum == m_minimumSlope && maximum == m_maximumSlope) { return; }
const float previousMinimum = m_minimumSlope; const float previousMaximum = m_maximumSlope; m_minimumSlope = minimum; m_maximumSlope = maximum; if (m_minimumSlopeSupplier && previousMinimum != minimum) { m_minimumSlopeSupplier->setValue(std::make_optional<float>(minimum)); } if (m_maximumSlopeSupplier && previousMaximum != maximum) { m_maximumSlopeSupplier->setValue(std::make_optional<float>(maximum)); } emit slopeRangeChanged();}
void ControlMapAlgebraInputsWithFloatSuppliers::loadElevationField(){ constexpr int band = 0; const QString path = elevationRasterPath(); if (!QFileInfo::exists(path)) { setErrorMessage(QStringLiteral("Elevation data is missing. Expected file: %1").arg(path)); return; }
// 1. Create a continuous field from the raster, then wrap it in a supplier after loading. ContinuousField::createFromFilesAsync({path}, band, utm32NSpatialReference, this) .then(this, [this](ContinuousField* continuousField) { onContinuousFieldCreated(continuousField); }) .onFailed(this, [this]() { setErrorMessage(QStringLiteral("Failed to load the elevation raster. Verify that Meribel_32N.tif is readable and valid.")); });}
void ControlMapAlgebraInputsWithFloatSuppliers::onContinuousFieldCreated(ContinuousField* continuousField){ if (!continuousField) { setErrorMessage(QStringLiteral("Failed to create a continuous field from the elevation raster.")); return; }
m_elevationFunction = new ContinuousFieldSupplier(continuousField, this); // 2. Derive slope and create suppliers for its minimum and maximum values. m_slopeFunction = m_elevationFunction->slope(); m_minimumSlopeSupplier = new FloatSupplier(std::make_optional<float>(m_minimumSlope), this); m_maximumSlopeSupplier = new FloatSupplier(std::make_optional<float>(m_maximumSlope), this);
// 3. Compare the slope to both suppliers, combine the conditions, and mask the slope field. BooleanFieldFunction* aboveMinimum = m_slopeFunction->isGreaterThanOrEqualTo(m_minimumSlopeSupplier); BooleanFieldFunction* belowMaximum = m_slopeFunction->isLessThanOrEqualTo(m_maximumSlopeSupplier); BooleanFieldFunction* inRange = aboveMinimum->logicalAnd(belowMaximum); ContinuousFieldFunction* selectedSlopes = m_slopeFunction->mask(inRange);
constexpr int colorRampSize = 256; const QList<double> gammaValues{1.0}; constexpr bool estimateStats = false; const QList<double> elevationMinimumValues{1199.0}; const QList<double> elevationMaximumValues{2740.0}; const MinMaxStretchParameters elevationStretchParameters(elevationMinimumValues, elevationMaximumValues); ColorRamp* elevationColorRamp = ColorRamp::create(PresetColorRampType::Surface, colorRampSize, this);
StretchRenderer* elevationRenderer = new StretchRenderer(elevationStretchParameters, gammaValues, estimateStats, elevationColorRamp, this);
const QList<double> slopeMinimumValues{0.0}; const QList<double> slopeMaximumValues{85.0}; const MinMaxStretchParameters slopeStretchParameters(slopeMinimumValues, slopeMaximumValues); ColorRamp* slopeColorRamp = ColorRamp::create(PresetColorRampType::Viridis, colorRampSize, this);
StretchRenderer* slopeRenderer = new StretchRenderer(slopeStretchParameters, gammaValues, estimateStats, slopeColorRamp, this);
// 4. Display the elevation and masked slope functions as analyses in an overlay. m_analysisOverlay = new AnalysisOverlay(this); m_mapView->analysisOverlays()->append(m_analysisOverlay);
FieldAnalysis* elevationAnalysis = FieldAnalysis::create(m_elevationFunction, elevationRenderer, this); if (elevationAnalysis) { elevationAnalysis->setOpacity(0.6F); m_analysisOverlay->analyses()->append(elevationAnalysis); }
m_slopeAnalysis = FieldAnalysis::create(selectedSlopes, slopeRenderer, this);
connect(m_mapView, &MapQuickView::analysisViewStateChanged, this, &ControlMapAlgebraInputsWithFloatSuppliers::onAnalysisViewStateChanged);
m_analysisOverlay->analyses()->append(m_slopeAnalysis); constexpr double initialViewpointScale = 10000.0; m_mapView->setViewpointCenterAsync(continuousField->extent().center(), initialViewpointScale); setErrorMessage(QString());}
void ControlMapAlgebraInputsWithFloatSuppliers::onAnalysisViewStateChanged(Analysis* analysis, const AnalysisViewState& viewState){ if (analysis != m_slopeAnalysis) { return; }
const AnalysisViewStatus status = viewState.status(); switch (status) { case AnalysisViewStatus::Updating: setUpdating(true); break; case AnalysisViewStatus::Error: { setUpdating(false); const Error error = viewState.error(); setErrorMessage(error.additionalMessage().isEmpty() ? error.message() : error.message() + QStringLiteral("\n") + error.additionalMessage()); break; } case AnalysisViewStatus::UpToDate: setUpdating(false); setErrorMessage(QString()); break; }}
void ControlMapAlgebraInputsWithFloatSuppliers::setUpdating(bool updating){ if (m_updating == updating) { return; }
m_updating = updating; emit updatingChanged();}
void ControlMapAlgebraInputsWithFloatSuppliers::setErrorMessage(const QString& errorMessage){ if (m_errorMessage == errorMessage) { return; }
m_errorMessage = errorMessage; emit errorMessageChanged();}// [WriteFile Name=ControlMapAlgebraInputsWithFloatSuppliers, Category=Analysis]// [Legal]// 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.// [Legal]
#ifndef CONTROLMAPALGEBRAINPUTSWITHFLOATSUPPLIERS_H#define CONTROLMAPALGEBRAINPUTSWITHFLOATSUPPLIERS_H
#include <QObject>#include <QString>
namespace Esri::ArcGISRuntime{ class Analysis; class AnalysisOverlay; class AnalysisViewState; class ContinuousField; class ContinuousFieldFunction; class FieldAnalysis; class FloatSupplier; class Map; class MapQuickView;} // namespace Esri::ArcGISRuntime
Q_MOC_INCLUDE("MapQuickView.h")
class ControlMapAlgebraInputsWithFloatSuppliers : public QObject{ Q_OBJECT
Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) Q_PROPERTY(float minimumSlope MEMBER m_minimumSlope NOTIFY slopeRangeChanged) Q_PROPERTY(float maximumSlope MEMBER m_maximumSlope NOTIFY slopeRangeChanged) Q_PROPERTY(bool updating MEMBER m_updating NOTIFY updatingChanged) Q_PROPERTY(QString errorMessage MEMBER m_errorMessage NOTIFY errorMessageChanged)
public: explicit ControlMapAlgebraInputsWithFloatSuppliers(QObject* parent = nullptr); ~ControlMapAlgebraInputsWithFloatSuppliers() override;
static void init();
Esri::ArcGISRuntime::MapQuickView* mapView() const; void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
Q_INVOKABLE void setSlopeRange(float minimum, float maximum);
signals: void mapViewChanged(); void slopeRangeChanged(); void updatingChanged(); void errorMessageChanged();
private: void loadElevationField(); void onContinuousFieldCreated(Esri::ArcGISRuntime::ContinuousField* continuousField); void onAnalysisViewStateChanged(Esri::ArcGISRuntime::Analysis* analysis, const Esri::ArcGISRuntime::AnalysisViewState& viewState); void setUpdating(bool updating); void setErrorMessage(const QString& errorMessage);
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::AnalysisOverlay* m_analysisOverlay = nullptr; Esri::ArcGISRuntime::ContinuousFieldFunction* m_elevationFunction = nullptr; Esri::ArcGISRuntime::ContinuousFieldFunction* m_slopeFunction = nullptr; Esri::ArcGISRuntime::FloatSupplier* m_minimumSlopeSupplier = nullptr; Esri::ArcGISRuntime::FloatSupplier* m_maximumSlopeSupplier = nullptr; Esri::ArcGISRuntime::FieldAnalysis* m_slopeAnalysis = nullptr;
float m_minimumSlope = 0.0; float m_maximumSlope = 10.0; bool m_updating = false; QString m_errorMessage;};
#endif // CONTROLMAPALGEBRAINPUTSWITHFLOATSUPPLIERS_H// [WriteFile Name=ControlMapAlgebraInputsWithFloatSuppliers, Category=Analysis]// [Legal]// 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.// [Legal]
import QtQuickimport QtQuick.Controls.Basicimport QtQuick.Layoutsimport Esri.Samples
Item { readonly property bool compactUi: width < 760
ControlMapAlgebraInputsWithFloatSuppliersSample { id: model }
MapView { id: view anchors.fill: parent objectName: "mapView" focus: true
Button { id: settingsButton anchors { horizontalCenter: parent.horizontalCenter bottom: view.attributionTop bottomMargin: 8 } text: qsTr("Settings") visible: !settingsPanel.visible onClicked: settingsPanel.visible = true } }
Component.onCompleted: model.mapView = view
Rectangle { id: settingsPanel visible: false anchors { left: parent.left right: parent.right bottom: view.bottom leftMargin: compactUi ? 8 : 18 rightMargin: compactUi ? 8 : 18 bottomMargin: compactUi ? 8 : 18 } height: settingsColumn.implicitHeight + panelVerticalPadding * 2 radius: 8 color: palette.base border.color: palette.mid opacity: 0.94 z: 2 clip: true readonly property int panelHorizontalPadding: compactUi ? 10 : 16 readonly property int panelVerticalPadding: compactUi ? 8 : 12
// accept mouse events so they do not propagate down to the map MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: mouse => mouse.accepted = true onWheel: wheel => wheel.accepted = true }
ColumnLayout { id: settingsColumn anchors { fill: parent leftMargin: settingsPanel.panelHorizontalPadding rightMargin: settingsPanel.panelHorizontalPadding topMargin: settingsPanel.panelVerticalPadding bottomMargin: settingsPanel.panelVerticalPadding } spacing: compactUi ? 4 : 6 clip: true
RowLayout { Layout.fillWidth: true
Item { Layout.minimumWidth: 40 Layout.maximumWidth: 40 }
Label { Layout.fillWidth: true Layout.minimumWidth: 0 text: qsTr("Slope range: %1 to %2 degrees").arg(model.minimumSlope).arg(model.maximumSlope) color: palette.text horizontalAlignment: Text.AlignHCenter elide: Text.ElideRight }
ToolButton { Layout.minimumWidth: 40 Layout.maximumWidth: 40 Layout.preferredHeight: 40 text: "X" background.opacity: 1 Accessible.name: qsTr("Close settings") ToolTip.visible: hovered ToolTip.text: qsTr("Close settings") onClicked: settingsPanel.visible = false } }
RangeSlider { id: slopeRange Layout.fillWidth: true Layout.minimumWidth: 0 from: 0 to: 85 stepSize: 1 first.value: model.minimumSlope second.value: model.maximumSlope
SystemPalette { id: systemPalette }
palette.window: systemPalette.button palette.light: systemPalette.light palette.mid: systemPalette.buttonText
first.onMoved: model.setSlopeRange(Math.round(first.value), Math.round(second.value)) second.onMoved: model.setSlopeRange(Math.round(first.value), Math.round(second.value))
background: Rectangle { x: slopeRange.leftPadding y: slopeRange.topPadding + (slopeRange.availableHeight / 2) - (height / 2) width: slopeRange.availableWidth height: 8 radius: 4 gradient: Gradient { orientation: Gradient.Horizontal GradientStop { position: 0.0 color: "#440154" } GradientStop { position: 0.2 color: "#414487" } GradientStop { position: 0.4 color: "#2A788E" } GradientStop { position: 0.6 color: "#22A884" } GradientStop { position: 0.8 color: "#7AD151" } GradientStop { position: 1.0 color: "#FDE725" } } } }
Item { id: rangeFooter Layout.fillWidth: true implicitHeight: Math.max(flattestLabel.implicitHeight, updatingStatus.implicitHeight, steepestLabel.implicitHeight)
Label { id: flattestLabel anchors { left: parent.left verticalCenter: parent.verticalCenter } width: parent.width * 0.25 text: qsTr("Flattest") color: palette.text elide: Text.ElideRight }
Item { id: updatingStatus anchors { left: parent.left right: parent.right leftMargin: parent.width * 0.25 rightMargin: parent.width * 0.25 verticalCenter: parent.verticalCenter } height: implicitHeight implicitHeight: Math.max(updatingIndicator.implicitHeight, updatingLabel.implicitHeight) visible: model.updating
Label { id: updatingLabel anchors.centerIn: parent width: Math.max(0, parent.width - (updatingIndicator.visible ? 2 * (updatingIndicator.width + 4) : 0)) text: qsTr("Analysis updating") color: palette.text elide: Text.ElideRight horizontalAlignment: Text.AlignHCenter }
BusyIndicator { id: updatingIndicator anchors { right: updatingLabel.left rightMargin: 4 verticalCenter: parent.verticalCenter } visible: parent.width >= updatingLabel.implicitWidth + 2 * (width + 4) running: model.updating implicitWidth: 22 implicitHeight: 22 } }
Label { id: steepestLabel anchors { right: parent.right verticalCenter: parent.verticalCenter } width: parent.width * 0.25 text: qsTr("Steepest") color: palette.text elide: Text.ElideRight horizontalAlignment: Text.AlignRight } }
Label { visible: model.errorMessage.length > 0 text: model.errorMessage color: palette.text wrapMode: Text.WordWrap Layout.fillWidth: true Layout.minimumWidth: 0 } } }}