HeatLayer Guidance

Topics: SharpMap Project, SharpMap v0.9 / v1.x, WinForms Controls
Apr 5 at 9:43 AM
Edited Apr 5 at 9:45 AM
Hi

I have been trying to load and generate a heat map from one of my shape files. In QGIS my heat map looks like this (I set up the Fire colour scheme to compare results):

QGIS Heat Layer
QGIS Heat Layer Link To Image

When I try to generate a heat map using SharpMap I just get what seems to be the Vector layer ploted. I realise I have probably made a silly mistake but have spent a number of hours now poking in the Heat Layer source code and getting no where. Attached is my code I'm using to populate the heat layer. This is the only content I'm adding to the map control.

Any help would be greatly appreciated.

Dave
private void AddHeatLayer(string file)
{
    SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer(System.IO.Path.GetFileNameWithoutExtension(file));
    vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(file, true);
    SharpMap.Layers.HeatLayer hlay = new SharpMap.Layers.HeatLayer(vlay, "Value");
    hlay.HeatColorBlend = SharpMap.Layers.HeatLayer.Fire;
    hlay.HeatValueComputer = GetValue;
    //mapControl.Map.Layers.Add(vlay);
    mapControl.Map.Layers.Add(hlay);
    mapControl.Map.ZoomToExtents();
    mapControl.Refresh();
}

private float GetValue(SharpMap.Data.FeatureDataRow data)
{
    float val = 0f;
        
    val = Convert.ToSingle(data[4]);

    if (val > 1f)
        val = 1f;
    else if (val < 0f)
        val = 0f;

    return val;
}
Coordinator
Apr 5 at 2:19 PM
Your GetValue function does return other values than 0?
Is there a chance that GetValue might fail due to null in column with index 4?
Apr 5 at 3:00 PM
Edited Apr 5 at 3:01 PM
Thanks for your response. I changed the second line of my GetValue function to:
try
{
    if (data[4] != null)
        val = Convert.ToSingle(data[4]);
}
catch
{
    val = 0f;
}
But this did not help. During my tests I noticed at least 1 value was 6.5E-16 so I even tried limiting the return value to be between 0.0001f and 1.0f but this still did not help.

I have also added the vector layer to the layers, as ZoomExtents was throwing an exception without it, I guess because the heat layer had not rendered at that point.

Dave
Apr 5 at 4:28 PM
Edited Apr 5 at 4:50 PM
I have managed to find my issue, by downloading the source code and creating a test solution including the minimum SharpMap projects to get by. The problem was the Opacity was set to zero in the render function, the OpacityMax value defaults to 0.7 and OpacityMIn is 1.0. If I change the max value to 1.0 I see the heat map.

I'm new to SharpMap so I'm not really sure what I've done. :(

Anyway first problem overcome, thanks for your help.

Dave

Having looked into this further InterpolateOpacityValues() does not get called unless one of the above property values are set. If neither of the values are set the _opacity array contains zeros. I assumed that the basic default values would allow a heatmap to be displayed. Should InterpolateOpacityValues() be called fromt he constructor? to use the default values?
Coordinator
Apr 5 at 8:56 PM
dmoor wrote:
Having looked into this further InterpolateOpacityValues() does not get called unless one of the above property values are set. If neither of the values are set the _opacity array contains zeros. I assumed that the basic default values would allow a heatmap to be displayed. Should InterpolateOpacityValues() be called fromt he constructor? to use the default values?
Good catch, I will fix that asap.