This project has moved and is read-only. For the latest updates, please go here.

VB.NET and CustomTheme

Topics: SharpMap v2.0, WinForms Controls
Oct 29, 2015 at 3:32 PM
Edited Oct 29, 2015 at 3:47 PM

I'm developing an application using SharpMap with VB.NET.
I'm stuck at the theming of a point-geometry.
The point-geometry is loaded via OleDBPoint out of a mssql-database.

I want to display the points in different colors by value-classes (e.g. red for value 1-5, blue for 6-10 and so on).

I've read through the examples, googled a lot and tested different approaches. It seems that CustomTheme is what I need to use. But I can't get it to work.
I don't even understand the samples (but c# is really strange to me...)
Maybe someone can give me a short example on how to implement CustomTheme with VB.Net. I'm really stuck at this!!

Oct 30, 2015 at 8:37 AM
This is a very limited example.
You might want to try SharpMap.Rendering.Thematics.UniqueValuesTheme or SharpMap.Rendering.Thematics.CategoryTheme from
Public Class CustomThemeExample

    Private testColumn As String
    Private styles As System.Collections.Generic.Dictionary(Of String, SharpMap.Styles.IStyle) = _
        New Dictionary(Of String, SharpMap.Styles.IStyle)
    Private defaultStyle As SharpMap.Styles.IStyle

    Public Sub New()
        'TODO FILL in STYLES
    End Sub

    Protected Overrides Sub Finalize()

        For Each kvp In Me.styles
            Dim style = kvp.Value
            If (TypeOf style Is IDisposable) Then
                DirectCast(style, IDisposable).Dispose()
            End If

    End Sub

    Public Sub CustomThemeExample()

        Dim map As New SharpMap.Map()
        Dim prv As New SharpMap.Data.Providers.OleDbPoint("", "points", "fid", "x", "y")
        Dim lyr As New SharpMap.Layers.VectorLayer("points", prv)

        testColumn = "Population"
        defaultStyle = lyr.Style

        lyr.Theme = New SharpMap.Rendering.Thematics.CustomTheme(AddressOf StyleForValue)

        Using bmp As System.Drawing.Bitmap = map.GetMap()
        End Using

    End Sub

    Public Function StyleForValue(row As SharpMap.Data.FeatureDataRow) As SharpMap.Styles.IStyle

        Dim testValue As String = Convert.ToString(row(Me.testColumn))
        Dim result As SharpMap.Styles.IStyle = Nothing
        If (Me.styles.TryGetValue(testValue, result)) Then
            Return result
        End If
        Return Me.defaultStyle

    End Function

End Class

Nov 4, 2015 at 10:53 AM

thank you. Now I've got the CustomThemes running!
But it seems, that I would need the 'SharpMap.Rendering.Thematics.CategoryTheme', as I wish to display value ranges as categories. I've seen the code on github but have no clue how to get the function implemented in my VB.NET project??
Would you please help me?

Nov 4, 2015 at 10:07 PM