Working with Points and Image Icons

Jun 10, 2011 at 7:22 PM

I have learned how to create a series of points using the FeatureSet as given in the DemoMap example. However I now want to add different images as an icon for some of the points I created - therefore do not think the Symboliser is the correct approach (or can it be used with categories ?)

So what I need is:

  1. when I add a point how can I add a unique identifier to it and how?
  2. an example on how to add an image to a specified point
  3. can I then rotate each icon separately and if yes how?

Preferably VB.net but I can read C# - will then translate it myself

Roger

Coordinator
Jun 11, 2011 at 6:17 AM

Roger,

I don't have an answer to your question, but at least I can tell you that I've added you to the team as an "Editor" which means that as you find out solutions to these problems, you would be able to post the relevant code on the documentation/tutorials page. 

Thanks,

Dan

Jun 11, 2011 at 8:48 AM

Thanks Dan - will be more than happy to do so. Hope I get some answers soon or find it myself as it is not very clear how to go about it.

Roger

May 19, 2015 at 4:36 AM
i have same issue
Developer
May 19, 2015 at 6:27 AM
Hey riadh,

you can do this with the help of a PointScheme. Just create it and add it to your FeatureLayer like the example below does.

You need one field (in my example it's contained in filterfeld) to tell each point to which category it belongs. When you add a new point to your featureset you add the correct filterfeld-value to it's datarow to put it in the category it belongs.

jany_
Dim filterfeld as String = "catField" 'field used to put the point into a certain category
Dim Legendentext as String = "LayerName" 'change to the text you want to show in legend
myScheme = New PointScheme
myScheme.Categories.Clear()
myScheme.EditorSettings.ClassificationType = DotSpatial.Symbology.ClassificationType.UniqueValues
myScheme.EditorSettings.FieldName = filterfeld
myScheme.LegendText = Legendentext
addImageCat(Angle, Size, Filterwert, Legendentext, Definitions.FolderBmp & "VP.png")

myFeatureLayer.Symbology = myScheme

Private Sub addImageCat(Angle As Integer, Size As Integer, Filterwert As String, Legendentext As String, ImageFilePath As String, Optional farbe As Color = Nothing)
            Dim image1 As Image = Drawing.Image.FromFile(ImageFilePath, True)
            Dim picsym As New PictureSymbol(image1, Size)
            picsym.Angle = Angle
            Dim cat As New PointCategory(picsym)
            cat.FilterExpression = "[" & Filterfeld & "] = '" & Filterwert & "'"
            cat.LegendText = Legendentext
            cat.Symbolizer.ScaleMode = ScaleMode.Simple
            cat.Symbolizer.Smoothing = False
            myScheme.AddCategory(cat)
End Sub
May 19, 2015 at 12:03 PM
Edited May 19, 2015 at 12:05 PM
it is very helpful, am working in C# but doesn't matter i will translate it. thank you very much!
riadh
May 19, 2015 at 12:15 PM
if i may, i have another question, how to draw a dash lines or polygons. i mean how to draw a different type of lines: dash, dot...... so on.
Developer
May 19, 2015 at 1:35 PM
The following code could be used to create a line layer that has categories with different dashstyles:
  myScheme = New LineScheme
  myScheme.Categories.Clear()
  myScheme.EditorSettings.ClassificationType = DotSpatial.Symbology.ClassificationType.UniqueValues
  myScheme.EditorSettings.FieldName = filterfeld
  myScheme.LegendText = Legendentext
  addDashCat(Filterwert, Color.Red, Drawing2D.DashStyle.Dash, 2)
  myFeatureLayer.Symbology = myScheme

Private Sub addDashCat(Filterwert As Integer, Color As Color, DashStyle As Drawing2D.DashStyle, Optional width As Double = 2)
 Dim cat As New DotSpatial.Symbology.LineCategory(Color, width)
 cat.Symbolizer.Strokes.Clear()
 cat.FilterExpression = "[" & Filterfeld & "] = '" & Filterwert & "'"
 cat.LegendText = Filterwert.ToString
 cat.Symbolizer.ScaleMode = ScaleMode.Simple

 Dim s As New SimpleStroke(2, Drawing.Color.Red)
 s.DashStyle = DashStyle
 cat.Symbolizer.Strokes.Add(s)
 cat.Symbolizer.Smoothing = False
 myScheme.AddCategory(cat)
End Sub
If you want to create more complicated DashStyles you could do it like stated in the Developer Getting Started Guide:
LineSymbolizer mySymbolizer = new LineSymbolizer();
mySymbolizer.Strokes.Clear();
CartographicStroke ties = new CartographicStroke(Color.Brown);
ties.DashPattern = new float[] {1/6f, 2/6f};
ties.Width = 6;
ties.EndCap = LineCap.Flat;
ties.StartCap = LineCap.Flat;
CartographicStroke rails = new CartographicStroke(Color.DarkGray);
rails.CompoundArray = new float[]{.15f,.3f,.6f,.75f};
rails.Width = 6;
rails.EndCap = LineCap.Flat;
rails.StartCap = LineCap.Flat;
mySymbolizer.Strokes.Add(ties);
mySymbolizer.Strokes.Add(rails);
myLayer.Symbolizer = mySymbolizer;
For a polygon layer with different categories you can use this:
myScheme = New PolygonScheme
myScheme.Categories.Clear()
myScheme.EditorSettings.ClassificationType = DotSpatial.Symbology.ClassificationType.UniqueValues
myScheme.EditorSettings.FieldName = filterfeld
myScheme.LegendText = Legendentext

addCat(Filterwert, Legendentext, New DotSpatial.Symbology.SimplePattern(FillColor) With {.Outline = New LineSymbolizer(OutlineColor, 1), .UseOutline = True}) ' pattern with single colored background and border 

addCat(Filterwert, Legendentext, New DotSpatial.Symbology.HatchPattern(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, OutlineColor, FillColor) With {.Outline = New LineSymbolizer(OutlineColor, 1), .UseOutline = True}) 'pattern with hatches

  Private Sub addCat(Filterwert As String, Legendentext As String, ParamArray Patterns() As Pattern)
            Dim cat As New DotSpatial.Symbology.PolygonCategory()
            cat.Symbolizer.Patterns.Clear()
            cat.FilterExpression = "[" & Filterfeld & "] = '" & Filterwert & "'"
            cat.LegendText = Legendentext
            cat.Symbolizer.ScaleMode = ScaleMode.Simple
            cat.Symbolizer.Smoothing = False
            For i As Integer = 0 To Patterns.Length - 1
                cat.Symbolizer.Patterns.Add(Patterns(i))
            Next
            myScheme.AddCategory(cat)
        End Sub