AE二次开发之缓冲区分析
个人学习使用
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
if (Button != 1 || m_hookHelper.FocusMap.LayerCount <= 0)
return;
IActiveView pActiveView = m_hookHelper.ActiveView;
IGraphicsContainer pGraCont = (IGraphicsContainer)pActiveView;
//删除地图上添加的所有Element
pGraCont.DeleteAllElements();
//获得点击位置并转化为点图形要素
IPoint pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
//获得地图中图层
IFeatureLayer pFeatureLayer = m_hookHelper.FocusMap.get_Layer(0) as IFeatureLayer;
if (pFeatureLayer == null)
{
return;
}
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
//进行点击,查询图层要素
ISpatialFilter pSpatialFilter = new SpatialFilterClass();
pSpatialFilter.Geometry = pPoint;
pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
IFeatureCursor featureCursor = pFeatureClass.Search(pSpatialFilter, false);
//获得点击查询的要素
IFeature pFeature = featureCursor.NextFeature();
if (pFeature != null && pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
{
IGeometry pGeometry = pFeature.Shape as IGeometry;
//通过ITopologicalOperator接口进行多边形的简单化处理
ITopologicalOperator pTopoOpe = (ITopologicalOperator)pGeometry;
pTopoOpe.Simplify();
//通过创建缓冲区相关
IGeometry pBufferGeo = pTopoOpe.Buffer(5000);
//创建多边形符号样式并添加到地图上
IScreenDisplay pdisplay = pActiveView.ScreenDisplay;
ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass();
pSymbol.Style = esriSimpleFillStyle.esriSFSCross;
RgbColor pColor = new RgbColorClass();
pColor.Blue = 200;
pColor.Red = 211;
pColor.Green = 100;
pSymbol.Color = (IColor)pColor;
//创建多边形渲染效果的Element
IFillShapeElement pFillShapeElm = new PolygonElementClass();
IElement pElm = (IElement)pFillShapeElm;
pElm.Geometry = pBufferGeo;
pFillShapeElm.Symbol = pSymbol;
//将渲染之后的多边形Element添加到地图IGraphicsContainer层中
pGraCont.AddElement((IElement)pFillShapeElm, 0);
}
//刷新整个Element
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}