Visualize changes in rasters over time by filtering a mosaic dataset raster for a selected timestamp.

Use case
A mosaic dataset can contain rasters collected over the same area at different times. Viewing the imagery one timestamp at a time makes it easier to compare how a place has changed, such as when tracking urban development, changes in vegetation, or the effects of a natural event.
How to use the sample
When the sample starts, the mosaic dataset raster is displayed in a map view and the available acquisition timestamps are loaded. Use the previous and next controls to step through the distinct timestamps in chronological order. The currently selected timestamp is shown, and the map view updates to display imagery for that time. Use the slider to adjust the opacity of the raster layer to compare it to the imagery basemap.
How it works
- Create a
Mapand display it in aMapView. - Create and load a
MosaicDatasetRasterfrom the sample mobile mosaic dataset and use it to create a raster layer. - Add the raster layer to the map.
- Get the raster’s distinct timestamps using
MosaicDatasetRaster::distinctTimestampsAsync(). - Create a
TimeExtentwith a time instant of the initial timestamp and set it on the map view usingMapView::setTimeExtent(). - Update the time extent on the map view when the selected timestamp changes.
Relevant API
- Map
- MapView
- MosaicDatasetRaster
- RasterLayer
- TimeAware
Offline data
Read more about how to set up the sample’s offline data here.
| Link | Local Location |
|---|---|
| ElToroMosaicDataset | <userhome>/ArcGIS/Runtime/Data/raster/ElToroMosaicDataset/el_toro.geodatabase |
About the data
The sample uses a mobile mosaic dataset ElToroMosaicDataset containing imagery rasters for one local area across multiple acquisition timestamps.
Tags
aerial imagery, date, mosaic dataset, raster, time, time extent, time-aware, time-enabled, timestamp
Sample code
// [WriteFile Name=FilterMosaicDatasetRasterByTimeExtent, Category=DisplayInformation]// [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
// sample headers#include "FilterMosaicDatasetRasterByTimeExtent.h"
// ArcGIS Maps SDK headers#include "Envelope.h"#include "Error.h"#include "LayerListModel.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "MosaicDatasetRaster.h"#include "RasterLayer.h"#include "TimeExtent.h"
// Qt headers#include <QDebug>#include <QFuture>#include <QStandardPaths>
using namespace Esri::ArcGISRuntime;
// helper method to get cross platform data pathstatic QString defaultDataPath(){ QString dataPath;
#ifdef Q_OS_IOS dataPath = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);#else dataPath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);#endif
return dataPath;}
FilterMosaicDatasetRasterByTimeExtent::FilterMosaicDatasetRasterByTimeExtent(QObject* parent /* = nullptr */) : QObject(parent), m_map(new Map(BasemapStyle::ArcGISImageryStandard, this)), m_mosaicDatasetRaster( new MosaicDatasetRaster(defaultDataPath() + "/ArcGIS/Runtime/Data/raster/ElToroMosaicDataset/el_toro.geodatabase", "el_toro", this)), m_rasterLayer(new RasterLayer(m_mosaicDatasetRaster, this)){ // Create a mosaic dataset raster from the mobile mosaic dataset and display it in a raster layer m_map->operationalLayers()->append(m_rasterLayer);}
FilterMosaicDatasetRasterByTimeExtent::~FilterMosaicDatasetRasterByTimeExtent() = default;
void FilterMosaicDatasetRasterByTimeExtent::init(){ // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<FilterMosaicDatasetRasterByTimeExtent>("Esri.Samples", 1, 0, "FilterMosaicDatasetRasterByTimeExtentSample");}
MapQuickView* FilterMosaicDatasetRasterByTimeExtent::mapView() const{ return m_mapView;}
// Set the view (created in QML)void FilterMosaicDatasetRasterByTimeExtent::setMapView(MapQuickView* mapView){ if (!mapView || mapView == m_mapView) { return; }
m_mapView = mapView;
// Once the raster layer has loaded, zoom to it and get the distinct timestamps of the raster connect(m_rasterLayer, &RasterLayer::doneLoading, this, [this](const Error& error) { if (!error.isEmpty()) { failLoading(); return; }
m_mapView->setViewpointGeometryAsync(m_rasterLayer->fullExtent(), 100);
m_mosaicDatasetRaster->distinctTimestampsAsync() .then(this, [this](const QList<QDateTime>& timestamps) { m_timestamps = timestamps; emit timestampsChanged();
// Display the imagery for the initial timestamp setCurrentIndex(0); finishLoading(); }) .onFailed(this, [this] { failLoading(); }) .onCanceled(this, [this] { failLoading(); }); });
m_mapView->setMap(m_map);
emit mapViewChanged();}
int FilterMosaicDatasetRasterByTimeExtent::currentIndex() const{ return m_currentIndex;}
void FilterMosaicDatasetRasterByTimeExtent::finishLoading(){ m_loading = false; emit loadingChanged();}
void FilterMosaicDatasetRasterByTimeExtent::failLoading(){ m_loadError = tr("Load error"); qWarning().noquote() << QStringLiteral("Unable to load offline imagery or its timestamps. Download and extract ElToroMosaicDataset to %1, " "ensure el_toro.geodatabase is readable, then reopen the sample.") .arg(defaultDataPath() + "/ArcGIS/Runtime/Data/raster/ElToroMosaicDataset"); finishLoading();}
void FilterMosaicDatasetRasterByTimeExtent::setCurrentIndex(int index){ if (index < 0 || index >= m_timestamps.size() || index == m_currentIndex) { return; }
m_currentIndex = index;
// Filter the raster to the selected timestamp by setting a time extent on the map view m_mapView->setTimeExtent(TimeExtent(m_timestamps.at(m_currentIndex)));
emit currentIndexChanged();}
int FilterMosaicDatasetRasterByTimeExtent::timestampCount() const{ return m_timestamps.size();}
QString FilterMosaicDatasetRasterByTimeExtent::currentTimestamp() const{ if (m_currentIndex < 0) { return {}; }
return m_timestamps.at(m_currentIndex).toUTC().toString("MM/dd/yyyy");}
void FilterMosaicDatasetRasterByTimeExtent::setRasterOpacity(double opacity){ m_rasterLayer->setOpacity(static_cast<float>(opacity));}// [WriteFile Name=FilterMosaicDatasetRasterByTimeExtent, Category=DisplayInformation]// [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 FILTERMOSAICDATASETRASTERBYTIMEEXTENT_H#define FILTERMOSAICDATASETRASTERBYTIMEEXTENT_H
// Qt headers#include <QDateTime>#include <QList>#include <QObject>
namespace Esri::ArcGISRuntime{ class Map; class MapQuickView; class MosaicDatasetRaster; class RasterLayer;} // namespace Esri::ArcGISRuntime
Q_MOC_INCLUDE("MapQuickView.h")
class FilterMosaicDatasetRasterByTimeExtent : public QObject{ Q_OBJECT
Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(int timestampCount READ timestampCount NOTIFY timestampsChanged) Q_PROPERTY(QString currentTimestamp READ currentTimestamp NOTIFY currentIndexChanged) Q_PROPERTY(bool loading MEMBER m_loading NOTIFY loadingChanged) Q_PROPERTY(QString loadError MEMBER m_loadError NOTIFY loadingChanged)
public: explicit FilterMosaicDatasetRasterByTimeExtent(QObject* parent = nullptr); ~FilterMosaicDatasetRasterByTimeExtent() override;
static void init();
Q_INVOKABLE void setRasterOpacity(double opacity);
signals: void mapViewChanged(); void currentIndexChanged(); void timestampsChanged(); void loadingChanged();
private: Esri::ArcGISRuntime::MapQuickView* mapView() const; void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
int currentIndex() const; void setCurrentIndex(int index); int timestampCount() const; QString currentTimestamp() const;
void finishLoading(); void failLoading();
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::MosaicDatasetRaster* m_mosaicDatasetRaster = nullptr; Esri::ArcGISRuntime::RasterLayer* m_rasterLayer = nullptr; QList<QDateTime> m_timestamps; int m_currentIndex = -1; bool m_loading = true; QString m_loadError;};
#endif // FILTERMOSAICDATASETRASTERBYTIMEEXTENT_H// [WriteFile Name=FilterMosaicDatasetRasterByTimeExtent, Category=DisplayInformation]// [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.Controlsimport Esri.Samples
Item { MapView { id: view anchors.fill: parent
Component.onCompleted: { // Set and keep the focus on MapView to enable keyboard navigation forceActiveFocus(); }
// Date stepper and opacity controls Pane { anchors { horizontalCenter: parent.horizontalCenter bottom: view.attributionTop bottomMargin: 10 } padding: 8 background: Rectangle { radius: 5 color: palette.base border { width: 1 color: "darkgrey" } }
Column { spacing: 5
Row { anchors.horizontalCenter: parent.horizontalCenter
ToolButton { icon.source: "qrc:/Samples/DisplayInformation/FilterMosaicDatasetRasterByTimeExtent/chevron-start-24.svg" enabled: model.currentIndex > 0 ToolTip.visible: hovered ToolTip.text: qsTr("First") onClicked: model.currentIndex = 0 }
ToolButton { icon.source: "qrc:/Samples/DisplayInformation/FilterMosaicDatasetRasterByTimeExtent/chevron-left-24.svg" enabled: model.currentIndex > 0 ToolTip.visible: hovered ToolTip.text: qsTr("Previous") onClicked: model.currentIndex = model.currentIndex - 1 }
Label { anchors.verticalCenter: parent.verticalCenter width: 100 horizontalAlignment: Text.AlignHCenter wrapMode: Text.Wrap text: model.loading ? qsTr("Loading...") : model.loadError.length > 0 ? qsTr("Offline data error") : model.timestampCount > 0 ? model.currentTimestamp : qsTr("No timestamps") }
ToolButton { icon.source: "qrc:/Samples/DisplayInformation/FilterMosaicDatasetRasterByTimeExtent/chevron-right-24.svg" enabled: model.currentIndex < model.timestampCount - 1 ToolTip.visible: hovered ToolTip.text: qsTr("Next") onClicked: model.currentIndex = model.currentIndex + 1 }
ToolButton { icon.source: "qrc:/Samples/DisplayInformation/FilterMosaicDatasetRasterByTimeExtent/chevron-end-24.svg" enabled: model.currentIndex < model.timestampCount - 1 ToolTip.visible: hovered ToolTip.text: qsTr("Last") onClicked: model.currentIndex = model.timestampCount - 1 } }
Item { anchors.horizontalCenter: parent.horizontalCenter width: opacitySlider.width height: opacityLabel.height
Label { id: opacityLabel text: qsTr("Opacity") }
Label { anchors.right: parent.right text: qsTr("%1%").arg(Math.round(opacitySlider.value * 100)) } }
Slider { id: opacitySlider anchors.horizontalCenter: parent.horizontalCenter width: 280 enabled: !model.loading && model.loadError.length === 0 && model.timestampCount > 0 from: 0 to: 1 stepSize: 0.01 value: 1 onValueChanged: model.setRasterOpacity(value) }
Label { anchors.horizontalCenter: parent.horizontalCenter width: opacitySlider.width visible: model.loadError.length > 0 text: model.loadError textFormat: Text.PlainText wrapMode: Text.Wrap Accessible.name: text } } } }
// Declare the C++ instance which creates the map etc. and supply the view FilterMosaicDatasetRasterByTimeExtentSample { id: model mapView: view }}