用过CAD的同志应该清楚,在CAD中可以指定对称轴,然后根据对称轴生成镜像,ArcEngine中也可以进行类似操作,如下图所示:
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
namespace WindowsFormsApplication1
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
axMapControl1.LoadMxFile(@"C:\Users\DSF\Desktop\data\无标题.mxd");
}
// 创建缓冲区
private void btnCreateGeometry_Click(object sender, EventArgs e)
{
// 线要素
IFeatureLayer pPolylineFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;
IFeatureClass pPolylineFeatureClass = pPolylineFeatureLayer.FeatureClass;
IPolyline pPolyline = pPolylineFeatureClass.GetFeature(0).Shape as IPolyline;
// 对称轴
ILine pLine = new Line();
pLine.PutCoords(pPolyline.FromPoint, pPolyline.ToPoint);
// 面要素
IFeatureLayer pPolygonFeatureLayer = axMapControl1.get_Layer(1) as IFeatureLayer;
IFeatureClass pPolygonFeatureClass = pPolygonFeatureLayer.FeatureClass;
// 绘制镜像
IFeatureCursor pPolygonFeatureCursor = pPolygonFeatureClass.Search(null, true);
IFeature pPolygonFeature = pPolygonFeatureCursor.NextFeature();
while (pPolygonFeature != null)
{
IGeometry pGeometry = CreateGeometry(pPolygonFeature.ShapeCopy, pLine);
Draw(pGeometry);
pPolygonFeature = pPolygonFeatureCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pPolygonFeatureCursor);
}
// 生成镜像实体
private IGeometry CreateGeometry(IGeometry pGeometry, ILine pLine)
{
IAffineTransformation2D pAffineTransformation2D = new AffineTransformation2D() as IAffineTransformation2D;
pAffineTransformation2D.DefineReflection(pLine);
ITransform2D pTransform2D = pGeometry as ITransform2D;
pTransform2D.Transform(esriTransformDirection.esriTransformForward, pAffineTransformation2D);
return pTransform2D as IGeometry;
}
// 绘制
private void Draw(IGeometry pGeometry)
{
IRgbColor pRgbColor = new RgbColor();
pRgbColor.Red = 0;
pRgbColor.Green = 255;
pRgbColor.Blue = 0;
// 创建符号
ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();
pSimpleFillSymbol.Color = pRgbColor;
// 创建元素
IFillShapeElement pFillShapeElement = new PolygonElement() as IFillShapeElement;
pFillShapeElement.Symbol = pSimpleFillSymbol;
IElement pElement = pFillShapeElement as IElement;
pElement.Geometry = pGeometry;
// 绘制元素
IActiveView pActiveView = axMapControl1.ActiveView;
IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
pGraphicsContainer.AddElement(pElement, 0);
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
}
}