Heat map: Difference between revisions
(Created page with "== General == Heat maps are typically used to indicate density of data points geographically using color coding. They can be used to visualise large amounts of point data in 2...") Â |
(→â€) |
||
Line 157: | Line 157: | ||
|HeatmapGroupSettings.KernelShape | |HeatmapGroupSettings.KernelShape | ||
|Controls how point values are distributed across the heatmap radius. See https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use | |Controls how point values are distributed across the heatmap radius. See https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use | ||
|enum ( | |enum (Quartic, Triangular, Uniform, Triweight, Epanechnikov or Gaussian) | ||
|- | |- | ||
|HeatmapGroupSettings.ValueScale | |HeatmapGroupSettings.ValueScale |
Revision as of 14:29, 17 November 2020
General
Heat maps are typically used to indicate density of data points geographically using color coding. They can be used to visualise large amounts of point data in 2D.
Examples include:
- Historical positions
- Population densities
- Frequency of events
https://en.wikipedia.org/wiki/Heat_map
Typically, bright of "hot" colors are used to indicate high level of activity or denser areas while "cooler" colors are used to indicate lower levels of activity. Several different palettes can be used for heatmaps. Some examples can be found here: https://www.andrewnoske.com/wiki/Code_-_heatmaps_and_color_gradients
Heat map generation
Geographical heat map generation follows the following general steps:
- For a given view, a set of possibly weighted positions are extracted
- Weights/counts are accumulated in a raster
- Some heat map kernel is applied to smooth and spread measurements
- Color is applied
Heat maps in GDK
Maria GDK provides an optimised engine for generating heatmaps for large amounts of geographical data, up to around 100 million points can be processed with acceptable performance. Parameters can be changed interactively with the heat map display changing nearly instantly.
IHeatMapLayerViewModel exposes the heat map API:
namespace TPG.GeoFramework.HeatMapLayer
{
/// <summary>
/// View model for general heat maps
/// </summary>
public interface IHeatMapLayerViewModel:IGeoLayerViewModel
{
/// <summary>
/// Heat map data is organized in HeatMapGroups. Each group contains clusters of heat map data.
/// Separate settings and color palettes can be set for each group.
/// Note that the heat map property setters are applied to both default settings and to all groups.
/// For detailed, individual group settings control, access elements in the HeatMapGroups directly
/// </summary>
ObservableCollection<HeatMapGroup> HeatMapGroups { get; }
/// <summary>
/// HeatMapSettings contain global settings and a default group setting that
/// is used when no settings are available for a heat map group.
/// </summary>
HeatMapSettings HeatMapSettings { get; }
/// <summary>
/// Sets kernel radius unit (meters or pixels)
/// </summary>
KernelRadiusUnitEnum KernelRadiusUnit { get; set; }
/// <summary>
/// Kernel radius, unit controlled by KernelRadiusUnit
/// </summary>
double KernelRadius { get; set; }
/// <summary>
/// Sets kernel shape. The kernel shape controls how values are smoothed in the HeatMap.
/// See https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use
/// </summary>
KernelShapeEnum KernelShape { get; set; }
/// <summary>
/// Max pixel radius used when applying kernel. This is relevant when setting the kernel unit to "meters"
/// and is used to limit demanding calculations
/// </summary>
double MaxPixelRadius { get; set; }
/// <summary>
/// Multiplier is applied to all values prior to applying the kernel
/// </summary>
double ValueScale { get; set; }
/// <summary>
/// Smaller grid cell sizes yield higher quality heat maps. Larger grid cell sizes are quicker. Typical range is 1-10.
/// </summary>
int GridCellSize { get; set; }
}
}
Adding positions
Positions are addud using IHeatMapLayerViewModel.HeatMapGroups. The sample below contains code from NGTester used to load heat map data from file. Note that using PositionGroupCollection below it is very easy to load large amounts of position data into the TPG NGTester heat map.
public static HeatMapGroup CreateTestGroup(string fileName)
{
PositionGroupCollection testData;
using (var stream = File.Open(fileName, FileMode.Open))
testData = PositionGroupCollection.Parser.ParseFrom(stream);
var result = new HeatMapGroup
{
Settings = new HeatMapGroupSettings {KernelShape = KernelShapeEnum.Triweight},
Name = !string.IsNullOrWhiteSpace(testData.Name) ? testData.Name : NameFromFileName(fileName)
};
foreach (var item in testData.PositionGroups)
{
var hdi = new HeatMapItemData
{
Id = item.Name,
GeoData = new HeatMapGeoData(item.Positions.Select(a => new GeoPos(a.Lat, a.Lon)).ToArray())
};
result.Add(hdi.Id, hdi);
}
return result;
}
heatMapVm.HeatMapGroups.Add(CreateTestGroup("some_test_data.geo");
Where PositionGroupCollection and "some_test_data.geo" is defined as a protobuf message:
message Position
{
double lat=1;
double lon=2;
}
message PositionGroup
{
string Name=1;
repeated Position Positions=2;
}
message PositionGroupCollection
{
string Name=1;
repeated PositionGroup PositionGroups=2;
}
Heat map settings
Heat map settings affects how the heat map is generated and displayed. IHeatMapLayerViewModel.HeatMapSettings control global settings and defaults. In addition, each HeatMapGroup contains an optional HeatMapGroupSettings
Item | Description | Value type |
---|---|---|
HeatMapSettings.GridCellSize | Controls quality of grid display. Higher values will greatly boost performance, while sacrificing heatmap quality. A value of "1" creates the best heatmap visualisation. Default is "2", this creates high resolution heatmaps while preserving good performance. Typical range is 1-8. | int (Pixels) |
HeatmapGroupSettings.KernelRadius | Controls the size (radius) of the heatmap measured from every data point | double (Value in Pixels or Meters, controlled by HeatmapGroupSettings.KernelRadiusUnit) |
HeatmapGroupSettings.KernelRadiusUnit | Controls the unit type for HeatmapGroupSettings.KernelRadius | enum ("Pixels" or "Meters") |
HeatmapGroupSettings.KernelShape | Controls how point values are distributed across the heatmap radius. See https://en.wikipedia.org/wiki/Kernel_(statistics)#Kernel_functions_in_common_use | enum (Quartic, Triangular, Uniform, Triweight, Epanechnikov or Gaussian) |
HeatmapGroupSettings.ValueScale | Can be used to compress or expand the values in the heatmap. Manipulating ValueScale can be used interactively to alter visuals without editing the color tables | double (Factor) |
HeatmapGroupSettings.MaxPixelRadius | Limits the maximum number of pixels in the heatmap radius. When selecting RadiusType "Meters", setting this parameter will limit the maximum heatmap size when zooming in. This may prevent sluggish performance. | double (Pixels) |
Heat map colors
When defining heat map colors, some heatmap value must be associated with each range of colors