Trying to Colour Scheme similar to MapWindow5 in MapWinGis


I’ve set up a colour scheme in MapWindow5, and thought it would relatively easy to set up something similar in MapWinGis, but I’m struggling.

Here is my code thus far:

GridColorScheme gridColorScheme = new GridColorScheme();
uint[] colours = { 16777152, 15656650, 14536083, 11443026, 15306020, 9109504 };

double interval = (double)grid.Maximum / 6.0;
double currentBottom = 0.0000000001;

GridColorBreak colorBreak;

for (uint currentBreak = 0; currentBreak < 6; ++currentBreak) {

    colorBreak = new GridColorBreak();
    colorBreak.HighColor = colours[currentBreak];
    colorBreak.LowColor = colours[currentBreak];

    colorBreak.LowValue = currentBottom;
    colorBreak.HighValue = currentBottom+interval;


    currentBottom += interval;


colorBreak = new GridColorBreak();
colorBreak.HighColor = 16777215;
colorBreak.LowColor = 16777215;

colorBreak.LowValue = 0.0;
colorBreak.HighValue = 0.0;


img.CustomColorScheme = gridColorScheme;

All I’d really like to do, is create a simple colour scheme for water depths, i.e. using a gradient from white to dark blue (maybe I’ll use red for the extremes, maybe), and set the zero values to be transparent.

Any ideas please


This produces:


In MW5 you can save your color scheme to a file:

This will produce a XML-file which you can open in any text editor.
The content is the serialized color scheme. So looking at the names you might get some idea what to do.

At this moment I don’t have a grid file near by so I can test it myself :wink:

Let us know if this works.


Yes I realised that saving the style in MapWindow5 created and XML files, which I read, which got me as far as I did. Here is an example XML saved style file:

    <XmlLayer xmlns:i="" xmlns="">
  <ColorSchemeCaption>Band: 1 of 1 (Undefined)</ColorSchemeCaption>
        <SymbologyMetadata xmlns="">
  <Identity xmlns:d2p1="">
    <d2p1:Connection i:nil="true" />
    <d2p1:Query i:nil="true" />
    <Layer LayerType="Image" LayerName="Test_case_1_WDraster_max_PEAK" LayerVisible="1" LayerKey="" MaxVisibleZoom="100" SourceName="Test_case_1_WDraster_max_PEAK.asc" Filename="" xmlns="">
      <ImageClass TransparencyColor="16777215" UseTransparencyColor="-1" DownsamplingMode="3" UpsamplingMode="5" AllowGridRendering="0" AllowHillshade="1" BufferSize="3604534" ClearGdalCache="1" SourceGridBandIndex="1" UseHistogram="1" IgnoreColorTable="1">
          <Band Min="0.000000" Max="2.030000" Valid="1" />
        <GridColorScheme Key="" NoDataColor="16777215" LightSourceIntensity="0.700000" AmbientIntensity="0.700000" LightSourceElevation="45.000000" LightSourceAzimuth="90.000000" LightSourceI="0.000000" LightSourceJ="-0.707000" LightSourceK="1.000000">
            <GridColorBreakClass HighColor="15854547" LowColor="16777215" LowValue="0.000000" HighValue="0.338333" />
            <GridColorBreakClass HighColor="14931622" LowColor="15854547" LowValue="0.338333" HighValue="0.676667" />
            <GridColorBreakClass HighColor="13942904" LowColor="14931622" LowValue="0.676667" HighValue="1.015000" />
            <GridColorBreakClass HighColor="9798201" LowColor="13942904" LowValue="1.015000" HighValue="1.353333" />
            <GridColorBreakClass HighColor="6510117" LowColor="9798201" LowValue="1.353333" HighValue="1.691667" />
            <GridColorBreakClass HighColor="10040879" LowColor="6510117" LowValue="1.691667" HighValue="2.030000" />
        <LabelsClass Generated="0" TextRenderingHint="3" />

This is where I got the concept of the GridColorScheme, GridColorBreaks etc. Although it appears that the upper half is unique to MapWindow5? Things like RasterColorBlend, ColorBlendItem…

How do you generate the colour codes?


OK I managed to get it to look the same, yay?! :slight_smile:

Must be something wrong with my loop, as hard coding the colour breaks in seemed to get it working.