HOW TO: produce heatmaps, custom heatmaps on any data

×

Warning message

You can't delete this newsletter because it has not been sent to all its subscribers.

The heatmaps can be produced on the basis of any kind of geolocated data. The main needs are:

  • The presence of a number of measured values (for example a set of sensors providing Temperature values located in a given area, may be more than 5 sensors, and the area is identified by GSP coordinates, Min/Max latitude, Min/Max Longitudes. They have to be identified by a Service URI with a Knowledge Base.
  • The identification of a ColorMap among those reported at the end of  this document, for esample: minTemperature. If a suitable colormap is not available you can create a new one by using the ColorMap manager in the resource management tool. You have to be at role of ToolAdmin or RootAdmin or on premise to create a new color map. In alternative please ask to the coordinator snap4city@disit.org to create your preferred ColorMap. ColorMaps can have a large number of color shades and thus many levels as you need.
  • EPSGProjection depends on the location in which you have to estimate the heatmaphttp://www.epsg-registry.org/, there are also databases for getting those codes. In alternative you can ask to us for providing the code according to your geo location area.
  • ValueType: a single code or vector of possible names for the sensors attributes such as:
    • “valueType” = ["NO2","NO_2","airQualityNO2","airqualityNO2"]

 

example of JSON that has to be passed at the DataAnalytic heatmap as list of parameters. The RStudio is taking the data from the KB using the Smart City API, and it ica capable to produce the results, the heatmap, directly saving the data of the heatmap into the HeatMap Server directly. The generation of the tiles for the images is performed automatically on our snap4city servers.

 

The RStudio to be used can be obtained from https://www.snap4city.org/drupal/sites/default/files/files/Automatic_IDW_Heatmaps_Creation-final-2.txt

We suggest to rename the file TXT into .R before using on the  IOT Node as described below.

see also TC1.19: Creating and Exploit heatmaps for Dashboards and as reference data services

 

example of parameters passed to the Rstudio file on IOT App block/nodes as described in the following. 

 

Msg.payload = {

   "city":"Florence",
   "long_min":11.1401,
   "long_max":11.3475,
   "lat_min":43.7195,
   "lat_max":43.8345,
   "epsgProjection":32632,
   "valueType":"airTemperature",
   "subnature":"Weather_sensor",
   "heatmapName":"Florence_AirTemperature",
   "fromDateTime":"3-hour",
   "colorMap":"airTemperature",

   "toDateTime": "2020-06-27T23:00:00"

}

The Generic Heatmap is created by using “Plumber-Data-analytic” nodes of the Snapt4City advanced developer library 

Configured as follows, and thus passing the Rstudio program as accessible from this web page.

This means that once loaded the RStudio programme you have to “create the plumber data analytic”. This process will created a docker with the data analytic transformed in a microservice for computing automatically allocated on the elastic cluster of snap4city 😊

The “Plumber-Data-analytic” block return specific errors if the settings are not suitable and/or if the process for heatmap computing is already running.

The produced Heatmaps can be animated if more than one instance per day is produced. The heatmap can be very large and high resolution, the distribution of the maps towards dashboards and Mobile App is very efficient since it is performed by using a geoserver according to WMS protocol.

Automatic_IDW_Heatmaps_Creation.R

#' @get /heatmapIDW
#' @serializer unboxedJSON

heatmapIDW <- function (city, long_min, long_max, lat_min, lat_max, epsgProjection, subnature, valueType, fromDateTime, toDateTime, heatmapName, colorMap) {

...

}

(Api from superservicemap)

PARAMETERS EXPLANATION

  • city = name of the city related to the heatmap bbox (e.g., Rome, Florence, Helsinki, Antwerp etc.)
  • long_min, long_max, lat_min, lat_max = heatmap bbox parameters (latitude and longitude coordinates)
  • epsgProjection = UTM Projection related to the heatmap zone
  • subnature = subnature of the sensor of interest (e.g., airQuality)
  • valueType = single parameter or parameters array with the names of the measure of interest (the case of the array is related to multiple names for a single measure and NOT to multiple different measures - e.g, NO2, no2, airQualityNO2 etc.)
  • fromDateTime = start date and time interval in timestamp format
  • fromDateTime = end date and time interval (for example 1-hour or 1-day or the timestamp format 2020-05-25T15:00:00)
  • heatmapName = name of the heatmap
  • colorMap = name of the color map associated to the type of measure of interest

R parameters example

city="Rome"
long_min <- 12.18645
long_max <- 12.76049
lat_min <-
41.68725
lat_max <- 42.06150
epsgProjection <-
32633
valueType <- "NO2" (or an array: valueType <- c ("NO2", "NO2_", "airQualityNO2", "airqualityNO2"))
à is possible to check the exact name just clicking on the sensor of interest from service map
subnature <- "Air_quality_monitoring_station"
à
to check from service map - transversal services
fromDateTime <-
"12-hour"
toDateTime <-
"2020-05-25T15:00:00"
heatmapName <-
"Rome_NO2"
colorMap <- "HighDensityNO2"

IOT app Json example

{

    "city": "Rome",

    "long_min": 12.18645,

    "long_max": 12.76049,

    "lat_min": 41.68725,

    "lat_max": 42.0615,

    "epsgProjection": 32633,

    "valueType": ["NO2", "NO_2", "airQualityNO2"]

    "fromDateTime": "6-hour",

    "toDateTime": "2020-05-25T15:00:00"

    "heatmapName": "Rome_NO2",

    "subnature": "Air_quality_monitoring_station",

    "colorMap": "HighDensityNO2"

}

Color maps/ measures association

  • NO2 -> "HighDensityNO2"
  • PM10 -> "HighDensityPM10"
  • PM25 -> "HighDensityPM25"
  • CO -> "airQualityCO"
  • CO2 -> "airQualityCO"
  • NO -> "airQualityNO"
  • O3 -> "airQualityO3"
  • airTemperature -> "airTemperature"
  • airHumidity -> "airHumidity"
  • windSpeed-> "windSpeed"

Nb. All the available color map names are listed at the end of this page

WHERE I CAN FIND THE EXACT NAME FOR subnature AND valueType PARAMETERS?

  1. Open the service map: https://servicemap.disit.org/WebAppGrafo/
  2. Under the voice Transversal Services in the top right menu it’s possible to check all the Services Categories. Each Service Category corresponds to a specific subnature. A possible subnature choice to create a weather/ air quality heatmap can be Weather_sensor or Air_quality_monitoring_station.
  3. Click on the subnature category and check all the sensors in the area of interest:

 4. Click on a sensor to check the name of the valueType:

NB: A single property per heatmap. If you are uncertain about the name of the valueType you can enter an array of possible names for that single measure. 

SUPERSERVICE MAPS API example to download data

"https://www.disit.org/superservicemap/api/v1/?serviceUri=ServiceUri&fromTime="fromDateTime&toTime=toDateTime"

ServiceUri = service uri related to the sensor
fromDateTime = fromDateTime R function parameter ("6-hour")
toDateTime = fromDateTime R function parameter ("2020-05-25T15:00:00")

Steps to save heatmaps data using API:

  1. Heatmaps data transformation in json format
    Information associated to each interpolated point:

listAttribTemp = list("mapName"=heatmapName,  "metricName"= colorMap, "description"= dataDescription, "clustered"= 0, "latitude"=UTM_x, "longitude"=UTM_y,"value"= averageInterpolatedValue, "date"= paste(toDateTime, "Z", sep=""),"xLength"=xLength, "yLength"=yLength,"projection"=epsgProjection, "file"=0, "org"="DISIT")

  • xLength and yLength are the cellsize dimension.
  • UTM_x and UTM_y are the UTM coordinates.
  • averageInterpolatedValue is the coordinate value.
  • heatmapName = heatmapName R function parameter
  • colorMap = colorMap R function parameter
  • epsgProjection = epsgProjection R function parameter
     
  1. Json Post

resultPOST <- POST(handle=my_handle, path="insertArray", body = request_body_json, url = NULL, encode = "json", add_headers("Content-Type" = "application/json"))

request_body_json = interpolated data in json format

  1. API to save data (If Result Post (completedParameter) is equal to 200)

"http://192.168.0.59/setMap.php?mapName=heatmapName&metricName=colorMap&date=toDateTime_Z&completed=completedParameter"

heatmapName = heatmapName R function parameter

colorMap = colorMap R function parameter

toDateTime_Z = toDateTime with a final Z: paste(toDateTime, "Z", sep="")

 

list of COLOR MAPS available at the 15/06/2020:

  • accidentDensity
  • airHumidity
  • airQualityAQI
  • airQualityCO
  • airQualityCO2
  • airQualityNO2
  • airQualityNOx
  • airQualityO3
  • airQualityPM10
  • airQualityPM2_5
  • airQualitySO2
  • airTemperature
  • AntwerpClickDensity
  • Benzene
  • bikeSafety
  • CAQI
  • clickDensity
  • dewPoint
  • EAQI
  • EnfuserAirQualityIndex
  • errors
  • HelsinkiClickDensity
  • HighDensityEAQI
  • HighDensityNO2
  • HighDensityNOx
  • HighDensityPM10
  • HighDensityPM25
  • LAeq
  • maxTemperature
  • minGroundTemperature
  • minTemperature
  • NO2
  • noiseLA
  • noiseLAeq
  • noiseLAmax
  • PM10
  • PM2_5
  • safetyOnBikeDensity
  • windGust
  • windSpeed