1、前言
在ArcEngine
中,线要素的符号有很多种,如简单线
、制图线
、离散线
、点线
等等,下面开始介绍。
2、常用的线符号
2.1、简单线符号
2.2、离散线符号
2.3、制图线符号
2.4、点线线符号
2.5、叠加线符号
2.6、图片线符号
3、实现代码
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", @"polyline.shp");
}
/// <summary>
/// 简单线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSimpleLineSymbol_Click(object sender, EventArgs e)
{
// 创建颜色
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 255;
pRgbColor.Green = 0;
pRgbColor.Blue = 0;
// 创建符号
ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();
pSimpleLineSymbol.Color = pRgbColor;
pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
pSimpleLineSymbol.Width = 2;
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pSimpleLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 离散线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnHashLineSymbol_Click(object sender, EventArgs e)
{
// 创建颜色
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 255;
pRgbColor.Green = 0;
pRgbColor.Blue = 0;
// 创建符号
IHashLineSymbol pHashLineSymbol = new HashLineSymbol();
pHashLineSymbol.Angle = 0;
pHashLineSymbol.Color = pRgbColor;
pHashLineSymbol.Width = 5;
//
double[] nums = new double[6];
nums[0] = 0;
nums[1] = 1;
nums[2] = 2;
nums[3] = 3;
nums[4] = 4;
nums[5] = 5;
//
ITemplate pTemplate = new Template();
pTemplate.Interval = 1;
for (int i = 0; i < nums.Length; i += 2)
{
pTemplate.AddPatternElement(nums[i], nums[i + 1]);
}
// 设置符号属性
ILineProperties pLineProperties = pHashLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
pLineProperties.Template = pTemplate;
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pHashLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 制图线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCartographicLineSymbol_Click(object sender, EventArgs e)
{
// 创建颜色
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 255;
pRgbColor.Green = 0;
pRgbColor.Blue = 0;
// 创建符号
ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbol();
pCartographicLineSymbol.Color = pRgbColor;
pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound;
pCartographicLineSymbol.MiterLimit = 10;
pCartographicLineSymbol.Width = 5;
//
double[] nums = new double[6];
nums[0] = 0;
nums[1] = 1;
nums[2] = 2;
nums[3] = 3;
nums[4] = 4;
nums[5] = 5;
// 创建模板
ITemplate pTemplate = new Template();
pTemplate.Interval = 1;
for (int i = 0; i < nums.Length; i += 2)
{
pTemplate.AddPatternElement(nums[i], nums[i + 1]);
}
// 设置符号属性
ILineProperties pLineProperties = pCartographicLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
pLineProperties.Template = pTemplate;
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pCartographicLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 点线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnMarkerLineSymbol_Click(object sender, EventArgs e)
{
// 创建点颜色
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 0;
pRgbColor.Green = 255;
pRgbColor.Blue = 0;
// 创建点符号
ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbol();
pSimpleMarkerSymbol.Angle = 0;
pSimpleMarkerSymbol.Color = pRgbColor;
pSimpleMarkerSymbol.Size = 2;
pSimpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSX;
// 创建线符号
IMarkerLineSymbol pMarkerLineSymbol = new MarkerLineSymbol();
pMarkerLineSymbol.MarkerSymbol = pSimpleMarkerSymbol;
pMarkerLineSymbol.Width = 10;
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pMarkerLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 叠加线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnMultiLayerLineSymbol_Click(object sender, EventArgs e)
{
// 创建简单线颜色
IRgbColor pSimpleLineRgbColor = new RgbColor();
pSimpleLineRgbColor.Red = 255;
pSimpleLineRgbColor.Green = 0;
pSimpleLineRgbColor.Blue = 0;
// 创建简单线符号
ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();
pSimpleLineSymbol.Color = pSimpleLineRgbColor;
pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
pSimpleLineSymbol.Width = 2;
// 创建制图线颜色
IRgbColor pCartographicLineRgbColor = new RgbColor();
pCartographicLineRgbColor.Red = 0;
pCartographicLineRgbColor.Green = 255;
pCartographicLineRgbColor.Blue = 0;
// 创建制图线符号
ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbol();
pCartographicLineSymbol.Color = pCartographicLineRgbColor;
pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound;
pCartographicLineSymbol.MiterLimit = 10;
pCartographicLineSymbol.Width = 5;
//
double[] nums = new double[6];
nums[0] = 0;
nums[1] = 1;
nums[2] = 2;
nums[3] = 3;
nums[4] = 4;
nums[5] = 5;
// 创建模板
ITemplate pTemplate = new Template();
pTemplate.Interval = 1;
for (int i = 0; i < nums.Length; i += 2)
{
pTemplate.AddPatternElement(nums[i], nums[i + 1]);
}
// 设置符号属性
ILineProperties pLineProperties = pCartographicLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
pLineProperties.Template = pTemplate;
// 创建叠加线符号
IMultiLayerLineSymbol pMultiLayerLineSymbol = new MultiLayerLineSymbol();
pMultiLayerLineSymbol.AddLayer(pSimpleLineSymbol);
pMultiLayerLineSymbol.AddLayer(pCartographicLineSymbol);
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pMultiLayerLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
/// <summary>
/// 图片线符号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPictureLineSymbol_Click(object sender, EventArgs e)
{
IPictureLineSymbol pPictureLineSymbol = new PictureLineSymbol();
pPictureLineSymbol.CreateLineSymbolFromFile(esriIPictureType.esriIPicturePNG, @"C:\Users\DSF\Desktop\Driving_Directions16.png");
pPictureLineSymbol.Offset = 0;
pPictureLineSymbol.Width = 20;
// 设置符号
IGeoFeatureLayer pGeoFeatureLayer = axMapControl1.get_Layer(0) as IGeoFeatureLayer;
IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
pSimpleRenderer.Symbol = pPictureLineSymbol as ISymbol;
// 刷新地图
axMapControl1.Refresh();
axTOCControl1.Update();
}
}
}