I’m trying to get a couple of shapes in a (polygon) shape file to fill with a specific color.
VB.Net code looks like:
Dim fieldIndex As Integer = LTag.Shpfile.Table.FieldIndexByName("GRIDCODE") For idx As Integer = 0 To LTag.Shpfile.NumShapes - 1 Dim fldval = LTag.Shpfile.CellValue(fieldIndex, idx) Dim tp As Type = fldval.GetType If tp = GetType(Double) Then Dim thisfieldval As Integer = CInt(DirectCast(fldval, Double)) ' check if this is one of the targetted shapes If ScIDs.Contains(thisfieldval) Then Dim newcat As ShapefileCategory = LTag.Shpfile.Categories.Add(thisfieldval.ToString) newcat.Expression = "[GRIDCODE]" newcat.ValueType = tkCategoryValue.cvExpression Dim newoptions As ShapeDrawingOptions = newcat.DrawingOptions newoptions.FillColor = Convert.ToUInt32(RGB(0, 0, thisfieldval)) newoptions.FillColor = Convert.ToUInt32(RGB(0, 0, 255)) newoptions.LineWidth = 2 newoptions.LineColor = utils.ColorByName(tkMapColor.Blue) End If End If Next LTag.Shpfile.Categories.ApplyExpressions()
I also tried without the Expression statement and a ValueType = tkCategoryValue.cvSingleValue but neither are working.
By the time you get to the last line of code, there are a correct number of Categories in the shapefile, but the map does not change. I guess the ApplyExpression call may not be right as there really is no expression to be evaluated.
Reading the documentation:
It’s the responsibility of the developer to map the new category to the particular shape by either:
- specifying [ShapefileCategory.Expression]
- by using [Shapefile.set_ShapeCategory()]
The Shapefile.set_ShapeCategory function looks more appropriate, but my (version 22.214.171.124) AxMap object tells me that it is not a member of Shapefile.
In short: any help would be very much appreciated.