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

duplicate label issue - sharpmap

Nov 22, 2006 at 8:35 AM
I am having problem with a label layer of US States map. I am getting lots of duplication ( like CA 4 times, NY 5 times etc.) of state names. and mainly it is occuring to coastal areas. does anyone have any ideas?
I tried the same shape file with a map browser and it is showing perfectly there. so shape file is not corrupted.
here is the code I am using for adding label layer.

Dim myStateLayer As SharpMap.Layers.VectorLayer
myStateLayer = New SharpMap.Layers.VectorLayer("States")
myStateLayer.DataSource = New SharpMap.Data.Providers.ShapeFile("C:\demowebsite\App_Data\USA\states.shp", True)
myStateLayer.Style.Fill = New System.Drawing.SolidBrush(Color.GreenYellow)
myStateLayer.Style.Outline = New Pen(Color.Black)
myStateLayer.Style.EnableOutline = True

Dim layStateLabel As New SharpMap.Layers.LabelLayer("StateLabels")

layStateLabel.DataSource = myStateLayer.DataSource

layStateLabel.LabelColumn = "STATE_ABBR"

layStateLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias
layStateLabel.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias

layStateLabel.Enabled = True

layStateLabel.Style = New SharpMap.Styles.LabelStyle
layStateLabel.Style.Font = New Font("Arial", 12)
layStateLabel.Style.ForeColor = Color.Blue
layStateLabel.Style.HorizontalAlignment = SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center
layStateLabel.Style.VerticalAlignment = SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle
layStateLabel.Style.CollisionDetection = True
layStateLabel.Style.CollisionBuffer = New System.Drawing.SizeF(10, 10)


Nov 23, 2006 at 2:56 AM
I would think that there are more islands at the coastal areas than in the center of the country.

....this is the point where you start thinking and hopefully realize what is happening... :-)

By default SharpMap labels all objects. So if a state is covering several islands, it places a label on each one. You can control this by setting the MultipartGeometryBehaviour property on the LabelLayer to place the label on for example the largest object in a multipolygon (slowest method) or the first (fastest method).
Nov 23, 2006 at 10:14 AM
Thanks a lot Odegaard. It solved my problem. I really appreciate your help. Thanks once again.