Trying to Colour Scheme similar to MapWindow5 in MapWinGis


#1

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;

    gridColorScheme.InsertBreak(colorBreak);

    currentBottom += interval;

}


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

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

gridColorScheme.InsertBreak(colorBreak);

img.SetTransparentColor(16777215);
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


#2

This produces:


#3

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.


#4

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="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/MW5.Services.Serialization">
  <ColorSchemeCaption>Band: 1 of 1 (Undefined)</ColorSchemeCaption>
  <CustomObjects>
    <XmlCustomObject>
      <Guid>7b9df651-4b8b-4aa8-a4a9-c1463a35dac7</Guid>
      <Object>
        <SymbologyMetadata xmlns="">
          <Initialized>false</Initialized>
          <RasterColorBlend>
            <Items>
              <ColorBlendItem>
                <Color>White</Color>
                <Position>0</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#D2EAF0</Color>
                <Position>0.166666672</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#A5D5E2</Color>
                <Position>0.333333343</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#78C0D4</Color>
                <Position>0.5</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#388194</Color>
                <Position>0.6666667</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#255663</Color>
                <Position>0.8333333</Position>
              </ColorBlendItem>
              <ColorBlendItem>
                <Color>#2F3699</Color>
                <Position>1</Position>
              </ColorBlendItem>
            </Items>
          </RasterColorBlend>
        </SymbologyMetadata>
      </Object>
    </XmlCustomObject>
  </CustomObjects>
  <Expanded>true</Expanded>
  <Guid>13fed943-dcf4-42dc-89f3-ca3dc11dc3d2</Guid>
  <HideFromLegend>false</HideFromLegend>
  <Identity xmlns:d2p1="http://schemas.datacontract.org/2004/07/MW5.Api.Concrete">
    <d2p1:Connection i:nil="true" />
    <d2p1:Filename>E:\PROCESSING\Test_case_1\outs\Test_case_1_WDraster_max_PEAK.asc</d2p1:Filename>
    <d2p1:GeometryType>None</d2p1:GeometryType>
    <d2p1:IdentityType>File</d2p1:IdentityType>
    <d2p1:Query i:nil="true" />
    <d2p1:ZValueType>None</d2p1:ZValueType>
  </Identity>
  <LayerType>Image</LayerType>
  <Name>Test_case_1_WDraster_max_PEAK</Name>
  <OcxLayer>
    <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">
        <Bands>
          <Band Min="0.000000" Max="2.030000" Valid="1" />
        </Bands>
        <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">
          <GridColorBreaks>
            <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" />
          </GridColorBreaks>
        </GridColorScheme>
        <LabelsClass Generated="0" TextRenderingHint="3" />
      </ImageClass>
    </Layer>
  </OcxLayer>
  <Selected>false</Selected>
</XmlLayer>

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?


#5

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.