Style problem

Topics: SharpMap Project
Jun 5, 2013 at 1:21 PM
Using VS 2010 and Sharpmap change set 102922

I have the following code running, but with two issues. Note the symboloffset lines are commented out because they throw a null reference exception. and I can't find the problem.

Second, I have color and size columns in the dataset and would like to use them on the symbols but I don't know how to do that.
  ' Add PostGIS site layer:
        Dim provider As SharpMap.Data.Providers.PostGIS
        SiteLayer = New SharpMap.Layers.VectorLayer("Site Layer")
        provider = New SharpMap.Data.Providers.PostGIS(poolConnection, "sites", "lonlat_nad83", "pk_sites")
        provider.DefinitionQuery = "jobnumber = '" & JobNumber & "'"
        SiteLayer.DataSource = provider
        SiteLayer.Enabled = True
        SiteLayer.IsQueryEnabled = True
        Dim circlestyle As New SharpMap.Styles.VectorStyle
        circlestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(New Pen(Drawing.Color.Black, 1), Brushes.White, 12)
        '  circlestyle.SymbolOffset = New SizeF(0, -(circlestyle.Symbol.Height / 2))
        Dim squarestyle As New SharpMap.Styles.VectorStyle
        squarestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(New Pen(Drawing.Color.SlateGray, 1), Brushes.White, 12)
        '   squarestyle.SymbolOffset = New SizeF(0, -(squarestyle.Symbol.Height / 2))
        Dim trianglestyle As New SharpMap.Styles.VectorStyle
        trianglestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateTriangle(New Pen(Drawing.Color.Red, 1), Brushes.White, 12)
        ' trianglestyle.SymbolOffset = New SizeF(0, -(trianglestyle.Symbol.Height / 2))
        Dim filledcirclestyle As New SharpMap.Styles.VectorStyle
        filledcirclestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateCircle(New Pen(Drawing.Color.Black, 1), Brushes.AliceBlue, 12)
        '   filledcirclestyle.SymbolOffset = New SizeF(0, -(filledcirclestyle.Symbol.Height / 2))
        Dim filledsquarestyle As New SharpMap.Styles.VectorStyle
        filledsquarestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(New Pen(Drawing.Color.SlateGray, 1), Brushes.Red, 12)
        ' filledsquarestyle.SymbolOffset = New SizeF(0, -(filledsquarestyle.Symbol.Height / 2))
        Dim filledtrianglestyle As New SharpMap.Styles.VectorStyle
        filledtrianglestyle.PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateTriangle(New Pen(Drawing.Color.Red, 1), Brushes.Black, 12)
        ' filledtrianglestyle.SymbolOffset = New SizeF(0, -(filledtrianglestyle.Symbol.Height / 2))
        Dim styles As New Dictionary(Of String, SharpMap.Styles.IStyle)()
        styles.Add("circle", circlestyle)
        styles.Add("square", squarestyle)
        styles.Add("triangle", trianglestyle)
        styles.Add("filledcircle", filledcirclestyle)
        styles.Add("filledsquare", filledsquarestyle)
        styles.Add("filledtriangle", filledtrianglestyle)
        SiteLayer.Theme = New SharpMap.Rendering.Thematics.UniqueValuesTheme(Of String)("symbol", styles, squarestyle)
Jun 6, 2013 at 10:02 AM
Edited Jun 6, 2013 at 10:14 AM
I'll have to investigate the first issue, for the second one you need to use theming.
Either you implement your own ITheme or use CustomTheme class and provide an appropriate delegete function.

Just noticed that you already use theming. In this case, you need to enhance the UniqueValuesTheme to additionally evaluate color and size and set it accordingly.

Hth FObermaier
Jun 6, 2013 at 10:11 AM
I just noticed what is wrong with the first issue.

As you use a Symbolizer for the style, you don't have a symbol set. Thus you can't evaluate how high it is.
You need to setup the symbolizer like this:
Dim filledsquarestyle As New SharpMap.Styles.VectorStyle
With filledsquarestyle
    .PointSymbolizer = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(New Pen(Drawing.Color.SlateGray, 1), Brushes.Red, 12)
    .PointSymbolizer.Offset = new System.Drawing.PointF(0, .Size.Height / 2f)
End With
NOTE: The code has not seen a compiler
Hth FObermaier