TatukGIS menu

Knowledge Base

KB10803 - Color a shapefile layer using attribute values with a layer event (Visual Basic)

Add a field called COLOUR to the layer:

  layer.AddField("COLOUR", TGIS_FieldType.gisFieldTypeString, 255, 0)

Set the color field to the shape:

  Dim sColor As String
  sColor = System.Drawing.ColorTranslator.ToHtml(myPolygon.Colour)
  ShapePolygon.SetField("COLOUR", sColor) 'shape polygon is of TGIS_Shape type

When using a ttkgp file, add a delegate to the PaintShape event:

  AddHandler m_objLayerBoundaryPolygon.PaintShape, AddressOf MyShapePaintEvent

In the PaintShapeEvent, get color from the field, assign property, and draw shape:

  Private Sub MyShapePaintEvent(ByVal sender As Object, ByVal _e As TGIS_PaintShapeEventArgs)
    Dim shape As TGIS_Shape = _e.Shape
    Dim sColor As String
    Dim colconverter As New System.Drawing.ColorConverter

     sColor = CType(shape.GetField("COLOUR" ), String)
     shape.Params.Area.OutlineColor =
     CType(colconverter.ConvertFromString(sColor ), System.Drawing.Color)

  End Sub

Created: November 19, 2008, Modified: December 08, 2015