Applies to: Nevron Diagram for .NET (Map for .NET)
How to use range fill rule for coloring Maps in Nevron .NET Diagram?
Fill rules are used to colorize a map based on the values of a shape field. When creating a fill rule you must specify the shapefile it is used on, the fill rule data column name and the colors to use (all of them or only the first, the last and their count). There are two types of fill rules:
- Value fill rules - all unique values in the fill rule’s data column are extracted and each unique value is colorized with the respective color. If the unique values are more than the colors, then the color counting is restarted and some different values will have the same color.
- Range fill rules - these fill rules are only applicable to data columns containing numbers. All unique values in the fill rule’s data column are extracted and then are grouped in a specified number of classes using the grouping algorithm specified to the DataGrouping property.
You can easily create and add fill rules to the FillRules collection of your maps. The following example will help you create a map with a fill rule based on the Japan population per region:
[C#]
using
System;
using
System.Drawing;
using
System.IO;
using
System.Windows.Forms;
using
Nevron.Diagram;
using
Nevron.Diagram.Maps;
using
Nevron.GraphicsCore;
...
private
void
Form1_Load(
object
sender, EventArgs e)
{
view.ViewLayout = ViewLayout.Fit;
document.Style.FillStyle =
new
NColorFillStyle(Color.FromArgb(204, 255, 204));
document.Style.StrokeStyle =
new
NStrokeStyle(
new
NLength(0.75f, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119));
document.RoutingManager.Enabled =
false
;
document.BridgeManager.Enabled =
false
;
document.Bounds =
new
NRectangleF(0, 0, 2700, 2700);
document.BackgroundStyle.FillStyle =
new
NColorFillStyle(Color.White);
// create the map
NEsriMap m_Map =
new
NEsriMap();
// create the COUNTRIES shape file
NEsriShapefile countries = m_Map.Add(SHAPEFILE_NAME);
countries.NameColumn =
"GMI_ADMIN"
;
countries.TextColumn =
"ADMIN_NAME"
;
// read the map data
m_Map.Read();
// create a fill rule
NMapFillRuleRange fillRule =
new
NMapFillRuleRange(countries,
"POP_ADMIN"
, Color.Green, Color.White, 9);
fillRule.DataGrouping = DataGrouping.Optimal;
m_Map.FillRules.Add(fillRule);
// import the map data
m_Map.Import(document, document.Bounds);
// make the Map layer the active layer so that the user can select the map shapes
string
layerName = Path.GetFileNameWithoutExtension(SHAPEFILE_NAME);
NLayer mapLayer = (NLayer)document.Layers.GetChildByName(layerName);
document.ActiveLayerUniqueId = mapLayer.UniqueId;
// size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding);
}
// select the map shape file
private
const
string
SHAPEFILE_NAME = @
" C:\Maps\japan.shp"
;
[VB.NET]
Imports
System
Imports
System.Drawing
Imports
System.IO
Imports
System.Windows.Forms
Imports
Nevron.Diagram
Imports
Nevron.Diagram.Maps
Imports
Nevron.GraphicsCore
...
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
view.ViewLayout = ViewLayout.Fit
document.Style.FillStyle =
New
NColorFillStyle(Color.FromArgb(204, 255, 204))
document.Style.StrokeStyle =
New
NStrokeStyle(
New
NLength(0.75F, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119))
document.RoutingManager.Enabled =
False
document.BridgeManager.Enabled =
False
document.Bounds =
New
NRectangleF(0, 0, 2700, 2700)
document.BackgroundStyle.FillStyle =
New
NColorFillStyle(Color.White)
' create the map
Dim
m_Map
As
New
NEsriMap()
' create the COUNTRIES shape file
Dim
countries
As
NEsriShapefile = m_Map.Add(SHAPEFILE_NAME)
countries.NameColumn =
"GMI_ADMIN"
countries.TextColumn =
"ADMIN_NAME"
' read the map data
m_Map.Read()
' create a fill rule
Dim
fillRule
As
New
NMapFillRuleRange(countries,
"POP_ADMIN"
, Color.Green, Color.White, 9)
fillRule.DataGrouping = DataGrouping.Optimal
m_Map.FillRules.Add(fillRule)
' import the map data
m_Map.Import(document, document.Bounds)
' make the Map layer the active layer so that the user can select the map shapes
Dim
layerName
As
String
= Path.GetFileNameWithoutExtension(SHAPEFILE_NAME)
Dim
mapLayer
As
NLayer =
DirectCast
(document.Layers.GetChildByName(layerName), NLayer)
document.ActiveLayerUniqueId = mapLayer.UniqueId
' size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding)
End
Sub
' select the map shape file
Private
Const
SHAPEFILE_NAME
As
String
=
"C:\Maps\japan.shp"
The different data grouping methods are:
- Equal Distribution - also known as quantiles, this method allows for unequally sized data intervals and involves adjustment of the interval limits until an equal number of data points can be slotted into each interval.
- Equal Interval - also known as equal ranges (or steps), this method involves division of the entire data range into equally sized intervals.
- Optimal - adjusts the size of data intervals in order to minimize the classification error and thus the map looks more balanced and the results seem more correct, with just a few shapes in the highest class as one would expect.
Article ID: 169, Created On: 1/10/2011, Modified: 1/10/2011