using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
//using TextSymbols;
using ESRI.ArcGIS.Controls;
//using 符号化.Annotation;
//using 符号化.Class;
//using 符号化;
using ESRI.ArcGIS.Animation;
using ESRI.ArcGIS.esriSystem;
//using 符号选择器;
using stdole;
using ESRI.ArcGIS.SystemUI;
using _5_3线状要素的符号化.Class;
namespace _5_3线状要素的符号化
{
public partial class Form1 : Form
{
private OperateMap m_OperateMap = null;
public string filepath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
public Form1()
{
InitializeComponent();
m_OperateMap = new OperateMap();
}
public IRgbColor GetRgbColor(int intR, int intG, int intB)
{
IRgbColor pRgbColor = null;
if (intR < 0 || intR > 255 || intG < 0 || intG > 255 || intB < 0 || intB > 255)
{
return pRgbColor;
}
pRgbColor = new RgbColorClass();
pRgbColor.Red = intR;
pRgbColor.Green = intG;
pRgbColor.Blue = intB;
return pRgbColor;
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
ICommand Cmd = new ControlsOpenDocCommandClass();
Cmd.OnCreate(mainMapControl.Object);
Cmd.OnClick();
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveMap(mainMapControl.DocumentFilename, mainMapControl.Map);
}
private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
{
ICommand Cmd = new ControlsSaveAsDocCommandClass();
Cmd.OnCreate(mainMapControl.Object);
Cmd.OnClick();
}
public void SaveMap(string m_FilePath, IMap m_SaveMap)
{
try
{
IMapDocument pMapDoc = new MapDocumentClass();
IMxdContents pMxdC = m_SaveMap as IMxdContents;
pMapDoc.New(m_FilePath);
pMapDoc.ReplaceContents(pMxdC);
if (pMapDoc.get_IsReadOnly(pMapDoc.DocumentFilename) == true)
{
MessageBox.Show("本地图文档是只读的,不能保存!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
pMapDoc.Save(pMapDoc.UsesRelativePaths, true);
}
catch (Exception ex)
{
}
}
private void SimpleLine_Click(object sender, EventArgs e)
{
try
{
//获取目标图层
ILayer pLayer = new FeatureLayerClass();
pLayer = mainMapControl.get_Layer(1);
IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;
//设置线符号
ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass();
simpleLineSymbol.Width = 0;//定义线的宽度
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSInsideFrame; //定义线的样式
simpleLineSymbol.Color = GetRgbColor(255, 100, 0);//定义线的颜色
ISymbol symbol = simpleLineSymbol as ISymbol;
//更改符号样式
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = symbol;
pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer;
mainMapControl.Refresh();
mainTOCControl.Update();
}
catch (Exception ex)
{
}
}
private void CartographicLine_Click(object sender, EventArgs e)
{
try
{
//获取目标图层
ILayer pLayer = new FeatureLayerClass();
pLayer = mainMapControl.get_Layer(1);
IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;
//设置线符号
ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbolClass();
pCartographicLineSymbol.Cap = esriLineCapStyle.esriLCSRound;//设置线要素首尾端点形状为圆形
pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound; //设置线要素转折点出的样式为圆滑
pCartographicLineSymbol.Width = 2;
//设置线要素符号模板
ILineProperties pLineProperties;
pLineProperties = pCartographicLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
double[] dob = new double[6];
dob[0] = 0;
dob[1] = 1;
dob[2] = 2;
dob[3] = 3;
dob[4] = 4;
dob[5] = 5;
ITemplate pTemplate = new TemplateClass();
pTemplate.Interval = 1;
for (int i = 0; i < dob.Length; i += 2)
{
pTemplate.AddPatternElement(dob[i], dob[i + 1]);
}
pLineProperties.Template = pTemplate;
IRgbColor pRgbColor = GetRgbColor(0, 255, 0);
pCartographicLineSymbol.Color = pRgbColor;
//更改符号样式
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = pCartographicLineSymbol as ISymbol;
pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer;
mainMapControl.Refresh();
mainTOCControl.Update();
}
catch
{ }
}
private void MultiLayerLine_Click(object sender, EventArgs e)
{
try
{
//获取目标图层
ILayer pLayer = new FeatureLayerClass();
pLayer = mainMapControl.get_Layer(1);
IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;
//设置线符号
IMultiLayerLineSymbol pMultiLayerLineSymbol = new MultiLayerLineSymbolClass();
ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;
pSimpleLineSymbol.Width = 2;
IRgbColor pRgbColor = GetRgbColor(255, 0, 0);
pSimpleLineSymbol.Color = pRgbColor;
//ISymbol pSymbol = pSimpleLineSymbol as ISymbol;
//pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; //设置线要素的颜色为
ICartographicLineSymbol pCartographicLineSymbol = new CartographicLineSymbolClass();
pCartographicLineSymbol.Cap = esriLineCapStyle.esriLCSRound;
pCartographicLineSymbol.Join = esriLineJoinStyle.esriLJSRound;
pCartographicLineSymbol.Width = 2;
ILineProperties pLineProperties;
pLineProperties = pCartographicLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
double[] dob = new double[6];
dob[0] = 0;
dob[1] = 1;
dob[2] = 2;
dob[3] = 3;
dob[4] = 4;
dob[5] = 5;
ITemplate pTemplate = new TemplateClass();
pTemplate.Interval = 1;
for (int i = 0; i < dob.Length; i += 2)
{
pTemplate.AddPatternElement(dob[i], dob[i + 1]);
}
pLineProperties.Template = pTemplate;
pRgbColor = GetRgbColor(0, 255, 0);
pCartographicLineSymbol.Color = pRgbColor;
pMultiLayerLineSymbol.AddLayer(pSimpleLineSymbol);
pMultiLayerLineSymbol.AddLayer(pCartographicLineSymbol);
//更改符号样式
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = pMultiLayerLineSymbol as ISymbol;
pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer;
mainMapControl.Refresh();
mainTOCControl.Update();
}
catch { }
}
private void PictureLine_Click(object sender, EventArgs e)
{
try
{
//获取目标图层
ILayer pLayer = new FeatureLayerClass();
pLayer = mainMapControl.get_Layer(1);
IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;
//设置线符号
IPictureLineSymbol pictureLineSymbol = new PictureLineSymbolClass();
//创建图片符号
string fileName = m_OperateMap.getPath(filepath) + "\\data\\Symbol\\border.bmp";
pictureLineSymbol.CreateLineSymbolFromFile(esriIPictureType.esriIPictureBitmap, fileName);
IRgbColor rgbColor = GetRgbColor(255, 0, 0);
pictureLineSymbol.Color = rgbColor;
pictureLineSymbol.Offset = 0;
pictureLineSymbol.Width = 3;
pictureLineSymbol.Rotate = false;
//更改符号样式
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = pictureLineSymbol as ISymbol;
pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer;
mainMapControl.Refresh();
mainTOCControl.Update();
}
catch { }
}
private void HashLine_Click(object sender, EventArgs e)
{
try
{
//获取目标图层
ILayer pLayer = new FeatureLayerClass();
pLayer = mainMapControl.get_Layer(1);
IGeoFeatureLayer pGeoFeatLyr = pLayer as IGeoFeatureLayer;
//设置线符号
IHashLineSymbol pHashLineSymbol = new HashLineSymbolClass();
ILineProperties pLineProperties = pHashLineSymbol as ILineProperties;
pLineProperties.Offset = 0;
double[] dob = new double[6];
dob[0] = 0;
dob[1] = 1;
dob[2] = 2;
dob[3] = 3;
dob[4] = 4;
dob[5] = 5;
ITemplate pTemplate = new TemplateClass();
pTemplate.Interval = 1;
for (int i = 0; i < dob.Length; i += 2)
{
pTemplate.AddPatternElement(dob[i], dob[i + 1]);
}
pLineProperties.Template = pTemplate;
pHashLineSymbol.Width = 2;
pHashLineSymbol.Angle = 45;//设置单一线段的倾斜角度
IRgbColor pColor = new RgbColor();
pColor = GetRgbColor(0, 0, 255);
pHashLineSymbol.Color = pColor;
//更改符号样式
ISimpleRenderer pSimpleRenderer = new SimpleRendererClass();
pSimpleRenderer.Symbol = pHashLineSymbol as ISymbol;
pGeoFeatLyr.Renderer = pSimpleRenderer as IFeatureRenderer;
mainMapControl.Refresh();
mainTOCControl.Update();
}
catch { }
}
}
}
VS2010 AE--------线状要素的符号化
最新推荐文章于 2024-06-25 10:11:52 发布