/// <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); }
private void buttonOK_Click(object sender, EventArgs e) { this.Visible = false; if (_axmapcontrol != null) { try { IEnvelope penvelope = new EnvelopeClass(); penvelope.XMin = Convert.ToDouble(textBoxWest.Text); penvelope.XMax = Convert.ToDouble(textBoxEast.Text); penvelope.YMax = Convert.ToDouble(textBoxNorth.Text); penvelope.YMin = Convert.ToDouble(textBoxSouth.Text); IPoint pmiddle = new PointClass(); pmiddle.PutCoords((penvelope.XMax + penvelope.XMin) / 2, (penvelope.YMax + penvelope.YMin) / 2);//中心点 /*********************************将Envelope转成Polygon*/ IPolygon pon = new PolygonClass(); IPointCollection ptcoll = new PolygonClass(); IPoint a = new PointClass(); IPoint b = new PointClass(); IPoint c = new PointClass(); IPoint d = new PointClass(); a.PutCoords(penvelope.XMin, penvelope.YMax); b.PutCoords(penvelope.XMax, penvelope.YMax); c.PutCoords(penvelope.XMax, penvelope.YMin); d.PutCoords(penvelope.XMin, penvelope.YMin); object missing = Type.Missing; ptcoll.AddPoint(a, ref missing, ref missing); ptcoll.AddPoint(b, ref missing, ref missing); ptcoll.AddPoint(c, ref missing, ref missing); ptcoll.AddPoint(d, ref missing, ref missing); pon = ptcoll as IPolygon; /*********************************/ IGeometry geo = new PolygonClass(); geo = pon as IGeometry; /*-----xisheng 20110802------*/ ISpatialReference earthref = null; ISpatialReference flatref = null; ISpatialReferenceFactory2 pSpatRefFac = new SpatialReferenceEnvironmentClass(); earthref = pSpatRefFac.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); if (this.WriteLog) { Plugin.LogTable.Writelog(this.Text);//xisheng 日志记录 0928; } if (_axmapcontrol.MapUnits == esriUnits.esriMeters) { flatref = _axmapcontrol.Map.SpatialReference; geo.SpatialReference = flatref;//yjl20110812 //geo.Project(flatref); } /*-----xisheng 20110802------*/ //创建Topo对象,简化后统一空间参考 ITopologicalOperator pTopo = (ITopologicalOperator)geo; pTopo.Simplify(); geo.Project(_axmapcontrol.Map.SpatialReference); if (m_frmQuery == null) { m_frmQuery = new frmQuery(_axmapcontrol, m_enumQueryMode); m_frmQuery.Owner = m_mainFrm; m_frmQuery.FormClosed += new FormClosedEventHandler(frmQuery_FormClosed); } //清除上次的所有元素 (_axmapcontrol.Map as IGraphicsContainer).DeleteAllElements(); m_frmBufferSet = new frmBufferSet(geo, _axmapcontrol.Map, m_frmQuery); m_frmBufferSet.FormClosed += new FormClosedEventHandler(frmBufferSet_FormClosed); _axmapcontrol.CenterAt(pmiddle); IGeometry pGeometry = m_frmBufferSet.GetBufferGeometry(); if (pGeometry == null || m_frmBufferSet.Res == false) { return; } m_frmQuery.Show(); ///ZQ 20111119 modify m_frmQuery.FillData(_axmapcontrol.ActiveView.FocusMap, pGeometry, m_frmBufferSet.pesriSpatialRelEnum); this.Close(); } catch (Exception ex) { SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "错误:" + ex.Message); } } }
/// <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; }