Skip to content

Working with temporal data

damylen edited this page Mar 5, 2015 · 1 revision

Introduction

We also wanted to support temporal data in Common Sense. Often we get datasets where the properties of our features are changing over time, e.g. the statistics of our cities or moving cars. In Common Sense temporal data is called ‘sensor data’, though it is definitely not limited to the traditional sensor data (temperature, etc.) To support sensor data we extended our geojson format a little bit to store the data and a timeline was introduced to interactively move through time.

Temporal support in GeoJSON

Properties can have a date like type e.g. creation time of a specific feature. The focus however of this article is on how to describe properties or geometries that can change over time. The extended version of GeoJSON to support this introduces a concept called ‘timestamps’. Timestamps is an array of moments (defined as an epoch millisecond number). They can be defined at the root level when they are the same for each feature (e.g. statics), or on a feature level when they different for each feature (e.g. temperature sensor).

The following example demonstrates how to use the timestamps on the root level:

{ "type": "FeatureCollection", "timestamps": [31536000000,63072000000,94694400000,126230400000], "features": [ { "type": "Feature", "geometry": { "type": "Point", "coordinates": [120.9924,31.77254]}, "sensors": { "Income": [100,110,120,130] }, } ] }

This example includes 4 timestamps starting from 01 Jan 1971 00:00:00 (31536000000ms after 1971). There is one feature with a sensor called ‘Income’. Income is an array of sensor data with the values for each of the timestamps. When the focus time changes (more on that later) CS will look up the latest value and set this value in a property with the same name as the sensor. This allows you to use property types, filtering and styling the same way as you would with normal properties.

If you want to use feature specific timestamps, the structure would be:

{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [120.9924,31.77254]}, "timestamps": [31536000000,63072000000,94694400000,126230400000], "sensors": { "Income": [100,110,120,130] }, }

Project time support

Before we introduce the timeline component let us first describe how Common Sense handles time in general. Each project contains a timeLine definition that includes the focus, start and end time. The focus time is used to select the sensor data. The start and end time are used to set the range of the timeline.

The easiest way to listen to focus time updates is to listen to the messagebus service:

this.$messageBusService.subscribe('timeline', function (trigger) { switch (trigger) { case 'focusChange': .... break; } });

Timeline component

Common Sense supports an interactive timeline component from the chap-links-library (github link). To easily integrate it in your CS website, we created an angular directive which is part of the csComp.js library. You need to add the module ‘csWeb.timeline’ to your angular.module and add the timeline in your main html page using the following statement: