public string[] strfname; //得到地圖內所有緩沖區內的地物名稱 public int n;//得到緩沖區內的個數 public void CreatBuffer(AxMapControl mc, double x, double y, double Dist, string sLayerName)//創造緩沖區函數 { IMap pMap = mc.Map; IActiveView pActiveView = (IActiveView)pMap; IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)pMap; ISimpleFillSymbol pFillSym = new SimpleFillSymbolClass(); IRgbColor pColor = new RgbColorClass(); pColor = getcolor(255, 255, 0, 255); ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1; pOutline.Color = pColor; pFillSym.Style = esriSimpleFillStyle.esriSFSCross; pFillSym.Color = pColor; pFillSym.Outline = pOutline; IPoint pPoint = new PointClass(); pPoint.PutCoords(x, y); ITopologicalOperator pTopol = (ITopologicalOperator)pPoint; IGeometry pBuffer = pTopol.Buffer(Dist); IFillShapeElement pFillEle = new CircleElementClass(); pFillEle.Symbol = pFillSym; IElement pEle = (IElement)pFillEle; pEle.Geometry = pBuffer; pGraphicsContainer.AddElement(pEle, 0);//畫出緩沖區圖形 ISpatialFilter pFilter=new SpatialFilter(); pFilter.Geometry=pBuffer; pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IQueryFilter pQueryFilter=pFilter as QueryFilter; IFeatureLayer pFeatureLayer; pFeatureLayer = mc.get_Layer(GetLayerFromName(sLayerName, mc)) as IFeatureLayer; if (pFeatureLayer == null) return; mc.Map.ClearSelection(); IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection; pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); ISelectionSet pSelection = pFeatureSelection.SelectionSet; n=pSelection.Count; strfname = new string[n]; int namenumber = 0; while (pFeature != null) { mc.FlashShape(pFeature.Shape, 1, 100, null); mc.DrawShape(pFeature.Shape); strfname[namenumber]=pFeature.get_Value(2).ToString(); mc.Map.SelectFeature(mc.get_Layer(GetLayerFromName(sLayerName, mc)), pFeature); pFeature = pFeatureCursor.NextFeature(); namenumber++; } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
更多GIS開發相關問題請加入 GIS開發學習QQ交流群 192251607 共同交流學習!