1、前言
这篇博客主要介绍一下点密度填充
。准备一份面要素数据,其属性表如下图所示:
下面我们会使用A
和B
这两个值类型字段来实现点密度符号化。
2、实现代码
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using stdole;
using ESRI.ArcGIS.Geodatabase;
namespace Win
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
axMapControl1.AddShapeFile(@"C:\Users\DSF\Desktop\data", @"polygon.shp");
}
/// <summary>
/// 点密度填充符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDotDensityFillSymbol_Click(object sender, EventArgs e)
{
// 创建点密度填充符号
IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbol();
pDotDensityFillSymbol.DotSize = 5;
pDotDensityFillSymbol.BackgroundColor = CreateRgbColor(255, 0, 0);
// 字段A符号
ISymbolArray pSymbolArray = pDotDensityFillSymbol as ISymbolArray;
ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbol();
pSimpleMarkerSymbol.Color = CreateRgbColor(0, 255, 0);
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
pSymbolArray.AddSymbol(pSimpleMarkerSymbol as ISymbol);
// 字段B符号
pSimpleMarkerSymbol = new SimpleMarkerSymbol();
pSimpleMarkerSymbol.Color = CreateRgbColor(0, 0, 255);
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
pSymbolArray.AddSymbol(pSimpleMarkerSymbol as ISymbol);
// 添加字段
IDotDensityRenderer pDotDensityRenderer = new DotDensityRenderer() as IDotDensityRenderer;
IRendererFields pRendererFields = pDotDensityRenderer as IRendererFields;
pRendererFields.AddField("A", "A");
pRendererFields.AddField("B", "B");
// 设置渲染属性
pDotDensityRenderer.DotDensitySymbol = pDotDensityFillSymbol;
pDotDensityRenderer.DotValue = 5;
pDotDensityRenderer.CreateLegend();
// 刷新地图
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
pGeoFeatureLayer.Renderer = pDotDensityRenderer as IFeatureRenderer;
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 创建RGB颜色
/// </summary>
/// <param name="R"></param>
/// <param name="G"></param>
/// <param name="B"></param>
/// <returns></returns>
private IRgbColor CreateRgbColor(int R, int G, int B)
{
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = R;
pRgbColor.Green = G;
pRgbColor.Blue = B;
return pRgbColor;
}
}
}
运行结果如下图所示: