Visualize and compare data over time

Several layers, including FeatureLayer and ArcGISMapImageLayer are time-aware, meaning they can use time-based rendering and filtering if it's enabled on the data source at the time of publishing. The SDK provides several ways to work with time:

  • Filter data with a time extent applied to the geo view
  • Apply a time offset to the data in a layer (useful for comparing data over time)
  • Control which eligible layers participate in time filtering
  • Add time-based parameters to queries

Filter data by time

You can filter data in time-aware layers by defining a time extent and applying it to the map or scene view. All time-aware layers in the map (or scene) displayed by the view will filter their data per the view's time extent (except when time filtering is not supported or is disabled).

To filter data by time, first create a time extent that captures the desired time range. For example, to include only data for the last 60 days, create two DateTimeOffset Dates, one for now and one for now minus 60 days:

DateTimeOffset now = DateTime.Now;
DateTimeOffset sixtyDaysAgo = DateTime.Now - new TimeSpan(60,0,0,0);
TimeExtent extent = new TimeExtent(sixtyDaysAgo, now);
The start time must be less than the end time - otherwise, an exception will be thrown.

Next, apply the time extent to the view.

MyMapView.TimeExtent = extent;

After applying the time extent to the view, all applicable layers in the map or scene contained by the view will only show data from the specified time extent. This includes layers that:

  • Support time filtering
  • Are connected to time-enabled data sources
  • Have not had time filtering disabled

You can explicitly exclude layers from participating in time filtering.

myLayer.IsTimeFilteringEnabled = false;

You can also detect if an otherwise time-aware layer is incapable of working with time (e.g. because it is connected to a data source without time values).

if (myLayer.SupportsTimeFiltering) 
    ... // Time-dependent work

Comparing two time periods

Because the time extent is defined for a geo view (map view or scene view), it is applied uniformly to all of the view's layers. Using a time offset, you can add (or subtract) a given amount of time from the filter defined by the geo view. The TimeOffset property of time-aware layers is useful for offsetting the filter applied to participating layers. For example, you can use a one-year offset to visualize year-to-year changes in a layer's data.

To visually compare data over time, first create two layers from the same service.

Uri mapServerUri = new Uri("...");
ArcGISMapImageLayer baseImageryLayer = new ArcGISMapImageLayer(mapServerUri);
ArcGISMapImageLayer offsetImageryLayer = new ArcGISMapImageLayer(mapServerUri);

Next, apply a time offset to one layer.

offsetImageryLayer.TimeOffset = new TimeValue(1, TimeUnit.Years);

Add the layers to a map and the map to a map view.

Map myMap = new Map(Basemap.CreateTopographic());
MyMapView.Map = myMap;

Set a time extent on the map view to filter the data.

MyMapView.TimeExtent = new TimeExtent(start, end);

Compare layers with and without time filtering

You can set the IsTimeFilteringEnabled property on a layer to prevent it from filtering its content based on the time extent defined on the geo view. To show both filtered and unfiltered data, first add two layers to the map.

Uri firstUri = new Uri("...");
Uri otherUri = new Uri("...");
FeatureLayer timeFilteredLayer = new FeatureLayer(firstUri);
FeatureLayer unfilteredLayer = new FeatureLayer(otherUri);

Next, exclude the unfiltered layer from time filtering.

unfilteredLayer.IsTimeFilteringEnabled = false;

Add the layers to a map and the map to a map view.

Map myMap = new Map(Basemap.CreateTopographic());
MyMapView.Map = myMap;

Set the time extent on the map view to filter the data.

MyMapView.TimeExtent = new TimeExtent(startTime, endTime);