111,097
社区成员




using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
namespace WinApp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
// 绘制按钮
private void btnDraw_Click(object sender, EventArgs e)
{
// 圆心
IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
pPoint.X = 400;
pPoint.Y = 400;
// 内部、外部半径
double innerRadius = 200;
double outerRadius = 300;
// 内部、外部圆
IGeometry pInnerCircleGeometry = CreateCircle(pPoint, innerRadius);
IGeometry pOuterCircleGeometry = CreateCircle(pPoint, outerRadius);
// 绘制圆环
IGeometry pRingGeometry = Erase(pOuterCircleGeometry, pInnerCircleGeometry);
CreateElement(axMapControl1.Object as IMapControlDefault, pRingGeometry);
}
// 根据圆心和半径创建一个圆
private IGeometry CreateCircle(IPoint pPoint, double radius)
{
// 创建圆的边界线
IConstructCircularArc pConstructCircularArc = new CircularArc() as IConstructCircularArc;
pConstructCircularArc.ConstructCircle(pPoint, radius, false);
ICircularArc pCircularArc = pConstructCircularArc as ICircularArc;
// 转换为片段集合
object missing = Type.Missing;
ISegment pSegment = pCircularArc as ISegment;
ISegmentCollection pSegmentCollection = new Ring() as ISegmentCollection;
pSegmentCollection.AddSegment(pSegment, ref missing, ref missing);
// 转换为环,闭合之
IRing pRing = pSegmentCollection as IRing;
pRing.Close();
// 返回地理实体
IGeometryCollection pGeometryCollection = new Polygon() as IGeometryCollection;
pGeometryCollection.AddGeometry(pRing, ref missing, ref missing);
IGeometry pGeometry = pGeometryCollection as IGeometry;
return pGeometry;
}
// 利用小圆对大圆进行擦除操作
private IGeometry Erase(IGeometry pSourceGeometry, IGeometry pEraseGeometry)
{
ITopologicalOperator pTopologicalOperator = pSourceGeometry as ITopologicalOperator;
IGeometry pGeometry = pTopologicalOperator.Difference(pEraseGeometry);
return pGeometry;
}
// 创建Element元素,添加到地图
private void CreateElement(IMapControlDefault mapControl, IGeometry pGeometry)
{
// 创建颜色
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 255;
pRgbColor.Green = 0;
pRgbColor.Blue = 0;
// 创建面符号
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();
pSimpleFillSymbol.Color = pRgbColor;
pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross;
// 创建面要素
IFillShapeElement pFillShapeElement = new PolygonElement() as IFillShapeElement;
pFillShapeElement.Symbol = pSimpleFillSymbol;
IElement pElement = pFillShapeElement as IElement;
pElement.Geometry = pGeometry;
// 添加至地图
IActiveView pActiveView = mapControl.ActiveView;
IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
pGraphicsContainer.DeleteAllElements();
pGraphicsContainer.AddElement(pElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
}