Color Code Line by range

Greetings,

I am working on color-code Polyline layer by reading a number field and assign color by value. Anyone did the same thing before?

Thanks!
Lang

Did you had a look at the categories?
Here’s an example: https://www.mapwindow.org/documentation/mapwingis4.9/_add_category_range_8cs-example.html

Hi pmeems,

I checked the example you suggested and looked at the LinePattern.cs file. Got it done. But I need to know the meaning of shapefile.set_ShapeCatetory(int ShapeIndex, int (The index of the visualization category).

What is visualization category? Do you have a list?

See code below, hopefully someone else will find it useful.

        var scheme = new ColorScheme();
        Utils utils = new Utils();
       
        for (int i = 0; i < sf.NumShapes; i++)
        {
            double value = (double)sf.get_CellValue(fieldIndex, i);
            if (value > 501)
            {
                ShapefileCategory ct = sf.Categories.Add("Poor");
                LinePattern pattern = new LinePattern();
                pattern.AddLine(utils.ColorByName(tkMapColor.Red), 6.0f, tkDashStyle.dsSolid);
                ct.DrawingOptions.LinePattern = pattern;
                ct.DrawingOptions.UseLinePattern = true;
                sf.set_ShapeCategory(i, 4);
             
            }
            else if (value < 200)
            {
                ShapefileCategory ct = sf.Categories.Add("Good");
                LinePattern pattern = new LinePattern();
                pattern.AddLine(utils.ColorByName(tkMapColor.Green), 6.0f, tkDashStyle.dsSolid);
                ct.DrawingOptions.LinePattern = pattern;
                ct.DrawingOptions.UseLinePattern = true;
               sf.set_ShapeCategory(i, 2);
            }
            else
            {
                ShapefileCategory ct = sf.Categories.Add("Fair");
                LinePattern pattern = new LinePattern();
                pattern.AddLine(utils.ColorByName(tkMapColor.Yellow), 6.0f, tkDashStyle.dsSolid);
                ct.DrawingOptions.LinePattern = pattern;
                ct.DrawingOptions.UseLinePattern = true;
                sf.set_ShapeCategory(i, 3);
            }
        }

The categories are a list and this index specifies the location of this category in the list, which will be shown in the legend in MW5 or can be used in your own legend control.

1 Like