/// <summary> /// 初始化信息,创建IElement实体存放人机交互产生的图形,并设定其显示符号,关闭定时器 /// </summary> public void MyInit() { //显示图形类型 ISimpleFillSymbol ipSimpleFillSymbol = new SimpleFillSymbolClass(); ipSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull; IRgbColor ipColor = new RgbColor(); ipColor.Red = 0; ipColor.Green = 255; ipColor.Blue = 0; ipSimpleFillSymbol.Color = ipColor; ILineSymbol ipLineSymple = new SimpleLineSymbolClass(); ipLineSymple.Width = 2; ipLineSymple.Color = ipColor; ipSimpleFillSymbol.Outline = ipLineSymple; this.m_FillSymbol = ipSimpleFillSymbol as IFillSymbol; //创建实体 IFillShapeElement ipFillShapeElement = new PolygonElementClass(); ipFillShapeElement.Symbol = this.m_FillSymbol; this.m_Element = ipFillShapeElement as IElement; IGraphicsContainer ipGraphicContainer = this.m_hookHelper.ActiveView.GraphicsContainer; ipGraphicContainer.AddElement(this.m_Element, 0); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { m_ActiveView = m_hookHelper.ActiveView; m_Map = m_hookHelper.FocusMap; IScreenDisplay pScreenDisplay = m_ActiveView.ScreenDisplay; IRubberBand pRubberCircle = new RubberCircleClass(); ISimpleFillSymbol pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Color = getRGB(255, 255, 0); IGeometry pCircle = pRubberCircle.TrackNew(pScreenDisplay, (ISymbol)pFillSymbol) as IGeometry; IConstructCircularArc pConstructArc = pCircle as IConstructCircularArc; IPolygon pPolygon = new PolygonClass(); ISegmentCollection pSegmentCollection = pPolygon as ISegmentCollection; ISegment pSegment = pConstructArc as ISegment; object missing = Type.Missing; pSegmentCollection.AddSegment(pSegment, ref missing, ref missing); pFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; pFillSymbol.Color = getRGB(255, 0, 0); IFillShapeElement pPolygonEle = new PolygonElementClass(); pPolygonEle.Symbol = pFillSymbol; IElement pEle = pPolygonEle as IElement; pEle.Geometry = pPolygon; IGraphicsContainer pGraphicsContainer = m_Map as IGraphicsContainer; pGraphicsContainer.AddElement(pEle, 0); m_ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { { object missing = Type.Missing; if (bCreateOrNot) { axMapControl1.CurrentTool = null; ESRI.ArcGIS.Geometry.IGeometry pGeometry = axMapControl1.TrackPolygon(); pGeometryCollection.AddGeometry(pGeometry, ref missing, ref missing); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol(); pSimpleLineSymbol.Color = GetAEColor(this.listView1.Items.Count + 1); pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol(); pSimpleFillSymbol.Color = GetAEColor(this.listView1.Items.Count + 1); IFillShapeElement pFillElement = new PolygonElementClass(); pFillElement.Symbol = pSimpleFillSymbol; IElement pElement; pElement = pFillElement as IElement; pElement.Geometry = pGeometry; pGraphic = axMapControl1.ActiveView as IGraphicsContainer; pGraphic.AddElement(pElement, 0); axMapControl1.Refresh(); polyGonCount += 1; this.txtSampleCount.Text = polyGonCount.ToString(); IElementProperties pElementProperties = pElement as IElementProperties; pElementProperties.Name = txtClassID.Text; } } }
//绘制多边形 public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { { rubberBand = new RubberPolygonClass(); IGeometry polygon = rubberBand.TrackNew(this.m_pMapControl.ActiveView.ScreenDisplay, null); if (polygon != null) { IFillShapeElement pElemFillShp; ISimpleFillSymbol pSFSym; IRgbColor pRGB; IElement element = new PolygonElementClass(); element.Geometry = polygon; pElemFillShp = (IFillShapeElement)element; pRGB = new RgbColorClass(); pRGB.Red = 255; pRGB.Green = 0; pRGB.Blue = 0; pSFSym = new SimpleFillSymbolClass(); 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.esriSFSSolid; pElemFillShp.Symbol = pSFSym; pGraphicsContainer = this.m_pMapControl.ActiveView as IGraphicsContainer; pGraphicsContainer.AddElement(element, 0); m_pActiveView.Refresh(); } base.OnMouseDown(button, shift, x, y, mapX, mapY); } }
private IElement method_9(IPoint ipoint_0) { IFillSymbol symbol = new SimpleFillSymbolClass(); (symbol as ISimpleFillSymbol).Style = esriSimpleFillStyle.esriSFSNull; IPolygon polygon = new PolygonClass(); object missing = Type.Missing; IPoint inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X, ipoint_0.Y); (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing); inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X, ipoint_0.Y - this.double_3); (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing); inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X + this.double_2, ipoint_0.Y - this.double_3); (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing); inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X + this.double_2, ipoint_0.Y); (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing); inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X, ipoint_0.Y); (polygon as IPointCollection).AddPoint(inPoint, ref missing, ref missing); IElement element = new PolygonElementClass { Geometry = polygon }; (element as IFillShapeElement).Symbol = symbol; return(element); }
/// <summary> /// 创建几何图形对应的用于高亮显示的元素 /// </summary> /// <param name="geometry"></param> /// <returns></returns> private static IElement CreateHightLightElement(IGeometry geometry) { IElement element = null; IColor redcolor = ColorCreate.GetIColor(255, 0, 0, 50); IColor bluecolor = ColorCreate.GetIColor(0, 0, 255); switch (geometry.GeometryType) { case esriGeometryType.esriGeometryLine: case esriGeometryType.esriGeometryPolyline: element = new LineElementClass(); element.Geometry = geometry; ((ILineElement)element).Symbol = SymbolCreate.GetSimpleLineSymbol(redcolor); break; case esriGeometryType.esriGeometryPolygon: element = new PolygonElementClass(); element.Geometry = geometry; ((PolygonElementClass)element).Symbol = SymbolCreate.GetSimpleFillSymbol(redcolor, bluecolor); break; case esriGeometryType.esriGeometryPoint: element = new MarkerElementClass(); element.Geometry = geometry; IMarkerSymbol pisymbol = new SimpleMarkerSymbolClass(); pisymbol.Color = (IColor)redcolor; pisymbol.Size = 6; ((MarkerElementClass)element).Symbol = pisymbol; break; } return(element); }
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); IElement element = new PolygonElementClass(); element.Geometry = buffer; graphicsContainer.AddElement(element, 0); pFeature = pEnumFeature.Next(); } axMapControl1.Refresh(); }
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 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); }
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> internal void FlashFeature() { IPoint point1 = new PointClass(); point1.PutCoords(101, 40); IPoint point2 = new PointClass(); point2.PutCoords(110, 40); IPoint point3 = new PointClass(); point3.PutCoords(112, 40); object o = Type.Missing; IPointCollection pointCollection = new PolygonClass(); pointCollection.AddPoint(point1, ref o, ref o); pointCollection.AddPoint(point2, ref o, ref o); pointCollection.AddPoint(point3, ref o, ref o); IPolygon polygon = pointCollection as IPolygon; IElement element = new PolygonElementClass(); element.Geometry = polygon; IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer; graphicsContainer.AddElement(element, 0); axMapControl.Refresh(); }
//ÉÁ˸¶à±ßÐÎ private static void FlashPolygon(IActiveView pActiveView, IGeometry pGeometry, int interval) { IScreenDisplay pDisplay = pActiveView.ScreenDisplay; ISimpleFillSymbol pFillSymbol; ISymbol pSymbol; IRgbColor pRGBColor; pFillSymbol = new SimpleFillSymbolClass(); pFillSymbol.Outline = null; pRGBColor = new RgbColorClass(); pRGBColor.Green = 148; pRGBColor.Red = 32; pRGBColor.Blue = 0; pFillSymbol.Color = pRGBColor as IColor; //added by chulili 20110805 pSymbol = pFillSymbol as ISymbol; pSymbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; pDisplay.SetSymbol(pSymbol); pDisplay.DrawPolygon(pGeometry); System.Threading.Thread.Sleep(interval); pDisplay.DrawPolygon(pGeometry); IElement pEle = new PolygonElementClass();//yjl¸ßÁÁÏÔʾ pEle.Geometry = pGeometry; (pEle as IFillShapeElement).Symbol = pSymbol as IFillSymbol; (pEle as IElementProperties).Name = _FlashTagName; (pActiveView as IGraphicsContainer).AddElement(pEle, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pEle, null); //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, pEle, 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> /// Draw a specified graphic on the map using the supplied colors. /// </summary> /// <param name="map"> /// An IMap interface. /// </param> /// <param name="geometry"> /// An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon. /// </param> /// <param name="rgbColor"> /// An IRgbColor interface. The color to draw the geometry. /// </param> /// <param name="outlineRgbColor"> /// An IRgbColor interface. For those geometry's with an outline it will be this color. /// </param> /// <remarks> /// Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh. /// </remarks> /// <returns> /// The <see cref="IElement"/>. /// </returns> private static IElement AddGraphicToMap( IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor) { var graphicsContainer = (IGraphicsContainer)map; // Explicit Cast IElement element = null; if (geometry.GeometryType == esriGeometryType.esriGeometryPoint) { // Marker symbols ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = (IElement)markerElement; // Explicit Cast } else if (geometry.GeometryType == esriGeometryType.esriGeometryPolyline) { // Line elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 5; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol; element = (IElement)lineElement; // Explicit Cast } else if (geometry.GeometryType == esriGeometryType.esriGeometryPolygon) { // Polygon elements ILineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = rgbColor; lineSymbol.Width = 2.0; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull; simpleFillSymbol.Outline = lineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast } if (element != null) { element.Geometry = geometry; graphicsContainer.AddElement(element, 0); } return(element); }
/// <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); }
public bool Buffer(string layerName, string sWhere, int iSize, IMap iMap) { IFeatureClass featClass; IFeature feature; IGeometry iGeom; DataOperator dataOperator = new DataOperator(iMap); IFeatureLayer featLayer = (IFeatureLayer)dataOperator.GetLayerByName(layerName); IGraphicsContainer graphicsContainer = (IGraphicsContainer)iMap; graphicsContainer.DeleteAllElements(); featClass = featLayer.FeatureClass; IQueryFilter queryFilter = new QueryFilter(); queryFilter.WhereClause = sWhere; IFeatureCursor featCursor; featCursor = (IFeatureCursor)featClass.Search(queryFilter, false); int count = featClass.FeatureCount(queryFilter); feature = featCursor.NextFeature(); iGeom = feature.Shape; IElement element = new PolygonElementClass(); ITopologicalOperator ipTO = (ITopologicalOperator)iGeom; element.Geometry = ipTO.Buffer(iSize); graphicsContainer.AddElement(element, 0); return(true); }
/// <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); } } }
public void AddObservPointsGraphicsToMap(IPolygon coverageArea, string areaName) { if ((coverageArea == null) || (coverageArea.SpatialReference == null)) { return; } ISimpleFillSymbol simplePolygonSymbol = new SimpleFillSymbolClass(); var color = (IRgbColor) new RgbColorClass() { Red = 255, Green = 253, Blue = 3 }; simplePolygonSymbol.Color = color; simplePolygonSymbol.Style = esriSimpleFillStyle.esriSFSHollow; ILineSymbol polygonOutline = new SimpleLineSymbol { Color = color, Width = 2 }; simplePolygonSymbol.Outline = polygonOutline; IFillShapeElement markerElement = new PolygonElementClass { Symbol = simplePolygonSymbol }; IElement element = null; element = (IElement)markerElement; if (element == null) { return; } element.Geometry = coverageArea; element.Geometry.SpatialReference = activeView.FocusMap.SpatialReference; var eprop = (IElementProperties)element; eprop.Name = areaName; var ge = new GraphicElement() { Source = coverageArea, Name = eprop.Name, Element = element }; if (allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Exists(el => el.Name == eprop.Name)) { DeleteGraphicsElement(ge, true, true); } graphics.AddElement(element, 0); allGraphics[MilSpaceGraphicsTypeEnum.Visibility].Add(ge); 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> /// 构造函数 /// </summary> /// <param name="_mapControl">arcgis地图控件</param> /// <param name="_element">要编辑的面图元</param> public EditPolygon(AxMapControl _mapControl, IMFElement _element) { element = _element as IMFPolygon; mapControl = _mapControl; markerList = new List <Model.EditMarker>(); polygonElement = _element as PolygonElementClass; pointList = new List <Element.Point_ArcMap>(); }
/// <summary> /// 根据IGeometry 生成一个Element,显示在地图上 /// </summary> /// <param name="pGC3D">element的容器</param> /// <param name="pGeom">element的几何信息</param> /// <param name="pSym">符号</param> /// <param name="sElementName">element的名称</param> public static void AddGraphics(IGraphicsContainer pGC, IGeometry pGeom, ISymbol pSym, string sElementName) { if (pGeom.IsEmpty) { return; } IElementProperties pElemProps; IElement pElement = null; IFillShapeElement pFillElement; //Point Type if (pGeom.GeometryType == esriGeometryType.esriGeometryPoint) { pElement = new MarkerElementClass(); IMarkerElement pPointElement; pPointElement = (IMarkerElement)pElement; pPointElement.Symbol = (IMarkerSymbol)pSym; pElement.Geometry = pGeom; } //Polyline Type else if (pGeom.GeometryType == esriGeometryType.esriGeometryPolyline) { pElement = new LineElementClass(); ILineElement pLineElement; pLineElement = (ILineElement)pElement; pLineElement.Symbol = (ILineSymbol)pSym; pElement.Geometry = pGeom; } //Polygon Type else if (pGeom.GeometryType == esriGeometryType.esriGeometryPolygon) { pElement = new PolygonElementClass(); pFillElement = (IFillShapeElement)pElement; pFillElement.Symbol = (IFillSymbol)pSym; pElement.Geometry = pGeom; } //MultiPatch Type else if (pGeom.GeometryType == esriGeometryType.esriGeometryMultiPatch) { pElement = new MultiPatchElementClass(); pFillElement = (IFillShapeElement)pElement; pFillElement.Symbol = (IFillSymbol)pSym; pElement.Geometry = pGeom; } if (pElement == null) { //Console.WriteLine("添加element时Element为null!"); return; } if (sElementName != "") { pElemProps = (IElementProperties)pElement; pElemProps.Name = sElementName; } pGC.AddElement(pElement, 1); }
/// <summary> /// 在图形容器中创建元素 /// </summary> /// <param name="graphicsContainer">图形容器,新建的元素将添加到该图形容器中</param> /// <param name="geometry">几何图形</param> /// <param name="eType">元素类型(点、线、面、文本等)</param> /// <returns></returns> public static IElement CreateElement(this IGraphicsContainer graphicsContainer, IGeometry geometry, EDrawElementType eType) { IElement element = null; switch (eType) { case EDrawElementType.Point: if (!(geometry is IPoint)) { throw new ArgumentException($"参数{nameof(geometry)}不是点({typeof(IPoint)}),无法由此创建点元素"); } element = new MarkerElementClass(); break; case EDrawElementType.Polyline: if (!(geometry is IPolyline)) { throw new ArgumentException($"参数{nameof(geometry)}不是折线({typeof(IPolyline)}),无法由此创建线元素"); } element = new LineElementClass(); break; case EDrawElementType.Polygon: if (!(geometry is IPolygon)) { throw new ArgumentException($"参数{nameof(geometry)}不是多边形({typeof(IPolygon)}),无法由此创建多边形元素"); } element = new PolygonElementClass(); break; case EDrawElementType.Circle: if (!(geometry is IPolygon)) { throw new ArgumentException($"参数{nameof(geometry)}不是多边形({typeof(IPolygon)}),无法由此创建圆形元素"); } element = new PolygonElementClass(); break; case EDrawElementType.Rectangle: if (!(geometry is IEnvelope)) { throw new ArgumentException($"参数{nameof(geometry)}不是矩形框({typeof(IEnvelope)}),无法由此创建矩形元素"); } element = new RectangleElementClass(); break; case EDrawElementType.Text: if (!(geometry is IPoint)) { throw new ArgumentException($"参数{nameof(geometry)}不是点({typeof(IPoint)}),无法由此创建文本元素"); } element = new TextElementClass(); break; } element.Geometry = geometry; graphicsContainer.AddElement(element, 0); return(element); }
/// <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(); }
public void Update(double newvalue, int row, int column)//x,y一起修改 { IPoint ipoint = (IPoint)pointCollection.Point[row]; switch (column) { case 0: break; case 1: ipoint.X = newvalue; break; case 2: ipoint.Y = newvalue; break; } //对于pointCollection进行修改 pointCollection.UpdatePoint(row, ipoint); //清空图像容器 pGraphicsContainer.DeleteAllElements(); IGeometry polygon = pointCollection as IGeometry; IPolygonElement polygonElement = new PolygonElementClass(); IElement polyElement = polygonElement as IElement; polyElement.Geometry = polygon; pGraphicsContainer.AddElement((IElement)polygonElement, 0); m_form.axMapControl1.ActiveView.Refresh(); for (int i = 0; i < pointCollection.PointCount; i++) { IMarkerSymbol markerSymbol = new SimpleMarker3DSymbolClass(); //markerSymbol的类型和分辨率 ((ISimpleMarker3DSymbol)markerSymbol).Style = esriSimple3DMarkerStyle.esriS3DMSSphere; ((ISimpleMarker3DSymbol)markerSymbol).ResolutionQuality = 1.0; //markerSymbol的颜色和大小 IRgbColor color = new RgbColorClass(); color.Red = 255; color.Green = 0; color.Blue = 0; markerSymbol.Size = 5; markerSymbol.Color = color as IColor; IElement pElement = new MarkerElementClass(); ((IMarkerElement)pElement).Symbol = markerSymbol; pElement.Geometry = pointCollection.Point[i]; pGraphicsContainer.AddElement(pElement, 0); /*IElement pElement=new MarkerElementClass(); * pElement.Geometry = pointCollection.Point[i]; * pGraphicsContainer.AddElement(pElement, 0);*/ } m_form.axMapControl1.ActiveView.Refresh(); }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (Button != 1 || m_hookHelper.FocusMap.LayerCount <= 0) { return; } IActiveView activeView = m_hookHelper.ActiveView; IGraphicsContainer graphicsContainer = activeView as IGraphicsContainer; // 删除地图上添加的所有Element graphicsContainer.DeleteAllElements(); // 获得点击位置并转化为点图形要素 IPoint point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y); // 获取地图中的图层 IFeatureLayer featureLayer = m_hookHelper.FocusMap.get_Layer(0) as IFeatureLayer; if (featureLayer == null) { return; } IFeatureClass featureClass = featureLayer.FeatureClass; // 进行点击,查询图层要素 ISpatialFilter spatialFilter = new SpatialFilterClass(); spatialFilter.Geometry = point; spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false); // 获得点击查询的要素 IFeature feature = featureCursor.NextFeature(); if (feature != null && feature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) { IGeometry geometry = feature.Shape as IGeometry; // 通过ITopologicalOperator接口进行多边行的简单化处理 ITopologicalOperator topologicalOperator = geometry as ITopologicalOperator; topologicalOperator.Simplify(); // 创建缓冲区 IGeometry bufferGeometry = topologicalOperator.Buffer(5000); // 创建多边形符号样式并添加到地图上 IScreenDisplay screenDisplay = activeView.ScreenDisplay; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSCross; IRgbColor rgbColor = ColorTool.GetRgbColor(211, 100, 200); simpleFillSymbol.Color = rgbColor; // 创建多边行渲染效果的Element IFillShapeElement fillShapElement = new PolygonElementClass(); IElement element = fillShapElement as IElement; element.Geometry = bufferGeometry; fillShapElement.Symbol = simpleFillSymbol; // 将渲染之后的多边形element添加到地图IGraphicsContainer中 graphicsContainer.AddElement(fillShapElement as IElement, 0); } // 刷新地图 activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
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(); }
/// <summary> /// 在图形容器中创建多边形元素 /// </summary> /// <param name="graphicsContainer">图形容器,新建的元素将添加到该图形容器中</param> /// <param name="polygon">多边形图形,用于创建多边形元素</param> /// <returns></returns> public static IFillShapeElement CreatePolygonElement(this IGraphicsContainer graphicsContainer, IPolygon polygon) { IFillShapeElement polygonElement = new PolygonElementClass(); IElement element = (IElement)polygonElement; element.Geometry = polygon; graphicsContainer.AddElement(element, 0); return(polygonElement); }
/// <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); }
private void test(IPoint point) { IGraphicsContainer gc = m_mapControl.Map as IGraphicsContainer; ITopologicalOperator topologicalOperator = point as ITopologicalOperator;; IElement element; element = new PolygonElementClass(); element.Geometry = topologicalOperator.Buffer(m_dEps); gc.AddElement(element, 0); m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void EndShow() { pGraphicsContainer.DeleteAllElements(); IGeometry polygon = pointCollection as IGeometry; IPolygonElement polygonElement = new PolygonElementClass(); IElement polyElement = polygonElement as IElement; polyElement.Geometry = polygon; pGraphicsContainer.AddElement((IElement)polygonElement, 0); m_form.axMapControl1.ActiveView.Refresh(); }
///<summary>Draw a specified graphic on the map using the supplied colors.</summary> /// ///<param name="map">An IMap interface.</param> ///<param name="geometry">An IGeometry interface. It can be of the geometry type: esriGeometryPoint, esriGeometryPolyline, or esriGeometryPolygon.</param> ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param> ///<param name="outlineRgbColor">An IRgbColor interface. For those geometry's with an outline it will be this color.</param> /// ///<remarks>Calling this function will not automatically make the graphics appear in the map area. Refresh the map area after after calling this function with Methods like IActiveView.Refresh or IActiveView.PartialRefresh.</remarks> public void AddGraphicToMap(IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor) { IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast IElement element = null; if ((geometry.GeometryType) == esriGeometryType.esriGeometryPoint) { // Marker symbols ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = (IElement)markerElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolyline) { // Line elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = 5; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol; element = (IElement)lineElement; // Explicit Cast } else if ((geometry.GeometryType) == esriGeometryType.esriGeometryPolygon) { // Polygon elements ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast } if (!(element == null)) { element.Geometry = geometry; graphicsContainer.AddElement(element, 0); } }
private IElement GetElement(IGeometry geometry, esriSimpleFillStyle simpleFillStyle) { IElement element; IPolygonElement polygonElement = new PolygonElementClass(); element = polygonElement as IElement; IFillShapeElement fillShapeElement = polygonElement as IFillShapeElement; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = simpleFillStyle; simpleFillSymbol.Color = ColorSelection.GetColor(); element.Geometry = geometry; fillShapeElement.Symbol = simpleFillSymbol; return element; }
private IElement OSMGeometryToGraphicElement(IGeometry featureGeometry, IColor featureColor) { IElement graphicElement = null; switch (featureGeometry.GeometryType) { case esriGeometryType.esriGeometryAny: break; case esriGeometryType.esriGeometryBag: break; case esriGeometryType.esriGeometryBezier3Curve: break; case esriGeometryType.esriGeometryCircularArc: break; case esriGeometryType.esriGeometryEllipticArc: break; case esriGeometryType.esriGeometryEnvelope: break; case esriGeometryType.esriGeometryLine: break; case esriGeometryType.esriGeometryMultiPatch: break; case esriGeometryType.esriGeometryMultipoint: break; case esriGeometryType.esriGeometryNull: break; case esriGeometryType.esriGeometryPath: break; case esriGeometryType.esriGeometryPoint: graphicElement = new MarkerElementClass() as IElement; graphicElement.Geometry = featureGeometry; IMarkerSymbol markerSymbol = null; if (m_documentDefaultSymbols == null) { // create a symbology for a point geometry ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = featureColor; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; simpleMarkerSymbol.Size = 18; markerSymbol = simpleMarkerSymbol; } else { markerSymbol = m_documentDefaultSymbols.MarkerSymbol; markerSymbol.Color = featureColor; } ((IMarkerElement)graphicElement).Symbol = markerSymbol; break; case esriGeometryType.esriGeometryPolygon: graphicElement = new PolygonElementClass() as IElement; graphicElement.Geometry = featureGeometry; // IFillSymbol fillSymbol = null; if (m_documentDefaultSymbols == null) { ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = featureColor; ILineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = featureColor; simpleLineSymbol.Width = 1; simpleFillSymbol.Outline = simpleLineSymbol; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; fillSymbol = simpleFillSymbol; } else { fillSymbol = m_documentDefaultSymbols.FillSymbol; fillSymbol.Color = featureColor; } ((IFillShapeElement)graphicElement).Symbol = fillSymbol; break; case esriGeometryType.esriGeometryPolyline: graphicElement = new LineElementClass() as IElement; graphicElement.Geometry = featureGeometry; ILineSymbol lineSymbol = null; if (m_documentDefaultSymbols == null) { lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = featureColor; lineSymbol.Width = 3; } else { lineSymbol = m_documentDefaultSymbols.LineSymbol; lineSymbol.Color = featureColor; } ((ILineElement)graphicElement).Symbol = lineSymbol; break; case esriGeometryType.esriGeometryRay: break; case esriGeometryType.esriGeometryRing: break; case esriGeometryType.esriGeometrySphere: break; case esriGeometryType.esriGeometryTriangleFan: break; case esriGeometryType.esriGeometryTriangleStrip: break; case esriGeometryType.esriGeometryTriangles: break; default: break; } return graphicElement; }
/// <summary> /// Creates an element from the given feature and adds it to the active view's graphics container. /// </summary> /// <param name="feature">The feature from which to create the element.</param> /// <param name="aView">The active view.</param> /// <param name="markerColorName">The marker color.</param> /// <returns>Returns a graphic element.</returns> public static IElement MarkFeature(IFeature feature, IActiveView aView, string markerColorName) { IElement element = null; if (feature != null && aView != null) { IPolygon poly = new PolygonClass(); try { ITopologicalOperator topOp = feature.Shape as ITopologicalOperator; poly.SpatialReference = feature.Shape.SpatialReference; poly = topOp.Buffer(aView.Extent.Width * .01) as IPolygon; if (poly.SpatialReference.Equals(aView.FocusMap.SpatialReference) == false) poly.Project(aView.FocusMap.SpatialReference); ISimpleFillSymbol fillSym = DisplayMap.GenerateGenericFillSymbol(markerColorName, esriSimpleFillStyle.esriSFSSolid); fillSym.Outline = DisplayMap.GenerateGenericLineSymbol(markerColorName, 2); element = new PolygonElementClass(); element.Geometry = poly; ((IFillShapeElement)element).Symbol = fillSym; IGraphicsContainer gCont = aView as IGraphicsContainer; gCont.AddElement(element, 0); aView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, topOp.Buffer(aView.Extent.Width * .02).Envelope); } catch (Exception e) { // _logger.LogException(e); } } return element; }
public override void RefreshFeedBack() { try { if (TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry == null) return; //屏幕绘制graphic表达此刻的Geometry IElement ipElement = null; if(_subType == 1) { ipElement = new LineElementClass(); ipElement.Geometry = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry; } else if(_subType == 2) { ipElement = new PolygonElementClass(); ipElement.Geometry = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry; ipElement.Geometry.SpatialReference = TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry.SpatialReference; //绘制Geometry时使用空心红框,以方便查看叠盖关系 ISimpleFillSymbol iSymbol = new SimpleFillSymbolClass(); ISimpleLineSymbol iOutlineSymbol = new SimpleLineSymbolClass(); IColor irgbColor = new RgbColorClass(); (irgbColor as IRgbColor).Red = 255; (irgbColor as IRgbColor).Blue = 0; (irgbColor as IRgbColor).Green = 0; iOutlineSymbol.Color = irgbColor; iSymbol.Style = esriSimpleFillStyle.esriSFSHollow; iSymbol.Outline = iOutlineSymbol; (ipElement as IFillShapeElement).Symbol = iSymbol; } (myHook.FocusMap as IGraphicsContainer).AddElement(ipElement, 0); (myHook.FocusMap as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, ipElement, TheReferenceInstances.TheAEditer.SketchEdit.DrawGeometry.Envelope); InfoUserStatusbar.InfoTip = "草图绘制完成!"; } catch (System.Exception e) { throw new ApplicationException(String.Format("把草图更新到Map出错!\n{0}", e.Message)); InfoUserStatusbar.InfoTip = "草图绘制失败!"; } finally { if (myHook.Hook is IMapControl3) { TheReferenceInstances.TheAxMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; (myHook.Hook as IMapControl3).CurrentTool = null; } else if (myHook.Hook is IPageLayoutControl2) { (myHook.Hook as IPageLayoutControl2).CurrentTool = null; } m_cursor = Cursors.Default; } }
/// <summary> /// Draw the polygon contained within the properties. /// </summary> /// <param name="polyToBeDrawn"> /// The polygon to be drawn. /// </param> /// <param name="graphicContainer"> /// The graphic container. /// </param> private void DrawPoly(Properties polyToBeDrawn, IGraphicsContainer graphicContainer) { var poly = new PolygonClass(); poly.Project(ArcMap.Document.ActiveView.Extent.SpatialReference); foreach (var pnt in polyToBeDrawn.Points) { var tempPoint = new PointClass(); tempPoint.PutCoords(pnt.X, pnt.Y); tempPoint.SpatialReference = Jarvis.ProjectedCoordinateSystem; tempPoint.Project(ArcMap.Document.ActiveView.Extent.SpatialReference); poly.AddPoint(tempPoint); } IElement elm = new PolygonElementClass(); elm.Geometry = poly; graphicContainer.AddElement(elm, 0); }
/// <summary> /// draw footprints on the map /// </summary> /// <param name="record">Record for which the footprint needs to be drwan</param> /// <param name="refreshview">Indicates if the view is refreshed or not after the element is drawn</param> /// <param name="deleteelements">Indicates if the element can be deleted or not</param> private void drawfootprint(CswRecord record, bool refreshview, bool deleteelements) { //create the triangle outline symbol ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; lineSymbol.Width = 2.0; //create the triangle's fill symbol ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Outline = (ILineSymbol)lineSymbol; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; IMxDocument mxDoc; mxDoc = (IMxDocument)m_application.Document; //the original projection system ISpatialReference spatialReference; IGeographicCoordinateSystem geographicCoordinateSystem; SpatialReferenceEnvironmentClass spatialReferenceEnviorment = new SpatialReferenceEnvironmentClass(); geographicCoordinateSystem = spatialReferenceEnviorment.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); spatialReference = (ISpatialReference)geographicCoordinateSystem; //set the geometry of the element IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.SpatialReference = spatialReference; point.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Miny); IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass(); point1.SpatialReference = spatialReference; point1.PutCoords(record.BoundingBox.Minx, record.BoundingBox.Maxy); IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass(); point2.SpatialReference = spatialReference; point2.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Maxy); IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass(); point3.SpatialReference = spatialReference; point3.PutCoords(record.BoundingBox.Maxx, record.BoundingBox.Miny); IPointCollection pointCollection; pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass(); object x = Type.Missing; object y = Type.Missing; pointCollection.AddPoint(point, ref x, ref y); pointCollection.AddPoint(point1, ref x, ref y); pointCollection.AddPoint(point2, ref x, ref y); pointCollection.AddPoint(point3, ref x, ref y); PolygonElementClass element = new PolygonElementClass(); element.Symbol = simpleFillSymbol; element.SpatialReference = spatialReference; element.Geometry.SpatialReference = spatialReference; element.Geometry = (IGeometry)pointCollection; element.Geometry.Project(mxDoc.ActiveView.Extent.SpatialReference); //add the graphics element to the map IGraphicsContainer graphicsContainer; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; if (deleteelements) { graphicsContainer.DeleteAllElements(); } graphicsContainer.AddElement(element, 0); if (refreshview) { mxDoc.ActiveView.Extent = element.Geometry.Envelope; mxDoc.ActiveView.Refresh(); } }
// // // public static void drawPolygon(IActiveView pActiveView) { IGraphicsContainer iGC = pActiveView as IGraphicsContainer; IRubberBand pRubberPoly = new RubberPolygonClass(); IScreenDisplay pScreenDisp = pActiveView.ScreenDisplay; IGeometry pGeom; pGeom = pRubberPoly.TrackNew(pScreenDisp, null); IPolygon pPoly = pGeom as IPolygon; IElement pEle; if (pPoly != null) { pEle = new PolygonElementClass() as IElement; pEle.Geometry = pPoly; iGC.AddElement(pEle, 0); } pActiveView.Refresh(); }
private void AddElement(IMap map, IGeometry geom) { IGraphicsContainer graphicsContainer = map as IGraphicsContainer; IRgbColor color = new RgbColorClass(); color.Green = 80; color.Red = 22; color.Blue = 68; IElement element = null; if (geom is IPoint) { ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Color = color; simpleMarkerSymbol.Size = 15; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = markerElement as IElement; if (element != null) { element.Geometry = geom; } } else if(geom is IPolygon) { var temp = new SimpleLineSymbol(); temp.Color = color; temp.Style = esriSimpleLineStyle.esriSLSSolid; temp.Width = 2; var s = new SimpleFillSymbol(); s.Color = color; s.Outline = temp; s.Style = esriSimpleFillStyle.esriSFSBackwardDiagonal; var pe = new PolygonElementClass(); element = pe as IElement; var fill = pe as IFillShapeElement; fill.Symbol = s; element.Geometry = geom; } graphicsContainer.AddElement(element, 0); IActiveView activeView = map as IActiveView; activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void DrawFanShaped(double x, double y, IActiveView pActiveView) { double radius = this.radius; double small_radius = this.small_radius; double start_angle = this.start_angle; double central_angle = this.central_angle; if (pActiveView != null) { IGraphicsContainer graphicsContainer = pActiveView as IGraphicsContainer; //画大圆 IPoint pCenterPoint = new PointClass(); pCenterPoint.PutCoords(x, y); ICircularArc pCircularArc = new CircularArcClass(); pCircularArc.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, radius); IPoint pStartPoint = pCircularArc.FromPoint; IPoint pEndPoint = pCircularArc.ToPoint; ILine pLine1 = new LineClass(); pLine1.PutCoords(pCenterPoint, pStartPoint); ILine pLine2 = new LineClass(); pLine2.PutCoords(pEndPoint, pCenterPoint); ISegmentCollection pRing1 = new PolygonClass(); ISegment pSegment1 = pLine1 as ISegment; pRing1.AddSegment(pSegment1); ISegment pSegment2 = pCircularArc as ISegment; pRing1.AddSegment(pSegment2); ISegment pSegment3 = pLine2 as ISegment; pRing1.AddSegment(pSegment3); //小圆 ICircularArc pCircularArc1 = new CircularArcClass(); pCircularArc1.PutCoordsByAngle(pCenterPoint, start_angle * Math.PI / 180.0, central_angle * Math.PI / 180.0, small_radius); IPoint pStartPoint1 = pCircularArc1.FromPoint; IPoint pEndPoint1 = pCircularArc1.ToPoint; ILine pLine3 = new LineClass(); pLine3.PutCoords(pCenterPoint, pStartPoint1); ILine pLine4 = new LineClass(); pLine4.PutCoords(pEndPoint1, pCenterPoint); ISegmentCollection pRing2 = new PolygonClass(); ISegment pSegment4 = pLine3 as ISegment; pRing2.AddSegment(pSegment4); ISegment pSegment5 = pCircularArc1 as ISegment; pRing2.AddSegment(pSegment5); ISegment pSegment6 = pLine4 as ISegment; pRing2.AddSegment(pSegment6); //简化 ITopologicalOperator pTopoLogical1 = pRing1 as ITopologicalOperator; pTopoLogical1.Simplify(); ITopologicalOperator pTopoLogical2 = pRing2 as ITopologicalOperator; pTopoLogical2.Simplify(); IGeometry geometry = pTopoLogical1.Difference(pTopoLogical2 as IGeometry); //产生一个SimpleFillSymbol符号 IRgbColor rgbColor = new RgbColorClass(); rgbColor.Red = 255; rgbColor.Green = 0; rgbColor.Blue = 0; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Width = 1; ISimpleFillSymbol simpleFillSymbol; simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSDiagonalCross; //设置颜色 IRgbColor rgbcolor = new RgbColorClass(); rgbcolor.Red = 0; rgbcolor.Green = 0; rgbcolor.Blue = 255; simpleFillSymbol.Color = rgbcolor as IColor; simpleFillSymbol.Outline = simpleLineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; IElement pElement = fillShapeElement as IElement; pElement.Geometry = geometry; graphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
///<summary>Draw a specified graphic on the map using the supplied colors.</summary> ///<param name="map">An IMap interface.</param> ///<param name="geometry">An IPoint interface. It can be of the geometry type esriGeometryPoint</param> ///<param name="rgbColor">An IRgbColor interface. The color to draw the geometry.</param> ///<param name="outlineRgbColor">An IRgbColor interface. For marker anfd polygons the outline it will be this color, for lines this is ignored</param> ///<param name="size">size in pixel as integer linewidth of outLine or of intire marker if point</param> ///<param name="userLock">locked from editing by user?</param> public static IElement AddGraphicToMap(IMap map, IGeometry geometry, IRgbColor rgbColor, IRgbColor outlineRgbColor, int size = 5, bool userLock = false) { IGraphicsContainer graphicsContainer = (IGraphicsContainer)map; // Explicit Cast IElement element = null; if ((geometry.GeometryType) == esriGeometryType.esriGeometryPoint) { // Marker symbols ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = rgbColor; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = outlineRgbColor; simpleMarkerSymbol.Size = size; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond; IMarkerElement markerElement = new MarkerElementClass(); markerElement.Symbol = simpleMarkerSymbol; element = (IElement)markerElement; // Explicit Cast } else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline) { // Line elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = rgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = size; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol; element = (IElement)lineElement; // Explicit Cast } else if ((geometry.GeometryType) == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon) { // Polygon elements ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = outlineRgbColor; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; simpleLineSymbol.Width = size; ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = rgbColor; simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal; simpleFillSymbol.Outline = simpleLineSymbol; IFillShapeElement fillShapeElement = new PolygonElementClass(); fillShapeElement.Symbol = simpleFillSymbol; element = (IElement)fillShapeElement; // Explicit Cast } if (!(element == null)) { element.Geometry = geometry; element.Locked = userLock; graphicsContainer.AddElement(element, 0); } return element; }
private void menuItem26_Click(object sender, System.EventArgs e) { ISelection pSelection; IMap pMap; IEnumFeature pEnumF; IFeature pFeature; IActiveView pActiveView = axMapControl1.ActiveView; IGraphicsContainer iGC = pActiveView as IGraphicsContainer; pMap = axMapControl1.ActiveView.FocusMap; if (pMap.SelectionCount != 2) { MessageBox.Show("��ѡ������Ҫ��"); return; } pSelection = pMap.FeatureSelection; pEnumF = pSelection as IEnumFeature; pFeature = pEnumF.Next(); IGeometry pGeomIn = pFeature.Shape; pFeature = pEnumF.Next(); IGeometry pGeomOther = pFeature.Shape; IGeometry rltGeom; //pGeomIn.SpatialReference=pFLayer.SpatialReference; if (pGeomIn.SpatialReference != pGeomOther.SpatialReference) MessageBox.Show("�ռ�ο���ͬ"); rltGeom = Utility.SymmetricDiff(pGeomIn, pGeomOther); if (rltGeom == null) { MessageBox.Show("û��difference"); return; } IElement inputEle = new PolygonElementClass(); inputEle.Geometry = rltGeom; iGC.AddElement(inputEle, 0); pActiveView.Refresh(); }
private void test(IPoint point) { IGraphicsContainer gc = m_mapControl.Map as IGraphicsContainer; ITopologicalOperator topologicalOperator = point as ITopologicalOperator; ; IElement element; element = new PolygonElementClass(); element.Geometry = topologicalOperator.Buffer(m_dEps); gc.AddElement(element, 0); m_mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 把Geometry弄成一个element,添加到地图上 /// </summary> /// <param name="pGeometry"></param> private void AddElement(IGeometry pGeometry) { try { IElement pElement = null; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSSolid; pSimpleFillSymbol.Outline = pSimpleLineSymbol; if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)//多义线 { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; pElement = pLineElement as IElement; pElement.Geometry = pGeometry; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)//圆 { ISegmentCollection pSegmentCollection; pSegmentCollection = new PolygonClass(); object Missing = Type.Missing;//注意 pSegmentCollection.AddSegment(pGeometry as ISegment, ref Missing, ref Missing);//后两个参数必须是这样,帮助说的,为什么?? pElement = new CircleElementClass(); pElement.Geometry = pSegmentCollection as IGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)//矩形 { pElement = new RectangleElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolygon)//多边形 { pElement = new PolygonElementClass(); pElement.Geometry = pGeometry; IFillShapeElement pFillShapeElement = pElement as IFillShapeElement; pFillShapeElement.Symbol = pSimpleFillSymbol; } else if (pGeometry.GeometryType == esriGeometryType.esriGeometryBezier3Curve)//Bezier曲线 { pElement = new LineElementClass(); pElement.Geometry = pGeometry; ILineElement pLineElement = pElement as ILineElement; pLineElement.Symbol = pSimpleLineSymbol; } this.pGraphicContainer.AddElement(pElement, 0); this.axMapControl1.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//��˷�ٲ��ҹ����漰�ĵؿ� public static void UpStreamFindParcels(AxMapControl ppAxMapControl, IEnumNetEID pEnumResultEdges, IGeometricNetwork pGeoNetwork) { try { IFeatureLayer pFeatLayerSewerLines = FindFeatLayer("Sewer Lines", ppAxMapControl); IFeatureLayer pFeatLayerParcels = FindFeatLayer("Parcels", ppAxMapControl); //����ѡ���Sewer�������д������ΰ� IGeometryCollection pGeomBag = new GeometryBagClass(); object missing = Type.Missing; int lEID; int iUserClassID; int iUserID; int iUserSubID; INetElements pNetElements = pGeoNetwork.Network as INetElements; pEnumResultEdges.Reset(); IFeature pFeature; for (int j = 0; j <= pEnumResultEdges.Count - 1; j++) { lEID = pEnumResultEdges.Next(); pNetElements.QueryIDs(lEID, esriElementType.esriETEdge, out iUserClassID, out iUserID, out iUserSubID); pFeature = pFeatLayerSewerLines.FeatureClass.GetFeature(iUserID); pGeomBag.AddGeometry(pFeature.Shape, ref missing, ref missing); // MessageBox.Show(iUserClassID.ToString()+","+iUserID.ToString()+","+iUserSubID.ToString()); } //���пռ����˵��Ӳ��������ڲ��ҵؿ���Ϣ ISpatialFilter pSpatialFilter = new SpatialFilterClass(); pSpatialFilter.Geometry = pGeomBag as IGeometry; pSpatialFilter.GeometryField = "Shape"; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.SearchOrder = esriSearchOrder.esriSearchOrderSpatial; //��ý��浽�ĵؿ���Ϣ IFeatureCursor pFeatCursor = pFeatLayerParcels.FeatureClass.Search(pSpatialFilter, false); //���ӱ�ѡ��ĵؿ����ݵ���ͼ��ͼ��ͼ�������� ICompositeGraphicsLayer pComGraphicLayer = new CompositeGraphicsLayerClass(); ILayer pLayer = pComGraphicLayer as ILayer; pLayer.Name = "��Ӱ��ĵؿ�"; IGraphicsContainer pGraphicContainer = pComGraphicLayer as IGraphicsContainer; //������ѡ��ĵؿ鵽ͼ�������� ISimpleFillSymbol pSymFill = new SimpleFillSymbolClass(); IFillSymbol pFillSymbol = pSymFill as IFillSymbol; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 0; pRgbColor.Green = 200; pRgbColor.Blue = 100; pFillSymbol.Color = pRgbColor as IColor; ICartographicLineSymbol pCartoLine = new CartographicLineSymbolClass(); IRgbColor pRgbColor2 = new RgbColorClass(); pRgbColor2.Red = 100; pRgbColor2.Green = 200; pRgbColor2.Blue = 100; pCartoLine.Width = 2; pCartoLine.Color = pRgbColor2 as IColor; pFillSymbol.Outline = pCartoLine; //����������еؿ����������� IArray pFeatArray = new ArrayClass(); pFeature = pFeatCursor.NextFeature(); while (pFeature != null) { IElement pPolyElement = new PolygonElementClass(); IFillShapeElement pFillShapeElement = pPolyElement as IFillShapeElement; pPolyElement.Geometry = pFeature.Shape; pFillShapeElement.Symbol = pFillSymbol; pGraphicContainer.AddElement(pPolyElement, 0); pFeatArray.Add(pFeature); pFeature = pFeatCursor.NextFeature(); } ppAxMapControl.AddLayer(pGraphicContainer as ILayer); ppAxMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //ma //frmUpstreamCreateOwnerList frmUpstreamCreateOwnerList1 = new frmUpstreamCreateOwnerList(ppAxMapControl,pFeatLayerParcels, pFeatArray); //frmUpstreamCreateOwnerList1.Show(); } catch (Exception eX) { MessageBox.Show(eX.Message); } }
private void theForm_BoxChange(object sender, EventArgs e) { bool bNeedRefresh = false; ISDUTExtension theExt = this.Extension; IGraphicsContainer theGCont = util.GraphicsHelper.get_GraphicsContainer(theExt.FocusMap); ui.CreateWellsiteBoxForm theForm = (ui.CreateWellsiteBoxForm)sender; IPolygon theBox = null; if (double.IsNaN(theForm.Orientation) == false && double.IsNaN(theForm.BoxSize) == false) { theBox = this.CreateBox(this._Wellsite, theForm.Orientation, theForm.BoxSize, theForm.SizeUnits); theBox.Project(theExt.FocusMap.SpatialReference); } // Clear existing feedback if (this._Feedback != null) { theGCont.DeleteElement(this._Feedback); this._Feedback = null; bNeedRefresh = true; } // Create new graphic if (theBox != null) { object theMissing = Type.Missing; IElement theBoxE = new PolygonElementClass(); theBoxE.Geometry = theBox; ((IFillShapeElement)theBoxE).Symbol = util.GraphicsHelper.get_SimplePolygonSymbol( util.GraphicsHelper.get_RgbColor(0, 0, 0), esriSimpleFillStyle.esriSFSHollow, util.GraphicsHelper.get_SimpleLineSymbol( util.GraphicsHelper.get_RgbColor(0, 0, 0), 2.0, esriSimpleLineStyle.esriSLSSolid)); ILine theLine = new LineClass(); theLine.PutCoords(this._Wellsite, theBox.FromPoint); ISegmentCollection theSegColl = new PolylineClass(); theSegColl.AddSegment((ISegment)theLine, ref theMissing, ref theMissing); IElement theLineE = new LineElementClass(); theLineE.Geometry = (IGeometry)theSegColl; IGroupElement theGroupE = new GroupElementClass(); theGroupE.AddElement(theBoxE); theGroupE.AddElement(theLineE); this._Feedback = (IElement)theGroupE; theGCont.AddElement(this._Feedback, 0); bNeedRefresh = true; } // Refresh the graphics in the map if (bNeedRefresh) { IActiveView theAV = (IActiveView)theExt.FocusMap; theAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, theAV.Extent); } }
/// <summary> /// Event handler for "Display Footprint" button click event /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void displayFootprinttoolStripButton_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; CswRecord record = (CswRecord)(resultsListBox.SelectedItem); drawfootprint(record, false, false); //add the graphics element to the map IMxDocument mxDoc; mxDoc = (IMxDocument)m_application.Document; IGraphicsContainer graphicsContainer; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; BoundingBox currentExtent = new BoundingBox(); currentExtent.Maxx = mxDoc.ActiveView.Extent.XMax; currentExtent.Minx = mxDoc.ActiveView.Extent.XMin; currentExtent.Maxy = mxDoc.ActiveView.Extent.YMax; currentExtent.Miny = mxDoc.ActiveView.Extent.YMin; BoundingBox newExtent = updatedExtent(currentExtent, record.BoundingBox); IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.PutCoords(newExtent.Minx, newExtent.Maxy); IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass(); point1.PutCoords(newExtent.Maxx, newExtent.Maxy); IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass(); point2.PutCoords(newExtent.Maxx, newExtent.Miny); IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass(); point3.PutCoords(newExtent.Minx, newExtent.Miny); IPointCollection pointCollection; pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass(); object x = Type.Missing; object y = Type.Missing; pointCollection.AddPoint(point, ref x, ref y); pointCollection.AddPoint(point1, ref x, ref y); pointCollection.AddPoint(point2, ref x, ref y); pointCollection.AddPoint(point3, ref x, ref y); PolygonElementClass element = new PolygonElementClass(); element.Geometry = (IGeometry)pointCollection; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; mxDoc.ActiveView.Extent = element.Geometry.Envelope; mxDoc.ActiveView.Refresh(); } catch (Exception ex) { ShowErrorMessageBox(ex.Message); } finally { Cursor.Current = Cursors.Default; } }
/// <summary> /// ���Ƽ���ͼ�� /// </summary> /// <params name="geoType"></params> /// <params name="geometry"></params> /// <returns></returns> ESRI.ArcGIS.Carto.IElement createElement_x(ESRI.ArcGIS.Geometry.IGeometry geometry) { IElement element = null; try { switch (geometry.GeometryType) { case esriGeometryType.esriGeometryPolygon: IFillShapeElement pPolygonElement; ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbolClass(); IPolygon pPolygon = new PolygonClass(); IRubberBand pRubberBand = new RubberPolygonClass(); ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pPolygonElement = new PolygonElementClass(); //if (e.button == 1) //{ // pPolygon=(IPolygon) pRubberBand.TrackNew(axMapControl1.ActiveView.ScreenDisplay, null); //} pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pSimpleLineSymbol.Color = TransColorToAEColor(Color.Blue); //pSimpleFillSymbol.Color = GetRGBColor(11, 200, 145); pSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull; pSimpleFillSymbol.Outline = pSimpleLineSymbol; IElement pElement = (IElement)pPolygonElement; pElement.Geometry = geometry; pPolygonElement.Symbol = pSimpleFillSymbol; element = (IElement)pPolygonElement; break; case esriGeometryType.esriGeometryPolyline://Polyline�� ISimpleLineSymbol simpleLineSymbol = m_NewPolygonFeedback.Symbol as ISimpleLineSymbol; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = simpleLineSymbol as ILineSymbol; element = lineElement as IElement; element.Geometry = geometry; break; case esriGeometryType.esriGeometryPoint: //���ý����� IRgbColor pRGB = new RgbColorClass(); pRGB.Red = 255; pRGB.Green = 0; pRGB.Blue = 0; ISimpleMarkerSymbol pSimpleMarkSymbol = new SimpleMarkerSymbolClass(); pSimpleMarkSymbol.Color = pRGB as IColor; pSimpleMarkSymbol.Size = 2; pSimpleMarkSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare; IMarkerElement pMarkerElement = new MarkerElementClass(); pMarkerElement.Symbol = pSimpleMarkSymbol as IMarkerSymbol; element = pMarkerElement as IElement; element.Geometry = geometry as IGeometry; break; } } catch { } return element; }
/// <summary> /// Event handler for "Show All Footprint" button click event /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void showAllFootprint_Click(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; IMxDocument mxDoc; mxDoc = (IMxDocument)m_application.Document; IGraphicsContainer graphicsContainer; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; BoundingBox currentExtent = new BoundingBox(); currentExtent.Maxx = mxDoc.ActiveView.Extent.XMax; currentExtent.Minx = mxDoc.ActiveView.Extent.XMin; currentExtent.Maxy = mxDoc.ActiveView.Extent.YMax; currentExtent.Miny = mxDoc.ActiveView.Extent.YMin; BoundingBox newExtent = currentExtent; if (showAll) { showAll = false; System.Windows.Forms.ToolTip toolTipForshowAll = new System.Windows.Forms.ToolTip(); toolTipForshowAll.SetToolTip(showAllFootprintToolStripButton, StringResources.hideAllFootprintTooltip); //showAllFootprintToolStripButton = StringResources.hideAllFootprintTooltip; showAllFootprintToolStripButton.Image = StringResources.hideAll; foreach (Object obj in resultsListBox.Items) { currentExtent = newExtent; CswRecord record = (CswRecord)obj; if (record.BoundingBox.Maxx != NONEXSISTANTNUMBER) { drawfootprint(record, true, false); newExtent = updatedExtent(currentExtent, record.BoundingBox); } } IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.PutCoords(newExtent.Minx, newExtent.Maxy); IPoint point1 = new ESRI.ArcGIS.Geometry.PointClass(); point1.PutCoords(newExtent.Maxx, newExtent.Maxy); IPoint point2 = new ESRI.ArcGIS.Geometry.PointClass(); point2.PutCoords(newExtent.Maxx, newExtent.Miny); IPoint point3 = new ESRI.ArcGIS.Geometry.PointClass(); point3.PutCoords(newExtent.Minx, newExtent.Miny); IPointCollection pointCollection; pointCollection = new ESRI.ArcGIS.Geometry.PolygonClass(); object x = Type.Missing; object y = Type.Missing; pointCollection.AddPoint(point, ref x, ref y); pointCollection.AddPoint(point1, ref x, ref y); pointCollection.AddPoint(point2, ref x, ref y); pointCollection.AddPoint(point3, ref x, ref y); PolygonElementClass element = new PolygonElementClass(); element.Geometry = (IGeometry)pointCollection; graphicsContainer = (IGraphicsContainer)mxDoc.FocusMap; mxDoc.ActiveView.Extent = element.Geometry.Envelope; mxDoc.ActiveView.Refresh(); } else { showAll = true; System.Windows.Forms.ToolTip toolTipForshowAll = new System.Windows.Forms.ToolTip(); toolTipForshowAll.SetToolTip(showAllFootprintToolStripButton, StringResources.showAllFootPrintToolTip); showAllFootprintToolStripButton.Image = StringResources.showAll; deleteelements(); } mxDoc.ActiveView.Refresh(); } catch (Exception ex) { ShowErrorMessageBox(ex.Message); } finally { Cursor.Current = Cursors.Default; } }
private void _drawPolygon() { if (this._axMapCtrl.ActiveView == null) { return; } ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = this._axMapCtrl.ActiveView.ScreenDisplay; // Constant. screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16) ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit cast. ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColorClass(); rgbColor.Red = 255; ESRI.ArcGIS.Display.IColor color = rgbColor; // Implicit cast. ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new ESRI.ArcGIS.Display.SimpleFillSymbolClass(); simpleFillSymbol.Color = color; ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic cast. ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass(); ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol); screenDisplay.SetSymbol(symbol); //screenDisplay.DrawPolygon(geometry); screenDisplay.FinishDrawing(); PolygonElementClass element = new PolygonElementClass(); element.Geometry = geometry; // Create lineSymbol ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); // set color & style,.... ESRI.ArcGIS.Display.IRgbColor lineColor = new ESRI.ArcGIS.Display.RgbColorClass(); lineColor.Red = 255; lineSymbol.Color = lineColor; lineSymbol.Width = 3; // Create fillSymbol ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); fillSymbol.Outline = lineSymbol; ESRI.ArcGIS.Display.IRgbColor fillColor = new ESRI.ArcGIS.Display.RgbColorClass(); fillColor.Red = 255; fillColor.Green = 255; fillSymbol.Color = fillColor; fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; element.Symbol = fillSymbol; this._axMapCtrl.ActiveView.GraphicsContainer.AddElement(element, 0); //((IGraphicsContainerSelect)(this._axMapCtrl.ActiveView.GraphicsContainer)).SelectElement(element); this._axMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); if (this._polygonName != "") { element.Name = this._polygonName; this._polygonName = ""; } /* else { int count = 0; IGraphicsContainer container = this._axMapCtrl.ActiveView.GraphicsContainer; container.Reset(); while (container.Next() != null) { count++; } element.Name = "Element " + count; } */ if (PolygonDrawn != null) { PolygonDrawn(element.Name); } }
private void FinishMainRoadButtonClick(object sender, RoutedEventArgs e) { if (isValid()) { if (isDirty()) { if (Ut.C("继续操作会清空之后的数据, 是否继续?")) { dirty = true; valid = true; foreach (MainRoad mainRoad in mainRoadList) { if (mainRoad.needDelete) mainRoad.delete(); else mainRoad.saveOrUpdate(); } //1. 靠主路生成区域. GisUtil.CreateShapefile(C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME, mapControl.SpatialReference, "polyline"); List<IGeometry> mainRoadGeometryList = new List<IGeometry>(); foreach (MainRoad mainRoad in mainRoadList) { IElement element = mainRoad.lineElement as IElement; mainRoadGeometryList.Add(element.Geometry); } GisUtil.AddGeometryListToShpFile(mainRoadGeometryList, C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME); cachedVillageAreaPolygonList = GisUtil.GetPolygonListFromPolylineList( Ut.MakePath(C.PROGRAM_FOLDER, SiteSelectorUserControl.MAINROAD_LIST_SHP_NAME), Ut.MakePath(C.PROGRAM_FOLDER, SiteSelectorUserControl.VILLAGE_AREA_SHP_NAME)); foreach (IPolygon polygon in cachedVillageAreaPolygonList) { GisUtil.drawPolygon(polygon, mapControl); } //2. 检查生成的区域是否符合标准. bool errorFlag = false; if (cachedVillageAreaPolygonList.Count == 0) errorFlag = true; foreach (IPolygon polygon in cachedVillageAreaPolygonList) { IArea area = polygon as IArea; if (area.Area > Village.VILLAGE_MAX_SIZE) { errorFlag = true; break; } } if (errorFlag) Ut.M("生成的图形中包含错误."); //3. 区域形成village对象和相应的内部路对象. villageList = new ObservableCollection<Village>(); foreach (IPolygon polygon in cachedVillageAreaPolygonList) { Village village = new Village(); village.programID = program.id; IPolygonElement polygonElement = new PolygonElementClass(); IElement element = polygonElement as IElement; element.Geometry = polygon; village.polygonElement = polygonElement; village.updateBoundary(); InnerRoad innerRoad = new InnerRoad(); innerRoad.programID = program.id; innerRoad.villageID = village.id; village.innerRoad = innerRoad; villageList.Add(village); } } else { return; } } else { valid = true; return; } } else { Ut.M("请完整填写信息"); return; } }
public void points() { string strs = "Marker"; switch (strs) { case "Marker": IMarkerElement pMarkerElement;//对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。 IElement pMElement; IPoint pPoint=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE pMarkerElement = new MarkerElementClass(); pMElement = pMarkerElement as IElement; RubberPointClass pRubberBand = new RubberPointClass();//你的RUBBERBAND随着你的图形耳边 //pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; ////pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint; //pPoint.X = 101; //pPoint.Y = 37; // pPoint.PutCoords(Convert.ToDouble(101), Convert.ToDouble(37)); //pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 200); // pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); // pPoint = axMapControl.ToMapPoint(334, 344); //pPoint.X = pPoint.X; //pPoint.Y = pPoint.Y; /*00000000000000000000000000000000000经纬度转换坐标*/ //IGlobeDisplay m_globeDisplay = axGlobeControl1.GlobeDisplay; //// IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay; ////axGlobeControl1.GlobeDisplay.ActiveViewer; //ISceneViewer sceneViewer = m_globeDisplay.ActiveViewer; //IGlobeViewUtil globeViewUtil = (IGlobeViewUtil)sceneViewer.Camera; //int winX, winY; ////globeViewUtil.GeographicToWindow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text), 0, out winX, out winY); ////pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(0, 0);//x,y为屏幕坐标 ////pPoint.X = Convert.ToDouble(textBox1.Text); ////pPoint.Y = Convert.ToDouble(textBox2.Text); //pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标 //axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out winX, out winY); // int mx = winX; //int my = winY; //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 400);//x,y为屏幕坐标 //调用GetProject2方法经纬度转换成米 pPoint = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); //pPoint.PutCoords(Convert.ToDouble(textBox3.Text), Convert.ToDouble(textBox4.Text)); /*00000000000000000000000000000000000*/ // pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(mx, my); //pPoint.PutCoords(mx, my); //pPoint.X = mx; //pPoint.Y = my; //ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass(); //pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem(2414); //pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954)); pMElement.Geometry = pPoint;//把你在屏幕中画好的图形付给 IElement 储存 IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 // axMapControl.get_Layer(0) // ILayer pLayer = this.axMapControl.get_Layer(1);//所要加的层 pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //axMapControl.Refresh(); break; case "Line": //ILineElement pLineElement; //IElement pLElement; //IPolyline pLine; // IGraphicsContainer pGraphicsContainerl = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 //pLineElement = new LineElementClass(); //pLElement = pLineElement as IElement; //RubberLineClass pRubberBandd = new RubberLineClass(); //pLine = pRubberBandd.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolyline; //pLElement.Geometry = pLine; //pGraphicsContainerl = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 //pGraphicsContainerl.AddElement(pLElement, 0);//把刚刚的element转到容器上 //axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //00000000000 //调用GetProject2方法经纬度转换成米 IPoint pPointl=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE pPointl = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); IPoint pPointl2=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE pPointl2 = GetProject2(-120, 40); //创建一个Line对象 ILine pLine2 = new LineClass(); //Polyline pLine2 = new PolylineClass(); //设置Line对象的起始终止点 pLine2.PutCoords(pPointl, pPointl2); //IPointCollection pMultipoint = new MultipointClass(); //object o=Type.Missing; //pMultipoint.AddPoint(pPointl, ref o, ref o); //pMultipoint.AddPoint(pPointl2, ref o, ref o); axMapControl.ActiveView.Refresh();//刷新当前视图 break; case "Fill": IFillShapeElement pFillShapeElement; IElement pgonElemnt; IPolygon pPolygon; pFillShapeElement = new PolygonElementClass(); pgonElemnt = pFillShapeElement as IElement;//Element RubberPolygonClass pRubberBand3 = new RubberPolygonClass();//在屏幕上画个多边形 pPolygon = pRubberBand3.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolygon; pgonElemnt.Geometry = pPolygon;//把这个多边形转成Element pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 //pGraphicsContainer.DeleteAllElements (); pGraphicsContainer.AddElement(pgonElemnt, 0);//把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); break; } }
/// <summary> /// 设置IGeometry的ISymbol /// </summary> /// <param name="pGeo"></param> /// 函数需要改进 public static void SetGeoColor(IGeometry pGeo, IGraphicsContainer pGraphContainer, string strElementName) { IElement ipElement = null; if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { ILineElement ipLineElement = new LineElementClass(); RgbColor ipColor = new RgbColor(); ipElement = (IElement)ipLineElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 2.0; ipColor.Red = 0; ipColor.Blue = 0; ipColor.Green = 255; ipLineSymbol.Color = (IColor)ipColor; ipLineElement.Symbol = ipLineSymbol; ((IElementProperties)ipElement).Name = strElementName; pGraphContainer.AddElement(ipElement, 0); } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { RgbColor ipColor = new RgbColor(); IPolygonElement ipPolygonElement = new PolygonElementClass(); ipElement = (IElement)ipPolygonElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 2.0; ipColor.Red = 0; ipColor.Blue = 0; ipColor.Green = 255; ipLineSymbol.Color = (IColor)ipColor; ipFillSymbol.Outline = ipLineSymbol; IFillShapeElement pFillElement = (IFillShapeElement)ipPolygonElement; ipFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pFillElement.Symbol = ipFillSymbol; ((IElementProperties)ipElement).Name = strElementName; pGraphContainer.AddElement(ipElement, 0); } }
/// <summary> /// 画线 /// </summary> internal void FlashFeature() { IPoint point1 = new PointClass(); //point1.PutCoords(101, 40); point1 = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text)); IPoint point2 = new PointClass(); //point2.PutCoords(110, 40); point2 = GetProject2(-120, 40); //IPoint point3 = new PointClass(); //point3.PutCoords(112, 40); object o = Type.Missing; IPointCollection pointCollection = new PolygonClass(); pointCollection.AddPoint(point1, ref o, ref o); pointCollection.AddPoint(point2, ref o, ref o); //pointCollection.AddPoint(point3, ref o, ref o); IPolygon polygon = pointCollection as IPolygon; IElement element = new PolygonElementClass(); element.Geometry = polygon; IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer; graphicsContainer.AddElement(element, 0); axMapControl.Refresh(); }
/// <summary> /// 聚焦到目标地物 /// </summary> /// <param name="pActiveView">地图视图</param> /// <param name="pFtLayer">图层</param> /// <param name="nOID">地物ID</param> public static void AddElement(IActiveView pActiveView, IFeatureLayer pFtLayer, int nOID) { IFeatureClass pFtCls = pFtLayer.FeatureClass; IFeature pFt = pFtCls.GetFeature(nOID); if (pFt == null) { return; } IGeometry pGeo = pFt.Shape; if (pGeo == null) { return; } IEnvelope pEnvelope = pGeo.Envelope; IGraphicsContainer pGraphContainer = pActiveView.GraphicsContainer; //根据拓扑错误图形的几何类型,来创建相应的element IElement ipElement = null; RgbColor ipColor = new RgbColor(); if (pGeo.GeometryType == esriGeometryType.esriGeometryPoint) { IMarkerElement ipMarkElement = new MarkerElementClass(); ipElement = (IElement)ipMarkElement; ipElement.Geometry = pGeo; ISimpleMarkerSymbol ipMarkerSymbol = new SimpleMarkerSymbolClass(); ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipMarkerSymbol.Color = (IColor)ipColor; ipMarkElement.Symbol = ipMarkerSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { ILineElement ipLineElement = new LineElementClass(); ipElement = (IElement)ipLineElement; ipElement.Geometry = pGeo; ISimpleLineSymbol ipLineSymbol = new SimpleLineSymbolClass(); ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipLineSymbol.Width = 2.0; ipLineElement.Symbol = ipLineSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygonElement ipPolygonElement = new PolygonElementClass(); ipElement = (IElement)ipPolygonElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 2.0; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipFillSymbol.Outline = ipLineSymbol; IFillShapeElement pFillElement = (IFillShapeElement)ipPolygonElement; ipFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pFillElement.Symbol = ipFillSymbol; } pGraphContainer.DeleteAllElements(); pGraphContainer.AddElement(ipElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); pActiveView.ScreenDisplay.UpdateWindow(); }
//编辑层 public void AddPointByBuffer(int index) { IPoint point1 = new PointClass(); //point1.PutCoords(101, 40); point1 = GetProject2(-120, 20); IPoint point2 = new PointClass(); //point2.PutCoords(110, 40); point2 = GetProject2(-120, 40); //IPoint point3 = new PointClass(); //point3.PutCoords(112, 40); object o = Type.Missing; IPointCollection pointCollection = new PolygonClass(); pointCollection.AddPoint(point1, ref o, ref o); pointCollection.AddPoint(point2, ref o, ref o); //pointCollection.AddPoint(point3, ref o, ref o); IPolygon polygon = pointCollection as IPolygon; IElement element = new PolygonElementClass(); element.Geometry = polygon; IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer; graphicsContainer.AddElement(element, 0); axMapControl.Refresh(); //ILayer pLayer = this.axMapControl.get_Layer(2);//获取当前图层,此图层为组图层,需要转换 //GlobeGraphicsLayer cLyr = null; //if (pLayer is GlobeLayer) //{ // //cLyr = (GlobeGraphicsLayer)pLayer; // IFeatureLayer pFeatureLyr = pLayer as IFeatureLayer;//将ILayer转换为IFeaturelayer,为了对图层上的要素进行编辑 // IFeatureClass pFeatCls = pFeatureLyr.FeatureClass;//定义一个要素集合,并获取图层的要素集合 // IFeatureClassWrite fr = (IFeatureClassWrite)pFeatCls;//定义一个实现新增要素的接口实例,并该实例作用于当前图层的要素集 // IWorkspaceEdit w = (pFeatCls as IDataset).Workspace as IWorkspaceEdit;//定义一个工作编辑工作空间,用于开启前图层的编辑状态 // IFeature f;//定义一个IFeature实例,用于添加到当前图层上 // w.StartEditing(true);//开启编辑状态 // w.StartEditOperation();//开启编辑操作 // //IPoint p;//定义一个点,用来作为IFeature实例的形状属性,即shape属性 // //下面是设置点的坐标和参考系 // //IFeatureLayer l = axMapControl.Map.get_Layer(index) as IFeatureLayer; // //IFeatureClass fc = l.FeatureClass; // //IFeatureClassWrite fr = fc as IFeatureClassWrite; // //IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; // //IFeature f; // //可选参数的设置 // object Missing = Type.Missing; // IPoint p = new PointClass(); // w.StartEditing(true); // w.StartEditOperation(); // IPolygon polygon; // for (int i = 0; i < 100; i++) // { // f = pFeatCls.CreateFeature(); // //定义一个多义线对象 // //IPolyline PlyLine = new PolylineClass(); // //定义一个点的集合 // IPointCollection ptclo = new PolygonClass(); // //定义一系列要添加到多义线上的点对象,并赋初始值 // for (int j = 0; j < 4; j++) // { // p.PutCoords(j, j); // ptclo.AddPoint(p, ref Missing, ref Missing); // } // //IPointCollection pointCollection = new PolygonClass(); // polygon = ptclo as IPolygon; // IElement element = new PolygonElementClass(); // element.Geometry = polygon; // IGraphicsContainer graphicsContainer = axMapControl.Map as IGraphicsContainer; // graphicsContainer.AddElement(element, 0); // axMapControl.Refresh(); // //f.Shape = PlyLine; // //fr.WriteFeature(f); // IGeometry geo = (IGeometry)polygon; // //开始画点 // IMarkerElement pMarkerElement;//对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。 // IElement pMElement; // pMarkerElement = new MarkerElementClass(); // pMElement = pMarkerElement as IElement; // pMElement.Geometry = polygon;//把你在屏幕中画好的图形付给 IElement 储存 // IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 // pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。 // axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); // } // //p = new PointClass(); // p.SpatialReference = this.axMapControl.SpatialReference; // //p.X = 600; // //p.Y = 500; // //将IPoint设置为IFeature的shape属性时,需要通过中间接口IGeometry转换 // IGeometry peo; // peo = p; // f = pFeatCls.CreateFeature();//实例化IFeature对象, 这样IFeature对象就具有当前图层上要素的字段信息 // f.Shape = peo;//设置IFeature对象的形状属性 // //f.set_Value(0, "Marker01");//设置IFeature对象的索引是3的字段值 // f.Store();//保存IFeature对象 // fr.WriteFeature(f);//将IFeature对象,添加到当前图层上 // w.StopEditOperation();//停止编辑操作 // w.StopEditing(true);//关闭编辑状态,并保存修改 // this.axMapControl.Refresh();//刷新地图 //} //IFeatureLayer l = axMapControl.Map.get_Layer(index) as IFeatureLayer; //IFeatureClass fc = l.FeatureClass; //IFeatureClassWrite fr = fc as IFeatureClassWrite; //IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit; //IFeature f; ////可选参数的设置 //object Missing = Type.Missing; //IPoint p = new PointClass(); //w.StartEditing(true); //w.StartEditOperation(); //for (int i = 0; i < 100; i++) //{ // f = fc.CreateFeature(); // //定义一个多义线对象 // IPolyline PlyLine = new PolylineClass(); // //定义一个点的集合 // IPointCollection ptclo = PlyLine as IPointCollection; // //定义一系列要添加到多义线上的点对象,并赋初始值 // for (int j = 0; j < 4; j++) // { // p.PutCoords(j, j); // ptclo.AddPoint(p, ref Missing, ref Missing); // } // f.Shape = PlyLine; // fr.WriteFeature(f); //} //w.StopEditOperation(); //w.StopEditing(true); }
/// <summary> /// Gets the element. /// </summary> /// <param name="pGeo">The p geo.</param> /// <param name="strElementName">Name of the STR element.</param> /// <returns></returns> /// 函数需要改进 private static IElement GetElement(IGeometry pGeo, string strElementName) { IElement ipElement = null; if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { ILineElement ipLineElement = new LineElementClass(); RgbColor ipColor = new RgbColor(); ipElement = (IElement)ipLineElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 0.5; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipLineElement.Symbol = ipLineSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { RgbColor ipColor = new RgbColor(); IPolygonElement ipPolygonElement = new PolygonElementClass(); ipElement = (IElement)ipPolygonElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 1.0; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipFillSymbol.Outline = ipLineSymbol; IFillShapeElement pFillElement = (IFillShapeElement)ipPolygonElement; ipFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pFillElement.Symbol = ipFillSymbol; } if (ipElement != null) { ((IElementProperties)ipElement).Name = strElementName; } return ipElement; }
/// <summary> /// 聚焦到目标地物 /// </summary> /// <param name="pMapCtrl">地图控件control</param> /// <param name="pFt">地物</param> public static void ZoomToElement(AxMapControl pMapCtrl, IGeometry pGeo) { if (pGeo == null || pGeo.IsEmpty) { return; } IEnvelope pEnvelope = pGeo.Envelope; IGraphicsContainer pGraphContainer = pMapCtrl.ActiveView.GraphicsContainer; //根据拓扑错误图形的几何类型,来创建相应的element IElement ipElement = null; RgbColor ipColor = new RgbColor(); if (pGeo.GeometryType == esriGeometryType.esriGeometryPoint) { IMarkerElement ipMarkElement = new MarkerElementClass(); ipElement = (IElement)ipMarkElement; ipElement.Geometry = pGeo; ISimpleMarkerSymbol ipMarkerSymbol = new SimpleMarkerSymbolClass(); ipColor.Red = 0; ipColor.Blue = 255; ipColor.Green = 0; RgbColor ipColor1 = new RgbColor(); ipColor1.NullColor = true; ipMarkerSymbol.Color = (IColor)ipColor1; ipMarkerSymbol.OutlineColor = (IColor)ipColor; ipMarkerSymbol.Outline = true; ipMarkerSymbol.OutlineSize = 2; ipMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ipMarkerSymbol.Size = 14; ipMarkElement.Symbol = ipMarkerSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { ILineElement ipLineElement = new LineElementClass(); ipElement = (IElement)ipLineElement; ipElement.Geometry = pGeo; ISimpleLineSymbol ipLineSymbol = new SimpleLineSymbolClass(); ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipLineSymbol.Width = 2.0; ipLineElement.Symbol = ipLineSymbol; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { IPolygonElement ipPolygonElement = new PolygonElementClass(); ipElement = (IElement)ipPolygonElement; ipElement.Geometry = pGeo; ISimpleFillSymbol ipFillSymbol = new SimpleFillSymbolClass(); ILineSymbol ipLineSymbol = ipFillSymbol.Outline; ipLineSymbol.Width = 2.0; ipColor.Red = 255; ipColor.Blue = 0; ipColor.Green = 0; ipLineSymbol.Color = (IColor)ipColor; ipFillSymbol.Outline = ipLineSymbol; IFillShapeElement pFillElement = (IFillShapeElement)ipPolygonElement; ipFillSymbol.Style = esriSimpleFillStyle.esriSFSHollow; pFillElement.Symbol = ipFillSymbol; } //pGraphContainer.DeleteAllElements(); pGraphContainer.AddElement(ipElement, 0); //pMapCtrl.ActiveView.Extent = pEnvelope; //如果是点类型则集中显示 if (pGeo.GeometryType == esriGeometryType.esriGeometryPoint) { //IEnvelope pEnv = pMapCtrl.ActiveView.FullExtent; //pEnv.Expand(0.005, 0.005, false); //pMapCtrl.ActiveView.Extent = pEnv; IPoint pPoint = (IPoint)pGeo; pMapCtrl.CenterAt(pPoint); pMapCtrl.MapScale = 2000; } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline) { if (!pEnvelope.IsEmpty) { pEnvelope.Expand(3, 3, true); pMapCtrl.ActiveView.Extent = pEnvelope; } else { IPointCollection pPntColl = pGeo as IPointCollection; IPoint pt = pPntColl.get_Point(1); pMapCtrl.CenterAt(pt); pMapCtrl.MapScale = 2000; } } else if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon) { pEnvelope.Expand(2, 2, true); pMapCtrl.ActiveView.Extent = pEnvelope; } //pMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); pMapCtrl.ActiveView.Refresh(); pMapCtrl.ActiveView.ScreenDisplay.UpdateWindow(); FlashGeometry(pMapCtrl.Object as IMapControl4, pGeo); //pMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //pMapCtrl.ActiveView.ScreenDisplay.UpdateWindow(); }
/// <summary> /// ��ʼ����Ϣ������IElementʵ�����˻�����������ͼ�Σ����趨����ʾ���ţ��رն�ʱ�� /// </summary> public void MyInit() { //��ʾͼ������ ISimpleFillSymbol ipSimpleFillSymbol = new SimpleFillSymbolClass(); ipSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull; IRgbColor ipColor = new RgbColor(); ipColor.Red = 0; ipColor.Green = 255; ipColor.Blue = 0; ipSimpleFillSymbol.Color = ipColor; ILineSymbol ipLineSymple = new SimpleLineSymbolClass(); ipLineSymple.Width = 2; ipLineSymple.Color = ipColor; ipSimpleFillSymbol.Outline = ipLineSymple; this.m_FillSymbol = ipSimpleFillSymbol as IFillSymbol; //����ʵ�� IFillShapeElement ipFillShapeElement = new PolygonElementClass(); ipFillShapeElement.Symbol = this.m_FillSymbol; this.m_Element = ipFillShapeElement as IElement; IGraphicsContainer ipGraphicContainer = this.m_hookHelper.ActiveView.GraphicsContainer; ipGraphicContainer.AddElement(this.m_Element, 0); }