Spatio-temporal Event Processing with StreamInsight, SQL Server Denali, and Bing Maps – Part 5

Yesterday, fellow Bing Maps MVP Nicolas Boonaert (blog) kindly tweeted a link to my series of posts about analysing spatio-temporal data using StreamInsight and Bing Maps. In addition to the generous words he said publicly, he also sent me a private message teasing me about the graphical presentation of the data. I believe the term he used was “moving pixelised potato on a map”… Winking smile

Spurred on by Nicolas’ comments, I thought I’d take the opportunity to improve the visual impact of my StreamInsight output by making use of my own HeatMap library to plot the outbreak as a heatmap rather than as a convex hull. To do so required remarkably few changes to the code:

First, instead of creating a (Polygonal) convex hull around all the events in the Stream Insight window at a  given point in time, I added a UDA that would instead create a (MultiPoint) union of all those points.

public class MultiPointUnion : CepAggregate<string, string>
    public override string GenerateOutput(IEnumerable<string> eventData)
      var gb = new SqlGeographyBuilder();
      foreach (var d in eventData)
        SqlGeography point = SqlGeography.Parse(d);
        gb.BeginFigure((double)point.Lat, (double)point.Long);

      return gb.ConstructedGeography();

Then, I amended the javascript that updated the map in the browser control. Instead of plotting a single polygon as a vector shape on the map, I imported the heatmap library and added a new HeatMapLayer as follows:

heatmapLayer = new HeatMapLayer(
  new Array(),
  { intensity: 0.4,
    radius: 25,
    colourgradient: {
      0.0: 'rgba(255, 255, 255, 0)',
      0.5: 'rgba(255, 255, 120, 100)',
      0.8: 'yellow',
      0.95: 'red',
      1.0: 'white'

(Colours were chosen somewhat arbitrarily – white hot spot right at the centre of each point, followed by red, and gradually diminishing yellow). Then, each time the WCF listener received a new event summary from StreamInsight, rather than plot it as a Microsoft.Maps.Polygon, it called a method that would split the WKT of the MultiPoint instance into an array of Microsoft.Maps.Locations, and supply these to the heatmap layer:


The result is shown in the video below, complete with my rather vague commentary (based on this evidence, I don’t think I’ll ever realise my childhood dreams of being a radio DJ… ). One thing to notice is that, while the convex hull approach I used before emphasises the overall geographic spread at any point in time, the heat map approach emphasises instead the intensity of events in certain areas.

This entry was posted in Bing Maps, Spatial, SQL Server and tagged , , , . Bookmark the permalink.

3 Responses to Spatio-temporal Event Processing with StreamInsight, SQL Server Denali, and Bing Maps – Part 5

  1. Sasha dos Santos says:


  2. Manuel Meyer says:

    Hey Alastair. I am currently investigating Microsoft StreamInsight for an internal presenation for the company I work for It is titled: CEP on Windows Azure. Your H5N1 application is stunning. Is there any chance I could get some source or executables to show it to the audience as a real world Streaminsight use case? That would be very impressive since it goes far beyond aggregating data and writing to the console…
    Many thanks for an answer and best regards…Manuel

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s