Andreas Hopfgartner
3 min readSep 10, 2018

How to bring IoT sensor data on a map

When you work with sensor data, you’ll get to the point to plot information derived from your sensors on a map. This might be just to plot the positions of devices to track your assets or bring even more sophisticated statistics on a map.

For most of the GIS projects I did, no matter how complicated they were, I had two different scenarios.

Scenario A: Learn from historic data. Here I needed to process or aggregate my sensor data in some way and bring the results to a map (like heatmaps, lineplots, positions with popup labels, …). In most cases it helps to plot the data on a map in order to recognize position-dependent correlations.

Scenario B: Production-like live (I intentionally avoid the term real-time here…) sensor information for asset tracking. Here I needed the position of the device and some extra information in a popup box.

The more complicated the end devices that are equipped with sensors are, the more you need to consult (a) the engineers who design these devices and (b) product owners or business people that develop business-relevant use cases. The most effective way is to provide them with graphical analyses, starting from the perspective of a minimal viable product, so that they can develop their own ideas. Then you can start to iterate and improve your sensor map application.

For all IoT analytics projects I used Python for data preprocessing and evaluation, mainly because there are useful packages for processing geodata, like shapely, pyproj and geopandas.

Because these kinds of projects have a proof-of-concept character, I usually use a Jupyter notebook environment before proper Python code goes into production. There are several Python packages and map tools to bring data on a map (ipyleaflet, folium, gmaps, …). However, all of them are more like a wrapper to the underlying map tool than a proper API. This means that your data is processed within Python and then sent to the map tool, packed with a configuration script. This prevents you from displaying live data on a map, as not only is your data updated with every time step on the map, but the map itself is also reloaded, which is very annoying when you try to follow some sensor information live.

The only environment that meets all my requirements (which, in my opinion, are not particularly excessive) is Mapbox. There is a Python package mapbox-gl, which is still under early development, but for me this is kind of the most native map environment. The best way is to process the data with Python, export it to a GeoJSON at the end of the processing chain and write the Mapbox code directly into JavaScript (which can be directly interpreted by a Jupyter notebook using from IPython.display import HTML). Using the mapbox-gl Python package to produce colorful plots and then reading the resulting html/JavaScript code helped me a lot to understand writing color-scaling functions, e.g.

To come back to the people that play with the map to generate business relevance: don’t let them waste their precious time executing code cells or bug-fixing. There are too many things that can go wrong. Build a data preprocessing pipeline and a minimal webserver (Python has one in package http.server) that brings this data on the map.

I think leaflet.js can be used in the same way. The most beautiful thing about Mapbox for enterprise applications is, that it is customizable in so many ways. If you use plain Mapbox, you get license and pricing information here. But it’s also possible to use the Mapbox framework for free by using OpenStreetMap maps. Also here, styling, tile servers, sprites and many other elements are customizable to build maps in corporate design. This is interesting for large municipal utilities, transportation companies, railway networks, after-sales in automotive companies that provide their customers with data and many more to provide their customers with maps that they can identify with the company behind.

Andreas Hopfgartner

Working as Cloud Solution Architect for Data & AI and also in the realm of Internet of Things for Microsoft in Germany.