This project has moved. For the latest updates, please go here.

Gradient Theme

Below is a few examples on how to create gradient styles, all based on the "PopDens" attribute in the demo-datasource "Countries.shp"

Grading Fill and Outline
SharpMap.Styles.VectorStyle min = new SharpMap.Styles.VectorStyle();
SharpMap.Styles.VectorStyle max = new SharpMap.Styles.VectorStyle();
//Create a fill that starts from white to red
//and an outline that starts from thin black to wide yellow
min.Fill = Color.White;
max.Fill = Color.Red;
min.Outline = new Pen(Color.Black,1);
max.Outline = new Pen(Color.Yellow,5);
min.EnableOutline = true;
max.EnableOutline = true;

//Create theme using a population density from 0 (min) to 400 (max)
myVectorLayer.Theme = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, min, max);

Using ColorBlending
Color blends automatically creates a gradient between two or more colors. In this case we use a rainbow fill blend based on five colors. The blend properties will override any style set in min and max values.
//Create theme using a population density from 0 (min) to 400 (max)
SharpMap.Rendering.Thematics.GradientTheme popdens = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400,
	new SharpMap.Styles.VectorStyle(), new SharpMap.Styles.VectorStyle());
//We can make more advanced coloring using the ColorBlend'er.
//Setting the FillColorBlend will override any fill-style in the min and max fills.
//In this case we just use the predefined Rainbow colorscale
popdens.FillColorBlend = SharpMap.Rendering.Thematics.ColorBlend.Rainbow5;
myVectorLayer.Theme = popdens;

Grading LabelStyles
The following shows how to change the size and style of a label based on the population density attribute "PopDens".
SharpMap.Styles.LabelStyle lblMin = new SharpMap.Styles.LabelStyle();
SharpMap.Styles.LabelStyle lblMax = new SharpMap.Styles.LabelStyle();
lblMin.ForeColor = Color.Black;
lblMin.Font = new Font(FontFamily.GenericSerif, 6);
lblMax.ForeColor = Color.Blue;
lblMax.BackColor = new SolidBrush(Color.FromArgb(128, 255, 255, 255));
lblMin.BackColor = lblMax.BackColor;
lblMax.Font = new Font(FontFamily.GenericSerif, 9);
myLabelLayer.Theme = new SharpMap.Rendering.Thematics.GradientTheme("PopDens", 0, 400, lblMin, lblMax);		


Last edited Aug 3, 2006 at 9:49 PM by SharpGIS, version 3