Using Cesium for 3D Thematic Visualisations on the Web

: Cesium (http://cesiumjs.org) is an open source, WebGL-based JavaScript library for virtual globes and 3D maps. It is an excellent tool for 3D thematic visualisations, but to use its full functionality it has to be feed with its own file format, CZML. Unfortunately, this format is not yet supported by any major GIS software. This paper introduces a plugin for QGIS, developed by the author, which facilitates the creation of CZML file for various types of visualisations. The usability of Cesium is also examined in various hardware/software environments.


Introduction
Visualising data in three dimensions on a virtual globe is a popular field of thematic cartography. Since the release of Google Earth, creating KML overlays became one of the most common ways of publishing such content (Sandvik 2008). For many years, the Google Earth plugin provided a simple way to put these KML-based visualisations to the web. Unfortunately, the technology of the plug-in became obsolete and finally by the end of 2016, Google stopped this service (Google 2016). With the emerging new technologies, WebGL and HTML5, several JavaScript-based virtual globe libraries, APIs (Application Programming Interfaces) were developed to facilitate displaying 3D interactive globe models on web pages without the use of any plugins. Such a library is OpenWebGlobe, created by Swiss researchers (Christen, Nebiker, Loesch 2012) or WebGL Earth JavaScript API, which originally was a bachelor thesis (Sloup 2011) and is currently maintained by Klokan Technologies. Although these two products are also useful in some cases, due to their limitations (discussed e.g. in Gede 2015a) it is advisable to use another library, the Cesium API (Cozzi 2013). Cesium offers much wider functionality, rich documentation and a very active developer community ensuring that most questions are answered quickly in developer forums. As for the thematic content of the globe, the possibilities of 3D visualisation are virtually unlimited -there are much more possible visual variables than in the case of 2D maps. This does not mean, however, that one should overwhelm the globe with data -placing too many objects to the globe or using too many visual variables simultaneously may result in information loss (Gede 2015b). In daily practice, however, most thematic globes use only one of the three most common visualization methods: choropleths, 3D prism maps and graduated 3D symbols. Using Cesium, only a few lines of JavaScript code is required to embed an interactive virtual globe into an HTML page. This is described in detail in the Cesium API documentation (Analytical Graphics 2016), especially in its tutorial section. Once having a virtual globe on our website, various types of thematic visualizations can be added to this globe several ways, depending on the data type/format.

Raster overlays
In a number of cases it is enough to drape a raster overlay to the globe. Raster overlays can be added as a single image (which is the advisable solution for smaller resolution images) or as tiled image sets, either through a TMS service or in a KMZ file. Using this solution we can use all the traditional cartographic visualization methods (e. g. point density, choropleths, isolines) but it is important to take the distortions into account while editing the map: the raster overlay have to be in equirectangular projection, therefore distances in east-west direction will be reduced significantly on higher latitudes. The compilation of equirectangular maps suitable for use on virtual globes is explained in details in (Hargitai, Gede 2009 and Gede 2015b).

Vector data
Vector data can be added to Cesium as KML/KMZ or CZML files, or (if there are only a handful of features to be added) by creating the 3D entities directly from JavaScript. KML (or KMZ) is the native format of Google Earth (Google 2017). These files can be added with a few lines of code. This is particularly useful when the thematic content in KMZ format had already been prepared for some other purpose and we would like to use the same material on Cesium. As KML is widely supported by most GIS applications, it is very easy to produce data in this format. When using KML/KMZ, one should keep in mind that not all features of KML is supported by Cesium. Basic geometry types have full support, as well as ground overlays, but for example context-sensitive styles or zoom-dependent visualization using Regions and LODs has not been implemented yet. The most widely usable format is Cesium Language (CZML). Similarly to KML/KMZ, adding CZML files to the globe is also very simple. The disadvantage of CZML is that it is not yet supported by any of the popular GIS software, but with a bit of programming skills these files can be easily produced. KML and CZML data can be added from remote URLs as well, provided the remote server supports cross-origin resource sharing (CORS) (W3C 2014).

Special features of CZML
Probably the most often used 3D thematic visualisation method is the 3D prism map -a choropleth map with its coloured polygons extruded above the surface. An advantage of CZML (compared to KML) that it is possible to set extruded polygons to follow the globe curvature instead of having flat surface, which is an important feature when displaying prism maps (Fig. 1)   Fig. 1. While raised polygons may cut into the surface in Google Earth (left), they follow the curvature of the sphere in Cesium (right).
Maybe the most important feature of CZML is that any numeric value can be interpolated through time. When displaying such data, the time-dependant value (e. g. the colour, height, position of elements) changes with time (Cesium provides a "time slider" for setting time).

A QGIS plug-in for creating CZML content
Unfortunately, most GIS software products do not support data export in CZML format. To help this situation, the author developed a QGIS plugin (available for download at https://github.com/samanbey/czml_generator), which facilitates the creation of (at the time of writing this paper) four different visualisation types in CZML. After copying the plugin to the Python plugin folder of QGIS, it can be added to the program in Plugin Manager, and will appear in the Plugins/CZML Generator menu.

3D Prism maps
Using the "Prism Map" menu item we can create 3D prisms (elevated choropleth) from any polygon layer. In the dialog box (Fig. 2) we can select the layer and the attribute field, as well as the colours for the lowest and the highest value of the chosen attribute (the values in between get interpolated colours). The prism heights can be linear, square root or logarithmic function of the attribute; a vertical exaggeration factor can also be defined. The plugin can also create an HTML format legend if the appropriate checkbox is set. The legend settings appear in an additional dialog box.
The resulting CZML file can be opened using the sample HTML viewer accompanying the plugin (located in the folder sampleViewer), after changing the CZML (and the legend, if created) file name in the code at the appropriate places (marked by comments). The map, created from the sample data also attached to the plugin can be seen on Fig. 3. When having time series data, one can also use the function "Prism Map with time". Its dialog box is similar to the previous one except that more than one attribute of the selected vector layer can be used. A timestamp has to be chosen for each attribute. When visualizing time series data, we have to set the animation and the timeLine options to true at the Cesium.Viewer constructor. These settings make the time slider and the other necessary controls visible in the viewer (Fig. 4).

Scaled models
The function "Scaled models with time" creates a CZML file containing 3D models with sizes corresponding the selected attribute value (Fig. 5). Settings are similar to the previous function but here also the URL of a 3D model has to be given. It is advisable to use a relative URL. A sample model (cow.glb) can be found in the folder sampleViewer. If multiple timestamps are given, the size of the models will change in time, reflecting the temporal change of the visualized data.

Connector lines
The plugin also supports creating raised connector lines. This type of visualisation can be useful when the goal is to emphasize connections between points, e. g. the flight network of an airline. This function requires a vector layer with lines or polylines as source. An example can be seen on Fig. 6.

Conclusions, furher plans
The open source virtual globe API, Cesium is a great tool to publish thematic data on 3D globes on the web. This paper introduces a QGIS plug-in (CZML Generator) developed by the author that facilitates creating this type of visualisations. The plug-in supports various methods: prism maps, scaled 3D models and raised connector lines. It is also capable of creating temporal animations. The CZML Generator plug-in is still under development; the author's aim to add several new functions, covering many fields of 3D thematic visualization.