This project is read-only.

Raster Layer ColorCategory possible bug

Jan 14, 2011 at 11:59 AM

I am using something simmilar to the following code to add a color map to a raster. 
The problem is that for a value that is exactly the same as the ValueFrom 
is not displaying the correct color but instead black. Everything else works ! this is a weird behaviour
I will try and search why this happens if anyone points me where to look at on the endless dotspatial code.
Any ideas why this happens ? Have i misunderstood something ?

  For i As Integer = 0 To legend.items.Count - 1
            Dim cat As ColorCategory
            cat = New ColorCategory(valueFrom, valueTo, TheColor, TheColor)
                cat.LegendText = catName

            cat.LegendItemVisible = true
        RasterSymbScheme.Categories = RasterSymbSchemeCats
        RasterSymb.Scheme = RasterSymbScheme
 Dim mrl As New MapRasterLayer(fn, RasterSymb)

May 26, 2011 at 4:14 PM

Actually the bug seems to be on the right bound of applied colour , when the value is exactly equal to the right bound(the so called endvalue) so it does not display the chosen highColor but instead the NoData color.

This bug happens when you display bgd raster files.

I will investigate this errors since it is a little urgent and i will post my findings here..

May 26, 2011 at 8:13 PM

These are two examples of how 0 and 1 values are drawn with high and low color and without:

here is a simple code sample on how to test this

   if (map1.Layers.Count > 0 )
                MapRasterLayer mrl = (MapRasterLayer) map1.Layers[0];

                RasterSymbolizer RasterSymb = new  RasterSymbolizer();
                ColorScheme RasterSymbScheme = new  ColorScheme();
                ColorCategoryCollection RasterSymbSchemeCats = new ColorCategoryCollection() ;
                RasterSymb.NoDataColor = Color.Red;

    ColorCategory cat0 = new ColorCategory(-40, -30, Color.FromArgb(160, 160, 160), Color.FromArgb(0, 84, 255));
                ColorCategory cat1 = new ColorCategory(-30, -20, Color.FromArgb(0, 84, 255), Color.FromArgb(138, 200, 230));
                ColorCategory cat2 = new ColorCategory(-20, -10, Color.FromArgb(138, 200, 230), Color.FromArgb(0, 240, 255));
                ColorCategory cat3 = new ColorCategory(-10, 0, Color.FromArgb(0, 240, 255), Color.FromArgb(138, 240, 145));
                ColorCategory cat4 = new ColorCategory(0, 10, Color.FromArgb(138, 240, 145), Color.FromArgb(255, 255, 0));
                ColorCategory cat5 = new ColorCategory(10, 20, Color.FromArgb(255, 255, 0), Color.FromArgb(255, 143, 0));
                ColorCategory cat6 = new ColorCategory(20, 30, Color.FromArgb(255, 143, 0), Color.FromArgb(255, 84, 0));

                cat0.LegendText = "Cat0";
                cat0.LegendItemVisible = true;
                cat1.LegendText = "Cat1";
                cat1.LegendItemVisible = true;
                cat2.LegendText = "Cat2";
                cat2.LegendItemVisible = true;
                cat3.LegendText = "Cat3";
                cat3.LegendItemVisible = true;
                cat4.LegendText = "Cat4";
                cat4.LegendItemVisible = true;
                cat5.LegendText = "Cat5";
                cat5.LegendItemVisible = true;
                cat6.LegendText = "Cat6";
                cat5.LegendItemVisible = true;

               RasterSymbScheme.Categories = RasterSymbSchemeCats;
                RasterSymb.Scheme = RasterSymbScheme;
                RasterSymb.ColorSchemeHasUpdated = true;
                mrl.Symbolizer = RasterSymb;
                RasterSymbolizer iRS = (RasterSymbolizer) mrl.Symbolizer;
                mrl.Symbolizer = RasterSymb;
                map1.ViewExtents = mrl.Extent;

Jun 3, 2011 at 12:56 AM

anyone if this is the appropriate method to use a color table ? the tutorial on raster seems a little bit different ...

Sep 24, 2012 at 4:37 PM


i've got the same problem, no color on limit.

Is someone found a solution ?

Best regards.

May 3, 2016 at 9:52 PM
So working with loading a raster and basically cloned my scheme from MapWindow. Right away I noticed the holes and it looks like this is still an issue. So do we have to adjust manually for the symbolizing of the end as < Val rather than <= Val. If that's the case then it looks like the start is > Val so really it is not inclusive on either boundary. Is that the way it should be?