# Color Code Line by range

**URL:** <https://mapwindow.discourse.group/t/color-code-line-by-range/162>\
**Category:** MapWinGIS\
**Created:** [May 17, 2019, 6:46pm UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162 "2019-05-17T18:46:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lang](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@lang](https://mapwindow.discourse.group/u/lang)\
**Post date:** [May 17, 2019, 6:46pm UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162/1 "2019-05-17T18:46:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [May 19, 2019, 2:00pm UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162/2 "2019-05-19T14:00:18Z")

</div>

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](https://www.mapwindow.org/documentation/mapwingis4.9/_add_category_range_8cs-example.html)

---

<div class="post-metadata">

**Author:** ![lang](https://avatars.discourse-cdn.com/v4/letter/l/0ea827/32.png) [@lang](https://mapwindow.discourse.group/u/lang)\
**Post date:** [May 24, 2019, 2:35pm UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162/3 "2019-05-24T14:35:17Z")

</div>

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);
            }
        }
```

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [May 28, 2019, 7:24am UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162/4 "2019-05-28T07:24:06Z")

</div>

> [@lang](#):
>
> But I need to know the meaning of shapefile.set\_ShapeCatetory(int ShapeIndex, int (The index of the visualization category).

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.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [July 3, 2019, 7:31am UTC](https://mapwindow.discourse.group/t/color-code-line-by-range/162/5 "2019-07-03T07:31:15Z")

</div>


