//在鹰眼地图上面画矩形框 public static void DrawRectangle(IEnvelope pIEnvelope) { //在绘制前,清除鹰眼中之前绘制的矩形框 IGraphicsContainer pGraphicsContainer = Variable.pEagleEyeMapFrm.EagelEyeMapControl.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; pGraphicsContainer.DeleteAllElements(); //得到当前视图范围 IRectangleElement pRectangleElement = new RectangleElementClass(); IElement pElement = pRectangleElement as IElement; pElement.Geometry = pIEnvelope; //设置矩阵框(实质为中间透明度面) IRgbColor pRgbColor = new RgbColorClass(); pRgbColor = GetRgbColor(255, 0, 0); pRgbColor.Transparency = 255; ILineSymbol pOutLine = new SimpleLineSymbolClass(); pOutLine.Width = 2; pOutLine.Color = pRgbColor; IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pRgbColor = new RgbColorClass(); pRgbColor.Transparency = 0; pFillSymbol.Color = pRgbColor; pFillSymbol.Outline = pOutLine; //向鹰眼中添加矩形框 IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0); //刷新 pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public static IElement CreatePolygonElement(IActiveView pActiveView, IGeometry pGeo) { Random rnd = new Random(); IRgbColor color = new RgbColorClass(); color.Blue = rnd.Next(0, 255); color.Green = rnd.Next(0, 255); color.Red = rnd.Next(0, 255); IColor color2 = color; ISimpleLineSymbol symbol = new SimpleLineSymbolClass(); symbol.Style = esriSimpleLineStyle.esriSLSSolid; symbol.Color = color2; symbol.Width = 2.0; ISimpleFillSymbol symbol2 = new SimpleFillSymbolClass(); symbol2.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal; IRgbColor color3 = new RgbColorClass(); color.Blue = rnd.Next(0, 255); color.Green = rnd.Next(0, 255); color.Red = rnd.Next(0, 255); symbol2.Color = color3; symbol2.Outline = symbol; pGeo = ErrManager.ConvertPoject(pGeo, pActiveView.FocusMap.SpatialReference); ISimpleFillSymbol symbol3 = symbol2; IElement element = new PolygonElementClass(); element.Geometry = pGeo; IFillShapeElement element2 = element as IFillShapeElement; element2.Symbol = symbol3; return(element); }
/// <summary> /// 当主图视野发生变化时,重新绘制鸟瞰图中的红色矩形框 /// </summary> private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { // 得到新范围 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; //在绘制前,清除axMapControl2中的任何图形元素 pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelope; //设置鹰眼图中的红线框 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 3; pOutline.Color = pColor; //设置颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; //设置填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);//部分刷新 }
public static IElement CreateElement(IGeometry pGeometry, IRgbColor linecolor, IRgbColor fillcolor) { if (pGeometry == null || linecolor == null || fillcolor == null) { return(null); } IElement pEle = null; if (pGeometry == null) { return(null); } //限制只能创建面要素 pEle = new PolygonElementClass(); pEle.Geometry = pGeometry; IFillShapeElement pFillEle = pEle as IFillShapeElement; ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); symbol.Color = fillcolor; symbol.Outline.Color = linecolor; symbol.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal; if (symbol == null) { return(null); } pFillEle.Symbol = symbol; return(pEle); }
/// <summary> /// 使用面要素刷新(存在覆盖注释问题) /// </summary> /// <param name="pGraphicsContainer"></param> /// <param name="pActiveView"></param> /// <param name="pElement"></param> private static void DrawPolyline2(IGraphicsContainer pGraphicsContainer, IActiveView pActiveView, IElement pElement) { //以下代码设置要素外框边线的颜色、透明度属性 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; //以下代码设置要素外框边线的颜色、宽度属性 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 2; pOutline.Color = pColor; pColor = new RgbColorClass(); pColor.NullColor = true; //以下代码设置要素内部的填充颜色、边线符号属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; //实现线框的生成 IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0); //刷新鹰眼视图的填充要素(绘图框) pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pFillShapeElement, null); }
private void AddPolygonElement(IGeometry geo, IActiveView pAV) { IElement pElem = new PolygonElement(); pElem.Geometry = geo; ISimpleFillSymbol pSFSym = new SimpleFillSymbol(); Color color = ColorTranslator.FromHtml(SystemInfo.Instance.FillColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; pSFSym.Color = pColor; pSFSym.Style = esriSimpleFillStyle.esriSFSDiagonalCross; ISimpleLineSymbol pSLSym = new SimpleLineSymbol(); pSLSym.Style = esriSimpleLineStyle.esriSLSSolid; pSLSym.Width = 1; pSLSym.Color = pColor; pSFSym.Outline = pSLSym; IFillShapeElement pElemFillShp = pElem as IFillShapeElement; pElemFillShp.Symbol = pSFSym; pGraphicsContainer = pAV as IGraphicsContainer; pGraphicsContainer.AddElement(pElem, 0); }
private IElement method_1() { object missing = System.Type.Missing; IPointCollection points = null; IElement element = new PolygonElementClass(); IFillShapeElement element2 = element as IFillShapeElement; new RgbColorClass(); IGeometry inGeometry = new RingClass(); IGeometry geometry2 = null; IGeometryCollection geometrys = new PolygonClass(); IGeometry geometry3 = null; points = (IPointCollection)inGeometry; points.AddPoint(base.LeftLow, ref missing, ref missing); points.AddPoint(base.RightLow, ref missing, ref missing); points.AddPoint(base.RightUp, ref missing, ref missing); points.AddPoint(base.LeftUp, ref missing, ref missing); points.AddPoint(base.LeftLow, ref missing, ref missing); geometry2 = this.method_2(); if (!geometry2.IsEmpty) { geometrys.AddGeometry(inGeometry, ref missing, ref missing); geometrys.AddGeometry(geometry2, ref missing, ref missing); } geometry3 = geometrys as IGeometry; if (!geometry3.IsEmpty) { geometry3.SpatialReference = geometry2.SpatialReference; element.Geometry = geometry3; element2.Symbol = this.method_7(); } return(element); }
/// <summary> /// 单击颜色单元格选颜色 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SC_dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == SC_dataGridView.Columns["color"].Index && e.RowIndex != -1) { SC_dataGridView.ClearSelection(); ColorDialog cd = new ColorDialog(); if (cd.ShowDialog() == DialogResult.OK) { SC_dataGridView.Rows[e.RowIndex].Cells["color"].Style.BackColor = cd.Color; //根据选中颜色新建绘制图形的填充符号 IRgbColor arccolor = new RgbColorClass(); arccolor.RGB = cd.Color.B * 65536 + cd.Color.G * 256 + cd.Color.R; ILineSymbol outline = new SimpleLineSymbolClass(); outline.Width = 3; outline.Color = arccolor; IFillSymbol fillsymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol pFillsyl = fillsymbol as ISimpleFillSymbol; pFillsyl.Style = esriSimpleFillStyle.esriSFSNull; fillsymbol.Outline = outline; IPolygonElement PolygonElement = new PolygonElementClass(); IElement pElement = PolygonElement as IElement; pElement.Geometry = SC_dataGridView.Rows[e.RowIndex].Cells["color"].Tag as IGeometry; IFillShapeElement FillShapeElement = pElement as IFillShapeElement; FillShapeElement.Symbol = fillsymbol; IGraphicsContainer pGraphicsContainer = main.getMapControl().Map as IGraphicsContainer; pGraphicsContainer.AddElement((IElement)PolygonElement, 0); main.getMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } } }
private void frmOverwindows_Load(object sender, EventArgs e) { this.axMapControl1.ShowScrollbars = false; this.m_pElement = new RectangleElementClass(); this.m_pFillSymbol = new SimpleFillSymbolClass(); ((ISimpleFillSymbol)this.m_pFillSymbol).Style = esriSimpleFillStyle.esriSFSNull; ILineSymbol symbol = new SimpleLineSymbolClass(); IRgbColor color = new RgbColorClass { Red = 0, Green = 0, Blue = 255 }; symbol.Color = color; symbol.Width = 1.0; this.m_pFillSymbol.Outline = symbol; IFillShapeElement pElement = this.m_pElement as IFillShapeElement; pElement.Symbol = this.m_pFillSymbol; this.axMapControl1.ActiveView.GraphicsContainer.AddElement(this.m_pElement, 0); this.m_CanDo = true; this.SetMainAvtiveView(this.m_pMainMapControl.ActiveView); this.Init(); }
//主地图:地图范围(Extent)变化 private void axMapControlMainMap_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { #region 主地图地图范围Extent变化时,鹰眼中的地图范围Extent也跟随着变化 IEnvelope envelope = (IEnvelope)e.newEnvelope; //得到主地图的新范围 IGraphicsContainer graphicsContainer = axMapControlEagleMap.Map as IGraphicsContainer; IActiveView activeView = graphicsContainer as IActiveView; graphicsContainer.DeleteAllElements(); //在绘制前,清除axMapControlEagleMap中的任何图形元素 IRectangleElement rectangleElement = new RectangleElement() as IRectangleElement; IElement element = rectangleElement as IElement; element.Geometry = envelope; //产生一个线符号对象,设置鹰眼中的红线框 ILineSymbol lineSymbol = new SimpleLineSymbol(); lineSymbol.Width = 1.6; lineSymbol.Color = RenderOpt.GetIColor(255, 0, 0); //设置填充符号的属性 IFillSymbol fillSymbol = new SimpleFillSymbol(); fillSymbol.Color = RenderOpt.GetIColor(255, 0, 0, 0); fillSymbol.Outline = lineSymbol; IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = fillSymbol; graphicsContainer.AddElement((IElement)fillShapeElement, 0); //刷新 envelope.Expand(2, 2, true); activeView.Extent = envelope; activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); #endregion }
private void method_9(IActiveView pView, IPoint point, double num, bool flag, IRgbColor color) { this.method_8(point, num, flag); ISegmentCollection segmentCollection = new Polygon() as ISegmentCollection; ICircularArc circularArc = this.method_8(point, num, flag); object missing = Type.Missing; segmentCollection.AddSegment(circularArc as ISegment, ref missing, ref missing); ICircleElement circleElement = new CircleElement() as ICircleElement; IElement element = (IElement)circleElement; element.Geometry = (segmentCollection as IGeometry); IFillShapeElement fillShapeElement = (IFillShapeElement)circleElement; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(); ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(); simpleLineSymbol.Color = (color); simpleLineSymbol.Width = (2.0); simpleLineSymbol.Style = (0); simpleFillSymbol.Color = (color); simpleFillSymbol.Style = (esriSimpleFillStyle)(1); simpleFillSymbol.Outline = (simpleLineSymbol); fillShapeElement.Symbol = (simpleFillSymbol); IGraphicsContainer graphicsContainer = (IGraphicsContainer)pView; graphicsContainer.AddElement((IElement)circleElement, 0); }
///////////////////////////////////////// private void axMapControl_sub_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { //实现鹰眼的方框的 symbol 部分 ILineSymbol outLineSymbol = new SimpleLineSymbol(); //设置鹰眼图中的红线! outLineSymbol.Width = 2; outLineSymbol.Color = GetColor(255, 0, 0, 255); IFillSymbol fillSymbol = new SimpleFillSymbol(); //设置填充符号的属性! fillSymbol.Color = GetColor(255, 0, 0, 0); //设置完全透明色 fillSymbol.Outline = outLineSymbol; //实现信息传递 IEnvelope envlope2 = e.newEnvelope as IEnvelope; IElement element2 = new RectangleElement(); element2.Geometry = envlope2; IFillShapeElement fillShapeElement2 = element2 as IFillShapeElement; fillShapeElement2.Symbol = fillSymbol; IGraphicsContainer graphicsContainer2 = axMapControl_sub.Map as IGraphicsContainer; graphicsContainer2.DeleteAllElements(); IElement pElement = fillShapeElement2 as IElement; graphicsContainer2.AddElement(pElement, 0); axMapControl_sub.Refresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// 三维场景中绘制面要素 20110609 /// </summary> /// <param name="pGeometry">面要素</param> /// <param name="r"></param> /// <param name="g"></param> /// <param name="b"></param> /// <param name="Z"></param> /// <param name="Width"></param> /// <returns></returns> public static IElement DrawPolygonZ(IGeometry pGeometry, int r, int g, int b, int Z, double Width) { IPolygon pEnvPolygon = (IPolygon)pGeometry; IZAware pZAware = (IZAware)pEnvPolygon; ((IZAware)pZAware).ZAware = true; IZ pZ = (IZ)pEnvPolygon; pZ.SetConstantZ(Z); IElement pElement; IPolygonElement pPolygonElement = new PolygonElementClass(); pElement = pPolygonElement as IElement; IFillShapeElement pFillShapeElement = pPolygonElement as IFillShapeElement; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; pSimpleFillSymbol.Color = getRGB(r, g, b); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; pSimpleLineSymbol.Color = getRGB(r, g, b); pSimpleLineSymbol.Color.Transparency = 10; pSimpleLineSymbol.Width = Width; ISymbol pSymbol = pSimpleLineSymbol as ISymbol; pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pSimpleFillSymbol.Outline = pSimpleLineSymbol; pElement.Geometry = pZ as IGeometry; pFillShapeElement.Symbol = pSimpleFillSymbol; return(pElement); }
/// <summary> /// 主窗体视图范围变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e) { //获得当前地图视图的外包矩形 IEnvelope pEnvelope = (IEnvelope)e.newEnvelope; //获得GraphicsContainer对象用来管理元素对象 IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; //清除对象中的所有图形元素 pGraphicsContainer.DeleteAllElements(); //获得矩形图形元素 IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pElement = pRectangleEle as IElement; pElement.Geometry = pEnvelope; //设置FillShapeElement对象的symbol IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = this.Presenter.getFillSymbol(); //进行填充 pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); //刷新视图 IActiveView pActiveView = pGraphicsContainer as IActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void AddRegion(AxMapControl axMapControl1, IGeometry GeomArea) { IPolygonElement ipPolygonElem = new PolygonElementClass(); ILineSymbol ipLine = new SimpleLineSymbolClass(); ipLine.Width = 1; IRgbColor ipColor = new RgbColorClass(); ipColor.RGB = 0x0000ff; ipLine.Color = ipColor; ISimpleFillSymbol ipFillSym = new SimpleFillSymbolClass(); IRgbColor ipColorFill = new RgbColorClass(); ipColorFill.RGB = 0xff0000; ipFillSym.Outline = ipLine; ipFillSym.Color = ipColorFill; ipFillSym.Style = esriSimpleFillStyle.esriSFSCross; IFillShapeElement ipShape = ipPolygonElem as IFillShapeElement; ipShape.Symbol = ipFillSym; IElement ipElement = ipPolygonElem as IElement; ipElement.Geometry = GeomArea; axMapControl1.ActiveView.GraphicsContainer.AddElement(ipElement, 0); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, ipElement, null); }
private void DrawRectangle(IEnvelope pEnvelope) { IGraphicsContainer pGraphicsContainer = axMapControl2.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; pGraphicsContainer.DeleteAllElements(); IRectangleElement pRectangleElement = new RectangleElementClass(); IElement pElement = pRectangleElement as IElement; pElement.Geometry = pEnvelope; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pRgbColor.Blue = 0; pRgbColor.Green = 0; pRgbColor.Transparency = 255; ILineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Width = 3; pLineSymbol.Color = pRgbColor; pRgbColor.Red = 255; pRgbColor.Blue = 0; pRgbColor.Green = 0; pRgbColor.Transparency = 0; IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Outline = pLineSymbol; pFillSymbol.Color = pRgbColor; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void mainMapControl_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { IEnvelope pEnvelope = e.newEnvelope as IEnvelope; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDash; pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Color = this.getRGBColor(0, 0, 0); ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Color = this.getRGBColor(255, 0, 0); pSimpleFillSymbol.Outline = pSimpleLineSymbol as ILineSymbol; pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; IRectangleElement pRectangleElement = new RectangleElementClass(); IElement pElement = pRectangleElement as IElement; pElement.Geometry = pEnvelope as IGeometry; IFillShapeElement pFillShapeElement = pRectangleElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol as IFillSymbol; IGraphicsContainer pGraphicsContainer = this.EagleaxMapControl.Map as IGraphicsContainer; pGraphicsContainer.DeleteAllElements(); pGraphicsContainer.AddElement(pElement, 0); this.EagleaxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void DrawEagleExtent(IEnvelope myEnvelope) { if (EnviVars.instance.EagleVisible) { this._mapControlEagle.ActiveView.GraphicsContainer.DeleteAllElements(); IRectangleElement rectangleElement = new RectangleElementClass(); IElement element = rectangleElement as IElement; element.Geometry = myEnvelope; IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Green = 0; rgbColor.Blue = 0; ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = rgbColor; lineSymbol.Width = 1.5; IRgbColor rgbColor2 = new RgbColorClass(); rgbColor2.Transparency = 0; IFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Color = rgbColor2; fillSymbol.Outline = lineSymbol; IFillShapeElement fillShapeElement = rectangleElement as IFillShapeElement; fillShapeElement.Symbol = fillSymbol; this._mapControlEagle.ActiveView.GraphicsContainer.AddElement(element, 0); this._mapControlEagle.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
/// <summary> /// 根据mapcontrol绘制的多边形在样本表格中生成样本 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BegineCreateSample(IGeometry SampleGeometry) { IPolygon polygon = (IPolygon)SampleGeometry; if (SampleLayerCombox.Tag != null) { //计算像元数 IArea area = polygon as IArea; IGeoDataset geodataset = SampleLayerCombox.Tag as IGeoDataset; IRaster raster = geodataset as IRaster; IRasterProps rasterprops = raster as IRasterProps; double pixelcount = System.Math.Abs(area.Area) / (rasterprops.MeanCellSize().X *rasterprops.MeanCellSize().Y); //生成表格 if (SC_dataGridView.ColumnCount == 0) { SC_dataGridView.Columns.Add("ID", "ID"); SC_dataGridView.Columns.Add("name", "样本名称"); SC_dataGridView.Columns.Add("value", "样本值"); SC_dataGridView.Columns.Add("color", "样本颜色"); SC_dataGridView.Columns.Add("count", "像元数(近似值)"); } SC_dataGridView.Rows.Add(); SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["ID"].Value = SC_dataGridView.Rows.Count; SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["name"].Value = "样本" + (SC_dataGridView.Rows.Count).ToString(); SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["value"].Value = (SC_dataGridView.Rows.Count).ToString(); SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["count"].Value = Convert.ToInt32(pixelcount) + 1; //生成随机色 Random random = new Random(); Color linecolor = new Color(); linecolor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)); //填充单元格颜色 SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["color"].Style.BackColor = linecolor; //将polygon存放到gridview表color列对应的tag中 SC_dataGridView.Rows[SC_dataGridView.Rows.Count - 1].Cells["color"].Tag = polygon; //新建绘制图形的填充符号 IRgbColor arccolor = new RgbColorClass(); arccolor.RGB = linecolor.B * 65536 + linecolor.G * 256 + linecolor.R; ILineSymbol outline = new SimpleLineSymbolClass(); outline.Width = 3; outline.Color = arccolor; IFillSymbol fillsymbol = new SimpleFillSymbolClass(); ISimpleFillSymbol pFillsyl = fillsymbol as ISimpleFillSymbol; pFillsyl.Style = esriSimpleFillStyle.esriSFSNull; fillsymbol.Outline = outline; IPolygonElement PolygonElement = new PolygonElementClass(); IElement pElement = PolygonElement as IElement; pElement.Geometry = SampleGeometry; IFillShapeElement FillShapeElement = pElement as IFillShapeElement; FillShapeElement.Symbol = fillsymbol; IGraphicsContainer pGraphicsContainer = main.getMapControl().Map as IGraphicsContainer; pGraphicsContainer.AddElement((IElement)PolygonElement, 0); main.getMapControl().ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); } }
/// <summary> /// 根据输入的要素在SceneControl中绘制元素 张琪 20110621 /// </summary> /// <param name="pSceneControl"></param> /// <param name="pGeom">几何要素</param> /// <param name="pSym"></param> public void AddGraphic(ISceneControl pSceneControl, IGeometry pGeom, ISymbol pSym) { if (pGeom == null) { return; } IElement pElement = null; switch (pGeom.GeometryType.ToString()) { case "esriGeometryPoint": //点要素 pElement = new MarkerElementClass(); IMarkerElement pPointElement = pElement as IMarkerElement; if (pSym != null) { IMarkerSymbol pMarker3DSymbol = pSym as IMarkerSymbol; pPointElement.Symbol = pMarker3DSymbol as IMarkerSymbol; } break; case "esriGeometryPolyline": //线要素 pElement = new LineElementClass(); ILineElement pLineElement = pElement as ILineElement; if (pSym != null) { ILineSymbol pLineSymbol = pSym as ILineSymbol; pLineElement.Symbol = pLineSymbol; } break; case "esriGeometryPolygon": //面要素 pElement = new PolygonElementClass(); IFillShapeElement pFillElement = pElement as IFillShapeElement; if (pSym != null) { IFillSymbol pFillSymbol = pSym as IFillSymbol; pFillElement.Symbol = pFillSymbol; } break; case "esriGeometryMultiPatch": //多面体要素 pElement = new MultiPatchElementClass(); IFillShapeElement pMultiPatchElement = pElement as IFillShapeElement; if (pSym != null) { IFillSymbol pFillSymbol = pSym as IFillSymbol; pMultiPatchElement.Symbol = pFillSymbol as IFillSymbol; } break; } pElement.Geometry = pGeom; IGraphicsContainer3D pGCon3D = pSceneControl.Scene.BasicGraphicsLayer as IGraphicsContainer3D; pGCon3D.AddElement(pElement);//在SceneControl中绘制要素 IGraphicsSelection pGS = pGCon3D as IGraphicsSelection; pSceneControl.Scene.SceneGraph.RefreshViewers(); }
/// <summary> /// 生成缓冲区 /// </summary> /// <param name="pGeometry"></param> /// <returns></returns> public IPolygon GenerateBuffer(IGeometry pGeometry, float Radius) { IGraphicsContainer pGraphicsContainer = (ESRI.ArcGIS.Carto.IGraphicsContainer)mapControl.Map; ITopologicalOperator pTopoOp = default(ITopologicalOperator); //拓扑接口,用来根据选择的对象和输入的距离产生缓冲区 IElement pElement = default(IElement); IGeometry geoBuffer = null; if ((pGeometry != null)) { pTopoOp = pGeometry as ITopologicalOperator; IPolygonElement pPolygonElement = new PolygonElement() as IPolygonElement; //PolygonElement pElement = pPolygonElement as IElement; //Generate Buffer geoBuffer = pTopoOp.Buffer((double)Radius) as IGeometry; pElement.Geometry = geoBuffer; //Get the IRGBColor interface IRgbColor pColor = default(IRgbColor); pColor = new RgbColor(); //Set the color properties pColor.RGB = 255; pColor.Transparency = 255; //Get the ILine symbol interface ILineSymbol pOutline = default(ILineSymbol); pOutline = new SimpleLineSymbol(); //Set the line symbol properties pOutline.Width = 2; pOutline.Color = pColor; //Set the color properties pColor = new RgbColor(); pColor.RGB = 255; pColor.Transparency = 0; //Get the IFillSymbol properties IFillSymbol pFillSymbol = new SimpleFillSymbol(); //Set the fill symbol properties pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; //QI for IFillShapeElement interface through the IElement interface IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; //Set the symbol property pFillShapeElement.Symbol = pFillSymbol; object obj = pFillSymbol as object; //this.axMapControl1.DrawShape(pElement.Geometry,ref obj ); pGraphicsContainer.AddElement(pFillShapeElement as IElement, 0); } mapControl.Refresh(); return(geoBuffer as IPolygon); }
private void 给出可测区域ToolStripMenuItem_Click(object sender, EventArgs e) { IGeometry buffer; ISelection pSeletion = axMapControl1.Map.FeatureSelection; IEnumFeature pEnumFeature = (IEnumFeature)pSeletion; IGraphicsContainer graphicsContainer = axMapControl1.ActiveView.GraphicsContainer; //graphicsContainer.DeleteAllElements(); IFeature pFeature = pEnumFeature.Next(); //选择集 double bufferDistance = GlobalData.dist; if (bufferDistance <= 0.0) { MessageBox.Show("距离设置错误"); return; } while (pFeature != null) { ITopologicalOperator topoOperator = pFeature.Shape as ITopologicalOperator; buffer = topoOperator.Buffer(bufferDistance); topoOperator = buffer as ITopologicalOperator; IGeometry result; if (rectpElement != null) { topoOperator.Clip(rectpElement.Geometry.Envelope); } IElement element = new PolygonElementClass(); element.Geometry = buffer; //创建矩形轮廓的样式 ILineSymbol linesymbol = new SimpleLineSymbolClass(); linesymbol.Width = 2; IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 65; rgbColor.Green = 105; rgbColor.Blue = 225; rgbColor.Transparency = 255; linesymbol.Color = rgbColor; IFillSymbol fillsymbol = new SimpleFillSymbolClass(); rgbColor.Transparency = 0; fillsymbol.Color = rgbColor; fillsymbol.Outline = linesymbol; IFillShapeElement fillshapeElement = element as IFillShapeElement; fillshapeElement.Symbol = fillsymbol; // 添加绘图元素 graphicsContainer.AddElement(element, 0); pFeature = pEnumFeature.Next(); } axMapControl1.Refresh(); }
private void axSceneControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ISceneControlEvents_OnMouseDownEvent e) { ICamera pCamera = this.axSceneControl1.Camera; IPoint point = pCamera.Target; IEnvelope pEnv = new EnvelopeClass(); pEnv.XMax = point.X + 2; pEnv.XMin = point.X - 2; pEnv.YMax = point.Y + 2; pEnv.YMin = point.Y - 2; IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pEle = pRectangleEle as IElement; pEle.Geometry = pEnv; //设置线框的边线对象,包括颜色和线宽 IRgbColor pColor = new RgbColorClass(); pColor.Red = 238; pColor.Green = 99; pColor.Blue = 99; pColor.Transparency = 255; // 产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1; pOutline.Color = pColor; // 设置颜色属性 pColor.Red = 238; pColor.Green = 99; pColor.Blue = 99; pColor.Transparency = 0; // 设置线框填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pEle as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; // 得到鹰眼视图中的图形元素容器 IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; // 在绘制前,清除 axMapControl1 中的任何图形元素 pGra.DeleteAllElements(); // 鹰眼视图中添加线框 pGra.AddElement((IElement)pFillShapeEle, 0); // 刷新鹰眼 pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void UCMap_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { if (scaleUpdated != null) { scaleUpdated(MapScale); } ucMapNavigate1.MapScale = (int)base.MapScale; // 得到新范围 IEnvelope pEnv = (IEnvelope)e.newEnvelope; IGraphicsContainer pGra = this.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; //在绘制前,清除axMapControl2中的任何图形元素 pGra.DeleteAllElements(); IRectangleElement pRectangleEle = new RectangleElementClass(); IElement pEle = pRectangleEle as IElement; pEle.Geometry = pEnv; //设置鹰眼图中的红线框 IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 1; pOutline.Color = pColor; //设置颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 0; pColor.Blue = 0; pColor.Transparency = 0; //设置填充符号的属性 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pEle as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGra.AddElement((IElement)pFillShapeEle, 0); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="pGeometry">几何图形</param> /// <param name="lineColor">边框颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns></returns> private static IElement CreateElement(IGeometry pGeometry, IRgbColor lineColor, IRgbColor fillColor) { if (pGeometry == null || lineColor == null || fillColor == null) { return(null); } IElement pElem = null; try { if (pGeometry is IEnvelope) { pElem = new RectangleElementClass(); } else if (pGeometry is IPolygon) { pElem = new PolygonElementClass(); } else if (pGeometry is ICircularArc) { ISegment pSegCircle = pGeometry as ISegment;//QI ISegmentCollection pSegColl = new PolygonClass(); object o = Type.Missing; pSegColl.AddSegment(pSegCircle, ref o, ref o); IPolygon pPolygon = pSegColl as IPolygon; pGeometry = pPolygon as IGeometry; pElem = new CircleElementClass(); } else if (pGeometry is IPolyline) { pElem = new LineElementClass(); } if (pElem == null) { return(null); } pElem.Geometry = pGeometry; IFillShapeElement pFElem = pElem as IFillShapeElement; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = fillColor; pSymbol.Outline.Color = lineColor; pSymbol.Style = esriSimpleFillStyle.esriSFSCross; if (pSymbol == null) { return(null); } pFElem.Symbol = pSymbol; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(pElem); }
public void DrawEnvelope(IEnvelope envelope) { if (envelope == null) { return; } try { //将鹰眼地图设置为地理容器,再设置为活动视图 IGraphicsContainer pGraphicsContainer = this.axMapControl.Map as IGraphicsContainer; IActiveView pActiveView = pGraphicsContainer as IActiveView; //清除鹰眼地图中的任何图形元素 pGraphicsContainer.DeleteAllElements(); //设置矩形范围 IRectangleElement pRectangeEle = new RectangleElementClass(); IElement pElement = pRectangeEle as IElement; pElement.Geometry = envelope; //创建鹰眼图中的红线框 IRgbColor pColor = new RgbColor(); pColor.Red = 255; pColor.Blue = 0; pColor.Green = 0; pColor.Transparency = 255; //创建线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 2; pOutline.Color = pColor; //设置颜色属性 pColor = new RgbColorClass(); pColor.Red = 255; pColor.Blue = 0; pColor.Green = 0; pColor.Transparency = 0; //设置填充符号 IFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = pColor; pFillSymbol.Outline = pOutline; IFillShapeElement pFillShapeEle = pElement as IFillShapeElement; pFillShapeEle.Symbol = pFillSymbol; pGraphicsContainer.AddElement((IElement)pFillShapeEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); interEnvelope = envelope; } catch (Exception ex) { LoggingService.Error(ex.Message + "\r\n" + ex.StackTrace); } }
private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e) { //创建矩形元素 IFillShapeElement fillShapeElement = ElementsHelper.GetRectangleElement(e.newEnvelope as IGeometry); //刷新总览窗体的mapcontrol if (m_FormOverview != null && !m_FormOverview.IsDisposed) { m_FormOverview.UpdateMapControlGraphics(fillShapeElement as IElement); } }
private void axPageLayoutControl1_OnExtentUpdated(object sender, IPageLayoutControlEvents_OnExtentUpdatedEvent e) { //QI for IEnvelope IEnvelope envelope = (IEnvelope)e.newEnvelope; //Get the IElement interface by finding an element by its name IElement element = m_PageLayoutControl.FindElementByName("ZoomExtent", 1); if (element != null) { //Delete the graphic m_PageLayoutControl.GraphicsContainer.DeleteElement(element); } element = new RectangleElementClass(); //Get the IRGBColor interface IRgbColor color = new RgbColorClass(); //Set the color properties color.RGB = 255; color.Transparency = 255; //Get the ILine symbol interface ILineSymbol outline = new SimpleLineSymbolClass(); //Set the line symbol properties outline.Width = 10; outline.Color = color; //Set the color properties color = new RgbColorClass(); color.RGB = 255; color.Transparency = 0; //Get the IFillSymbol properties IFillSymbol fillSymbol = new SimpleFillSymbolClass(); //Set the fill symbol properties fillSymbol.Color = color; fillSymbol.Outline = outline; //QI for IFillShapeElement interface through the IElement interface IFillShapeElement fillShapeElement = (IFillShapeElement)element; //Set the symbol property fillShapeElement.Symbol = fillSymbol; //Add the element m_PageLayoutControl.AddElement(element, e.newEnvelope, Type.Missing, "ZoomExtent", -1); //Refresh the graphics m_PageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="geometry">几何图形</param> /// <param name="lineColor">边界颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns>图形元素</returns> public static IElement CreateElement(IGeometry geometry, IRgbColor lineColor, IRgbColor fillColor) { if (geometry == null || lineColor == null || fillColor == null) { return(null); } IElement element = null; // 判断图形的类型 if (geometry is IEnvelope) { element = new RectangleElementClass(); } else if (geometry is IPolygon) { element = new PolygonElementClass(); } else if (geometry is ICircularArc) { ISegment segment = geometry as ISegment; ISegmentCollection segmentCollection = new PolygonClass(); segmentCollection.AddSegment(segment, Type.Missing, Type.Missing); IPolygon polygon = segmentCollection as IPolygon; geometry = polygon as IGeometry; element = new CircleElementClass(); } else if (geometry is IPolyline) { element = new LineElementClass(); } if (element == null) { return(null); } element.Geometry = geometry; ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); symbol.Outline.Color = lineColor; symbol.Color = fillColor; symbol.Style = esriSimpleFillStyle.esriSFSCross; if (symbol == null) { return(null); } IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = symbol; return(element); }
/// <summary> /// 在地图上绘制图形(单一) /// </summary> /// <param name="envelope">图形外包络</param> /// <param name="mapControl">绘制目标(地图控件对象)</param> public static void DrawMapShape(IEnvelope envelope, IMapControl2 mapControl) { IElement pElement = new RectangleElementClass() { Geometry = envelope }; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = getFillSymbol(getLineSymbol()); IGraphicsContainer pGC = mapControl.Map as IGraphicsContainer; pGC.DeleteAllElements(); pGC.AddElement(pElement, 0); mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }