ArcEngine创建缓冲区,并查询缓冲区内要素

来源:互联网 发布:java页面自动跳转代码 编辑:程序博客网 时间:2024/06/11 09:05

实现功能:

1.获取鼠标选中的要素

2.对选中要素设置缓冲距离,在地图上显示缓冲区

3.进行缓冲区查询,获得缓冲区内的要素,并放入TreeList展示

        /// <summary>        /// 创建缓冲区        /// </summary>        private void CreateBuffer()        {            ITopologicalOperator pTopo = null;            IElement pElement = null;            IGeometry pBuffer = null;            IGeometry pGeo = null;            ISelection pSelection = null;            IEnumFeatureSetup pEnumFeatureSetup = null;            IEnumFeature pEnumFeature = null;            IFillSymbol pFillSymbol = null;            IRgbColor pRgbColor = null;            IFeature pFea = null;            IFeature pFeature = null;            IFeatureLayer pFeaLayer = null;            IFeatureClass pFeaClass = null;            IFeatureCursor pFeaCursor = null;            ISpatialFilter pSpatialfilter = null;            try            {                if (m_pMap != null)                {                    (m_pMap as IGraphicsContainer).DeleteAllElements();                }                ////    获得选中要素                pSelection = m_pMap.FeatureSelection;                pEnumFeatureSetup = pSelection as IEnumFeatureSetup;                pEnumFeatureSetup.AllFields = true;                pEnumFeature = pEnumFeatureSetup as IEnumFeature;                pEnumFeature.Reset();                pFea = pEnumFeature.Next();                ////    遍历选中要素                while (pFea != null)                {                    pGeo = pFea.ShapeCopy;                    pTopo = pGeo as ITopologicalOperator;                    pBuffer = pTopo.Buffer(m_dDistance);                    pElement = new PolygonElementClass();                    pElement.Geometry = pBuffer;                    ////    设置缓冲区颜色                    pFillSymbol = new SimpleFillSymbolClass();                    pRgbColor = new RgbColorClass();                    pRgbColor.Red = 255;                    pRgbColor.Green = 255;                    pRgbColor.Blue = 153;                    pRgbColor.Transparency = 1;                    pFillSymbol.Color = pRgbColor;                    (pElement as IFillShapeElement).Symbol = pFillSymbol;                    (m_pMap as IGraphicsContainer).AddElement(pElement, 0);                    ////    设置空间过滤器                    pSpatialfilter = new SpatialFilterClass();                    pSpatialfilter.Geometry = pBuffer;                    ////    遍历图层                    for (int i = 0; i < m_pMap.LayerCount; i++)                    {                        pFeaLayer = m_pMap.get_Layer(i) as IFeatureLayer;                        pFeaClass = pFeaLayer.FeatureClass;                        switch (pFeaClass.ShapeType)                        {                            case esriGeometryType.esriGeometryPoint:                                {                                    pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;                                    break;                                }                            case esriGeometryType.esriGeometryPolyline:                                {                                    pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;                                    break;                                }                            case esriGeometryType.esriGeometryPolygon:                                {                                    pSpatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;                                    break;                                }                        }                        pSpatialfilter.GeometryField = pFeaClass.ShapeFieldName;                        pFeaCursor = pFeaClass.Search(pSpatialfilter, false);                        pFeature = pFeaCursor.NextFeature();                        TreeListNode tlNode = null;                        ////    查询到的要素添加到TreeList                        while (pFeature != null)                        {                            ////    添加图层节点到TreeList                            bool bIsContainLayer = false;                            foreach (TreeListNode node in tlResult.Nodes)                            {                                if (node.GetDisplayText(0).Equals(pFeaLayer.Name))                                {                                    tlNode = node;                                    bIsContainLayer = true;                                    break;                                }                            }                            if (!bIsContainLayer)                            {                                tlNode = tlResult.AppendNode(new object[] { pFeaLayer.Name }, null);                            }                            ////    添加要素到图层节点下                            bool bIsAdd = false;                            foreach (TreeListNode childnode in tlNode.Nodes)                            {                                if (childnode.GetDisplayText(0).Equals(pFeature.OID.ToString()))                                {                                    bIsAdd = true;                                    break;                                }                            }                            if (!bIsAdd)                            {                                tlResult.AppendNode(new object[] { pFeature.OID, GtMap.GxAEHelper.Feature.GetValue(pFeature, "NAME") }, tlNode);                            }                            pFeature = pFeaCursor.NextFeature();                        }                    }                    pFea = pEnumFeature.Next();                }                IActiveView pActiveView = m_pMap as IActiveView;                pActiveView.Refresh();            }            catch (Exception ex)            {            }        }



0 0
原创粉丝点击