Back to Devexpress

ChoroplethColorizer Class

windowsforms-devexpress-dot-xtramap-10dfc4fe.md

latest7.8 KB
Original Source

ChoroplethColorizer Class

Represents the Choropleth-like colorizer.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public class ChoroplethColorizer :
    GenericColorizer<ColorizerColorItem>,
    ILegendDataProvider,
    IChoroplethColorizer,
    IColorizer
vb
Public Class ChoroplethColorizer
    Inherits GenericColorizer(Of ColorizerColorItem)
    Implements ILegendDataProvider,
               IChoroplethColorizer,
               IColorizer

The following members return ChoroplethColorizer objects:

Remarks

The ChoroplethColorizer class is intended to colorize vector items based on their values.

To colorize vector items using this colorizer, assign an instance of the ChoroplethColorizer class to the VectorItemsLayer.Colorizer property and adjust its settings as required. For instance, specify colors via the ChoroplethColorizer.ColorItems property, range intervals via the ChoroplethColorizer.RangeStops property and the manner of distributing colors along range intervals via the ChoroplethColorizer.RangeDistribution property.

For more information, refer to Colorizers.

Example

This example demonstrates how to paint each map contour in a specific color. To accomplish this, it is necessary to create a colorizer (choropleth or graph) and assign it to the VectorItemsLayer.Colorizer property.

For this colorizer, it is necessary to create a ShapeAttributeValueProvider object, specify the name of the shape attribute that contains a value to be colorized to its ShapeAttributeValueProvider.AttributeName property, and assign this value provider to the ChoroplethColorizer.ValueProvider property.

Then, split the entire data into ranges and add the required range stops to the DoubleCollection returned by the ChoroplethColorizer.RangeStops property.

Finally, add the desired set of colors to the GenericColorizerItemCollection<T> that is accessed from the ChoroplethColorizer.ColorItems property. The colorizer automatically associates each color with the specified data ranges.

Note

  • If you wish to display information on what each color means, create a Color Scale legend. To do this, create a ColorScaleLegend object and add it to the MapControl.Legends collection. In this legend, set its ItemsLayerLegend.Layer property to the previously created layer object and adjust other legend properties as required.
  • If you wish copy the shape file to your project, you should also copy the Countries.dbf file.

View Example

csharp
// Create colorizer for the MapLayer.
    MapLayer.Colorizer = CreateColorizer();
private MapColorizer CreateColorizer() {
    // Create a Choropleth colorizer
    ChoroplethColorizer colorizer = new ChoroplethColorizer();

    // Specify colors for the colorizer.
    colorizer.ColorItems.AddRange(new ColorizerColorItem[] {
        new ColorizerColorItem(Color.FromArgb(0x5F, 0x8B, 0x95)), 
        new ColorizerColorItem(Color.FromArgb(0x79, 0x96, 0x89)),
        new ColorizerColorItem(Color.FromArgb(0xA2, 0xA8, 0x75)), 
        new ColorizerColorItem(Color.FromArgb(0xCE, 0xBB, 0x5F)),
        new ColorizerColorItem(Color.FromArgb(0xF2, 0xCB, 0x4E)),
        new ColorizerColorItem(Color.FromArgb(0xF1, 0xC1, 0x49)), 
        new ColorizerColorItem(Color.FromArgb(0xE5, 0xA8, 0x4D)),
        new ColorizerColorItem(Color.FromArgb(0xD6, 0x86, 0x4E)),
        new ColorizerColorItem(Color.FromArgb(0xC5, 0x64, 0x50)), 
        new ColorizerColorItem(Color.FromArgb(0xBA, 0x4D, 0x51))
    });

    // Specify range stops for the colorizer.
    colorizer.RangeStops.AddRange(new double[] { 0, 3000, 10000, 18000, 28000, 
        44000, 82000, 185000, 1000000, 2500000, 15000000 });

    // Specify the attribute that provides data values for the colorizer.
    colorizer.ValueProvider = new ShapeAttributeValueProvider() { AttributeName = "GDP_MD_EST" };

    return colorizer;
}
vb
' Create colorizer for the MapLayer.
    MapLayer.Colorizer = CreateColorizer()
Private Function CreateColorizer() As MapColorizer
    ' Create a Choropleth colorizer
    Dim colorizer As New ChoroplethColorizer()

    ' Specify colors for the colorizer.
    colorizer.ColorItems.AddRange(New ColorizerColorItem() { _
        New ColorizerColorItem(Color.FromArgb(&H5F, &H8B, &H95)), _
        New ColorizerColorItem(Color.FromArgb(&H79, &H96, &H89)), _
        New ColorizerColorItem(Color.FromArgb(&HA2, &HA8, &H75)), _
        New ColorizerColorItem(Color.FromArgb(&HCE, &HBB, &H5F)), _
        New ColorizerColorItem(Color.FromArgb(&HF2, &HCB, &H4E)), _
        New ColorizerColorItem(Color.FromArgb(&HF1, &HC1, &H49)), _
        New ColorizerColorItem(Color.FromArgb(&HE5, &HA8, &H4D)), _
        New ColorizerColorItem(Color.FromArgb(&HD6, &H86, &H4E)), _
        New ColorizerColorItem(Color.FromArgb(&HC5, &H64, &H50)), _
        New ColorizerColorItem(Color.FromArgb(&HBA, &H4D, &H51)) _
    })

    ' Specify range stops for the colorizer.
    colorizer.RangeStops.AddRange(New Double() { 0, 3000, 10000, 18000, 28000, 44000, 82000, 185000, 1000000, 2500000, 15000000 })

    ' Specify the attribute that provides data values for the colorizer.
    colorizer.ValueProvider = New ShapeAttributeValueProvider() With {.AttributeName = "GDP_MD_EST"}

    Return colorizer
End Function

Inheritance

Object MapDisposableObject ColorizerBase<IColorizerElement> MapColorizer PredefinedColorsColorizer GenericColorizer<ColorizerColorItem> ChoroplethColorizer

See Also

ChoroplethColorizer Members

DevExpress.XtraMap Namespace