/// <summary> /// 在三维场景中由两点生成线的绘制 20110609 /// </summary> /// <param name="Point1">前一个点要素</param> /// <param name="Point2">后一点要素</param> /// <param name="r"></param> /// <param name="g"></param> /// <param name="b"></param> /// <param name="Width">线符号宽</param> /// <returns></returns> public static IElement PointToPolyline(IPoint Point1, IPoint Point2, int r, int g, int b, double Width) { ILine line = new LineClass(); line.PutCoords(Point1, Point2); object missing = Type.Missing; ISegmentCollection segColl = new PolylineClass(); segColl.AddSegment(line as ISegment, ref missing, ref missing); IPolyline pPolyline = new PolylineClass(); pPolyline = segColl as IPolyline; IZAware pZAware = new PolylineClass(); pZAware = pPolyline as IZAware; pZAware.ZAware = true; IElement lineElement = new LineElementClass(); ISimpleLine3DSymbol pSimpleLine3DSymbol = new SimpleLine3DSymbolClass(); pSimpleLine3DSymbol.Style = esriSimple3DLineStyle.esriS3DLSWall; pSimpleLine3DSymbol.ResolutionQuality = 1; ILineSymbol pLineSymbol = pSimpleLine3DSymbol as ILineSymbol; pLineSymbol.Color = getRGB(r, g, b); pLineSymbol.Width = Width; lineElement.Geometry = pZAware as IGeometry; ILineElement lineElement2 = lineElement as ILineElement; lineElement2.Symbol = pLineSymbol; return(lineElement); }
private void DrawTraceRsult(IEnumNetEID JunctionEIDs, IEnumNetEID EdgEIDs) { if (JunctionBarrierEIDs == null || EdgEIDs == null) { return; } INetElements netElements = m_GeometryNetwork.Network as INetElements; int userClssID = -1; int userID = -1; int userSubID = -1; int eid = -1; // IFeatureClass fteClss; IFeature feature; //设置管点和管线显示的Symbol ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass(); simpleMarkerSymbol.Color = Method.Getcolor(255, 0, 0); simpleMarkerSymbol.Size = 6; simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Color = Method.Getcolor(255, 0, 0); simpleLineSymbol.Width = 2; simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element; //获取管点结果 for (int i = 0; i < JunctionEIDs.Count; i++) { eid = JunctionEIDs.Next(); netElements.QueryIDs(eid, esriElementType.esriETJunction, out userClssID, out userID, out userSubID); fteClss = GetFteClssByID(userClssID, this.Mapcontrol.Map); if (fteClss != null) { feature = fteClss.GetFeature(userID); element = new MarkerElementClass(); element.Geometry = feature.Shape; ((IMarkerElement)element).Symbol = simpleMarkerSymbol; ((IElementProperties)element).Name = "Result"; this.Mapcontrol.ActiveView.GraphicsContainer.AddElement(element, 0); } } //获取管线结果 for (int j = 0; j < EdgEIDs.Count; j++) { eid = EdgEIDs.Next(); netElements.QueryIDs(eid, esriElementType.esriETEdge, out userClssID, out userID, out userSubID); fteClss = GetFteClssByID(userClssID, this.Mapcontrol.Map); if (fteClss != null) { feature = fteClss.GetFeature(userID); element = new LineElementClass(); element.Geometry = feature.Shape; ((ILineElement )element).Symbol = simpleLineSymbol; ((IElementProperties)element).Name = "Result"; this.Mapcontrol.ActiveView.GraphicsContainer.AddElement(element, 0); } } }
//----------------------------------干扰源定位中的绘制 // 绘制线段 public static void DrawLine(IPoint p1, IPoint p2, int r, int g, int b) { IPolyline line = new PolylineClass(); object _missing = Type.Missing; line.FromPoint = p1; line.ToPoint = p2; ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = ColorUtilities.GetColor(r, g, b); lineSymbol.Width = 0.25; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; IElement element = lineElement as IElement; element.Geometry = line as IGeometry; IGraphicsLayer pLayer = (GISMapApplication.Instance.Scene as IBasicMap).BasicGraphicsLayer; IGraphicsContainer3D pGC = pLayer as IGraphicsContainer3D; pGC.AddElement(element); }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { try { if (button == 1) { Color color = ColorTranslator.FromHtml(SystemInfo.Instance.TextColor); IColor pColor = new RgbColorClass(); pColor.RGB = color.B * 65536 + color.G * 256 + color.R; ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine = pRubberBand.TrackNew(m_Display, null); ILineElement lineElement = new LineElementClass(); lineElement.Symbol = pLineSym; IElement element = lineElement as IElement; element.Geometry = pLine; pGraphicsContainer.AddElement(element, 0); m_ActiveView.Refresh(); } } catch (System.Exception ex) { } }
//红色线 public static void ViewPolylines(IMapControl4 pMapControl, List <CPolyline> cpllt) { //设置线段属性 ILineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 1; pSimpleLineSymbol.Color = CHelpFunc.GenerateIRgbColor(255, 0, 0) as IColor; //生成线段 IElementCollection pEleCol = new ElementCollectionClass(); for (int i = 0; i < cpllt.Count; i++) { ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pSimpleLineSymbol; IElement pElement = pLineElement as IElement; pElement.Geometry = cpllt[i].pPolyline; pEleCol.Add(pElement, 0); } //显示线段 IGraphicsContainer pGra = pMapControl.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; pGra.AddElements(pEleCol, 5); pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void ShowNavi() { IGraphicsContainer pGraphicsContainer = axMapControl1.Map as IGraphicsContainer; IActiveView pActiveView = axMapControl1.Map as IActiveView; // 得到“城市”图层 IFeatureLayer pFeatureLayer = axMapControl1.get_Layer(0) as IFeatureLayer; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; int indexFlield = pFeatureClass.Fields.FindField("PointName"); IPolyline pPolyline = new PolylineClass(); IPointCollection pPointCollection = pPolyline as IPointCollection; IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.AddField("PointName"); foreach (string staString in opPath) { pQueryFilter.WhereClause = "PointName='" + staString + "'"; IFeatureCursor pCursor = pFeatureClass.Search(pQueryFilter, true); IFeature pFeature = pCursor.NextFeature(); System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); GC.Collect(); GC.WaitForPendingFinalizers(); if (pFeature != null) { ESRI.ArcGIS.Geometry.Point pPoint = pFeature.Shape as ESRI.ArcGIS.Geometry.Point; pPointCollection.AddPoint(pPoint); } } object pSym = null; IRgbColor pColor; pColor = new RgbColorClass(); pColor.Red = 0; pColor.Blue = 255; pColor.Green = 0; pSym = new SimpleLineSymbolClass(); ISimpleLineSymbol pSym1 = pSym as ISimpleLineSymbol; pSym1.Width = 6; pSym1.Style = esriSimpleLineStyle.esriSLSDash; pSym1.Color = pColor; ILineElement pLienElement = new LineElementClass(); pLienElement.Symbol = pSym1; IElement pElement = pLienElement as IElement; pElement.Geometry = pPolyline as IGeometry; pGraphicsContainer.AddElement(pElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public static IElement ConstructPolylineElement(IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width) { ISimpleLine3DSymbol simpleLine3DSymbol = new SimpleLine3DSymbolClass(); simpleLine3DSymbol.Style = style; simpleLine3DSymbol.ResolutionQuality = HighResolution; ILineSymbol lineSymbol = simpleLine3DSymbol as ILineSymbol; lineSymbol.Color = color; lineSymbol.Width = width; ILine3DPlacement line3DPlacement = lineSymbol as ILine3DPlacement; line3DPlacement.Units = Units; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; IElement element = lineElement as IElement; element.Geometry = geometry; 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); }
private IElement method_8(IPoint ipoint_0, ILineSymbol ilineSymbol_0, string string_1) { IGroupElement element = new GroupElementClass(); IPolyline polyline = new PolylineClass(); object missing = Type.Missing; IPoint inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X + (this.double_2 / 10.0), ipoint_0.Y - (this.double_3 / 2.0)); (polyline as IPointCollection).AddPoint(inPoint, ref missing, ref missing); inPoint = new PointClass(); inPoint.PutCoords(ipoint_0.X + (this.double_2 * 0.9), ipoint_0.Y - (this.double_3 / 2.0)); (polyline as IPointCollection).AddPoint(inPoint, ref missing, ref missing); IElement element2 = new LineElementClass { Geometry = polyline }; (element2 as ILineElement).Symbol = ilineSymbol_0; element.AddElement(element2); if (this.bool_1) { element.AddElement(this.method_9(ipoint_0)); } if (string_1.Length > 0) { element.AddElement(this.method_12(ipoint_0, string_1, 10)); } return(element as IElement); }
/// <summary> /// 插入线标记 并且将线标记移动到后面 /// </summary> /// <param name="mapControl"></param> /// <param name="pGeometry"></param> /// <returns></returns> public static IElement DrawLineSymbol(AxMapControl mapControl, IGeometry pGeometry) { IRgbColor pColor = GetColor(0, 255, 255); pColor.Transparency = 255; //产生一个线符号对象 ILineSymbol pOutline = new SimpleLineSymbolClass(); pOutline.Width = 4; pOutline.Color = pColor; ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pOutline; IElement pElement = pLineElement as IElement; pElement.Geometry = pGeometry; //添加标注 InsertElement(mapControl, pElement, 0); IGraphicsContainerSelect tmpGSelect = (IGraphicsContainerSelect)mapControl.Map; //将元素移动到后面 tmpGSelect.SelectElement(pElement); IGraphicsContainer pGraphicsContainer = mapControl.Map as IGraphicsContainer; pGraphicsContainer.SendToBack(tmpGSelect.SelectedElements); tmpGSelect.UnselectAllElements(); return(pElement); }
private void AddPolyline(GraphicElement graphicElement, MilSpaceGraphicsTypeEnum graphicsType, bool doRefresh = false, bool persist = false) { IPolyline profileLine = graphicElement.Source; ILineElement lineElement = new LineElementClass(); var curList = allGraphics[graphicsType]; bool exists = curList.Any(ge => ge.ProfileId == graphicElement.ProfileId && ge.ElementId == graphicElement.ElementId); if (!persist && exists) { return; } lineElement.Symbol = DefineProfileLineSymbol(graphicsType); IElement elem = (IElement)lineElement; elem.Geometry = profileLine; graphicElement.Element = elem; DeleteGraphicsElement(graphicElement); graphics.AddElement(elem, 0); if (!exists) { curList.Add(graphicElement); } if (doRefresh) { activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
private void iRandomColorRampToolStripMenuItem_Click(object sender, EventArgs e) { IMap mmap = axMapControl1.Map; IActiveView pActiveView = mmap as IActiveView; IGeometry pLine = axMapControl1.TrackLine(); ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); IEnumColors pEnumColors = CreateRdmColorRamp(140, 220, 35, 100, 32, 80, 12, 7); IColor pColor = pEnumColors.Next(); pLineSymbol.Color = pColor; pLineSymbol.Width = 2; pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element = new LineElementClass(); element.Geometry = pLine; ILineElement pLineElement = element as ILineElement; pLineElement.Symbol = pLineSymbol; IGraphicsContainer ppGraphicsContainer = mmap as IGraphicsContainer; ppGraphicsContainer.AddElement(pLineElement as IElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void convertColorToolStripMenuItem_Click(object sender, EventArgs e) { IColor pColor = GetRGB(Color.Black); if (colorDlg.ShowDialog() == DialogResult.OK) { pColor = GetRGB(colorDlg.Color); } IMap mmap = axMapControl1.Map; IActiveView pActiveView = mmap as IActiveView; IGeometry pLine = axMapControl1.TrackLine(); ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); pLineSymbol.Color = pColor; pLineSymbol.Width = 2; pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element = new LineElementClass(); element.Geometry = pLine; ILineElement pLineElement = element as ILineElement; pLineElement.Symbol = pLineSymbol; IGraphicsContainer ppGraphicsContainer = mmap as IGraphicsContainer; ppGraphicsContainer.AddElement(pLineElement as IElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private void algorithmicColorRampToolStripMenuItem_Click(object sender, EventArgs e) { IMap mmap = axMapControl1.Map; IActiveView pActiveView = mmap as IActiveView; IGeometry pLine = axMapControl1.TrackLine(); ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass(); IEnumColors pEnumColors = CreateAlgColorRamp(GetRGB(0, 255, 0), GetRGB(255, 0, 255), 20); IColor pColor = pEnumColors.Next(); pLineSymbol.Color = pColor; pLineSymbol.Width = 2; pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; IElement element = new LineElementClass(); element.Geometry = pLine; ILineElement pLineElement = element as ILineElement; pLineElement.Symbol = pLineSymbol; IGraphicsContainer ppGraphicsContainer = mmap as IGraphicsContainer; ppGraphicsContainer.AddElement(pLineElement as IElement, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 展线 /// </summary> /// <param name="pGra">符号展现容器</param> /// <param name="line">线形状</param> private void MakeLineSymbol(IGraphicsContainer pGra, IPolyline line) { //IActiveView pAcitveView = pGra as IActiveView; IElement pEle; //定义颜色 IRgbColor pColor = new RgbColorClass(); pColor.Blue = 0; pColor.Green = 0; pColor.Red = 255; ILineElement pMakEle = new LineElementClass(); //设置线的宽度,颜色,符号,几何形状等属性 pEle = pMakEle as IElement; ILineSymbol pMakSym = new SimpleLineSymbolClass(); pMakSym.Width = 1; pMakSym.Color = pColor; pMakEle.Symbol = pMakSym; //IPolyline newline = new PolylineClass(); //newline.ToPoint = line.ToPoint; //newline.FromPoint = line.FromPoint; pEle.Geometry = line as ESRI.ArcGIS.Geometry.IGeometry; //添加线元素 pGra.AddElement(pEle, 0); //pAcitveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <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); }
// Creates Route polyline private void CreatePolyline(ISMDirections objDirections) { // create polyline IPolyline objLine = null; objLine = new PolylineClass(); // get points collection IPointCollection objPoints = null; objPoints = objLine as IPointCollection; // Adds Directions points to polyline AddPointsToPolyline(objDirections, ref objPoints); // Project points to Map projection IMxDocument objDoc = m_application.Document as IMxDocument; IMap objMap = objDoc.FocusMap; objLine.Project(objMap.SpatialReference); // create path graphics element IElement objElement = null; objElement = new LineElementClass(); objElement.Geometry = objLine; // Set line color width and style SetLineProperties(objElement); // get Graphic container IGraphicsContainer objCont = objMap as IGraphicsContainer; // Add line to map objCont.AddElement(objElement, 0); }
private void DrawLine(IPoint p1, IPoint p2) { IPolyline pline = new PolylineClass(); pline.FromPoint = p1; pline.ToPoint = p2; ILineElement lineElement; lineElement = new LineElementClass(); IElement element; ISimpleLineSymbol pSLnSym; IRgbColor pRGB; pRGB = new RgbColorClass(); pRGB.Red = 0; pRGB.Green = 0; pRGB.Blue = 0; pSLnSym = new SimpleLineSymbolClass(); pSLnSym.Color = pRGB; pSLnSym.Style = ESRI.ArcGIS.Display.esriSimpleLineStyle.esriSLSSolid; lineElement.Symbol = pSLnSym; element = lineElement as IElement; element.Geometry = pline; IGraphicsContainer graphicsContainer = this.m_pMapControl.Map as IGraphicsContainer; graphicsContainer.AddElement(element, 0); this.m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); }
/// <summary> /// 构造函数 /// </summary> /// <param name="_mapControl">arcgis地图控件</param> /// <param name="_element">要编辑的线图元</param> public EditLine(AxMapControl _mapControl, IMFElement _element) { element = _element as IMFLine; markerList = new List <EditMarker>(); lineElement = _element as LineElementClass; mapControl = _mapControl; pointList = new List <Point_ArcMap>(); }
/// <summary> /// 根据输入的要素在SceneControl中绘制元素 张琪 20110621 /// </summary> /// <param name="pSceneControl"></param> /// <param name="pGeom">几何要素</param> /// <param name="pSym"></param> public void AddGraphic(ISceneControl pSceneControl, IGeometry pGeom, ISymbol pSym) { if (pGeom == null) { return; } IElement pElement = null; switch (pGeom.GeometryType.ToString()) { case "esriGeometryPoint": //点要素 pElement = new MarkerElementClass(); IMarkerElement pPointElement = pElement as IMarkerElement; if (pSym != null) { IMarkerSymbol pMarker3DSymbol = pSym as IMarkerSymbol; pPointElement.Symbol = pMarker3DSymbol as IMarkerSymbol; } break; case "esriGeometryPolyline": //线要素 pElement = new LineElementClass(); ILineElement pLineElement = pElement as ILineElement; if (pSym != null) { ILineSymbol pLineSymbol = pSym as ILineSymbol; pLineElement.Symbol = pLineSymbol; } break; case "esriGeometryPolygon": //面要素 pElement = new PolygonElementClass(); IFillShapeElement pFillElement = pElement as IFillShapeElement; if (pSym != null) { IFillSymbol pFillSymbol = pSym as IFillSymbol; pFillElement.Symbol = pFillSymbol; } break; case "esriGeometryMultiPatch": //多面体要素 pElement = new MultiPatchElementClass(); IFillShapeElement pMultiPatchElement = pElement as IFillShapeElement; if (pSym != null) { IFillSymbol pFillSymbol = pSym as IFillSymbol; pMultiPatchElement.Symbol = pFillSymbol as IFillSymbol; } break; } pElement.Geometry = pGeom; IGraphicsContainer3D pGCon3D = pSceneControl.Scene.BasicGraphicsLayer as IGraphicsContainer3D; pGCon3D.AddElement(pElement);//在SceneControl中绘制要素 IGraphicsSelection pGS = pGCon3D as IGraphicsSelection; pSceneControl.Scene.SceneGraph.RefreshViewers(); }
/// <summary> /// 在图形容器中创建元素 /// </summary> /// <param name="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> /// 根据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); }
private void route_Search_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (this.start_time.EditValue == "" || this.end_time.EditValue == "") { MessageBox.Show("请选择起止日期"); return; } SqlHelper help = new SqlHelper(); String sql = "select * from route where tm between '" + this.start_time.EditValue + "' and '" + this.end_time.EditValue + "'"; DataTable dt = help.getMySqlRead(sql); ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol(); simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSCircle; IColor color = GisClass.GetRgbColor(0, 255, 0); simpleMarkerSymbol.Color = color; ILineElement lineElement = new LineElementClass(); IElement ele1 = lineElement as IElement; ISegment pSegment; ILine pLine = null; object o = Type.Missing; ISegmentCollection pPath = new PathClass(); for (int i = 0; i < dt.Rows.Count; i++) { IMarkerElement markerEle = new MarkerElementClass(); IElement ele = markerEle as IElement; IPoint point = new PointClass(); markerEle.Symbol = simpleMarkerSymbol; point.PutCoords(Double.Parse(dt.Rows[i]["x"].ToString()), Double.Parse(dt.Rows[i]["y"].ToString())); ele.Geometry = point; pGraphicsContainer.AddElement(ele, 0); //逐段添加线 if (i > 0 && i < dt.Rows.Count) { IPoint point1 = new PointClass(); point1.PutCoords(Double.Parse(dt.Rows[i - 1]["x"].ToString()), Double.Parse(dt.Rows[i - 1]["y"].ToString())); pLine = new LineClass(); pLine.PutCoords(point1, point); pSegment = pLine as ISegment; pPath.AddSegment(pSegment, ref o, ref o); } axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); } IGeometryCollection pPolyline = new PolylineClass(); pPolyline.AddGeometry(pPath as IGeometry, ref o, ref o); IPolyline polyline = pPolyline as IPolyline; //获取范围 IEnvelope ev = polyline.Envelope; this.axMapControl1.ActiveView.Extent = ev; ele1.Geometry = pPolyline as IPolyline; pGraphicsContainer.AddElement(ele1, 0); }
private void button1_Click(object sender, EventArgs e) { //当确定按钮被点击时 //连接数据库,路径规划 //string sqlstr = "select ST_asbinary(ST_Union(geom)) as route from pgr_fromAtoB('whu_road_feature2line'::text,114.353,30.539,114.367,30.544) ;"; string sqlstr = null; if ((startX * startY * endX * endY) != 0) { sqlstr = "select ST_asbinary(ST_Union(geom)) as route from pgr_fromAtoB('whu_road_feature2line'::text," + startX + "," + startY + "," + endX + "," + endY + ") ;"; } else { MessageBox.Show("起始点或终止点不能为空"); return; } Byte[] routeWKB = DAO.executeRouteQuery(sqlstr); IGeometry geom; int countin = routeWKB.GetLength(0); //地图容器,创建临时元素 IMap pMap = mMapControl.Map; IActiveView pActiveView = pMap as IActiveView; IGraphicsContainer pGraphicsContainer = pMap as IGraphicsContainer; if (pElement != null) { pGraphicsContainer.DeleteElement(pElement); } //转换wkb为IGeometry IGeometryFactory3 factory = new GeometryEnvironment() as IGeometryFactory3; factory.CreateGeometryFromWkbVariant(routeWKB, out geom, out countin); IPolyline pLine = (IPolyline)geom; //定义要素symbol ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColor(); pColor.Red = 11; pColor.Green = 120; pColor.Blue = 233; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; //线元素symbol绑定 ILineElement pLineElement = new LineElementClass(); pLineElement.Symbol = pLineSym; //添加geom pElement = pLineElement as IElement; pElement.Geometry = pLine; //加入地图并刷新 pGraphicsContainer.AddElement(pElement, 0); pActiveView.Refresh(); //object symbol = pLineSym as object; //mMapControl.DrawShape(pLine, ref symbol); }
private void DrawLineOnActiveView(List <int> lstIndices, double[][] arrValue, IActiveView pActiveView) { try { int intLstCnt = lstIndices.Count; IGraphicsContainer pGraphicContainer = pActiveView.GraphicsContainer; pGraphicContainer.DeleteAllElements(); IRgbColor pRgbColor = m_pSnippet.getRGB(0, 255, 255); //IRgbColor pRgbColor = new RgbColorClass(); //pRgbColor.Red = 0; //pRgbColor.Green = 255; //pRgbColor.Blue = 255; //pRgbColor.Transparency = 255; ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass(); pSimpleLineSymbol.Width = 2; pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid; pSimpleLineSymbol.Color = pRgbColor; for (int i = 0; i < intLstCnt; i++) { int intIdx = lstIndices[i]; double[] arrSelValue = arrValue[intIdx]; //drawing a polyline IPoint FromP = new PointClass(); FromP.X = arrSelValue[0]; FromP.Y = arrSelValue[1]; IPoint ToP = new PointClass(); ToP.X = arrSelValue[2]; ToP.Y = arrSelValue[3]; IPolyline polyline = new PolylineClass(); IPointCollection pointColl = polyline as IPointCollection; pointColl.AddPoint(FromP); pointColl.AddPoint(ToP); IElement pElement = new LineElementClass(); ILineElement pLineElement = (ILineElement)pElement; pLineElement.Symbol = pSimpleLineSymbol; pElement.Geometry = polyline; pGraphicContainer.AddElement(pElement, 0); } pActiveView.Refresh(); } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
/// <summary> /// 在图形容器中创建线元素 /// </summary> /// <param name="graphicsContainer">图形容器,新建的元素将添加到该图形容器中</param> /// <param name="polyline">线图形,用于创建线元素</param> /// <returns></returns> public static ILineElement CreatePolylineElement(this IGraphicsContainer graphicsContainer, IPolyline polyline) { ILineElement lineElement = new LineElementClass(); IElement element = (IElement)lineElement; element.Geometry = polyline; graphicsContainer.AddElement(element, 0); return(lineElement); }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="pGeometry">几何图形</param> /// <param name="lineColor">边框颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns></returns> private static IElement CreateElement(IGeometry pGeometry, IRgbColor lineColor, IRgbColor fillColor) { if (pGeometry == null || lineColor == null || fillColor == null) { return(null); } IElement pElem = null; try { if (pGeometry is IEnvelope) { pElem = new RectangleElementClass(); } else if (pGeometry is IPolygon) { pElem = new PolygonElementClass(); } else if (pGeometry is ICircularArc) { ISegment pSegCircle = pGeometry as ISegment;//QI ISegmentCollection pSegColl = new PolygonClass(); object o = Type.Missing; pSegColl.AddSegment(pSegCircle, ref o, ref o); IPolygon pPolygon = pSegColl as IPolygon; pGeometry = pPolygon as IGeometry; pElem = new CircleElementClass(); } else if (pGeometry is IPolyline) { pElem = new LineElementClass(); } if (pElem == null) { return(null); } pElem.Geometry = pGeometry; IFillShapeElement pFElem = pElem as IFillShapeElement; ISimpleFillSymbol pSymbol = new SimpleFillSymbolClass(); pSymbol.Color = fillColor; pSymbol.Outline.Color = lineColor; pSymbol.Style = esriSimpleFillStyle.esriSFSCross; if (pSymbol == null) { return(null); } pFElem.Symbol = pSymbol; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(pElem); }
public override void OnDblClick() { base.OnDblClick(); if (this.pNewLineFeedback != null) { IPolyline pPolyline = this.pNewLineFeedback.Stop(); IElement pElement = new LineElementClass(); pElement.Geometry = pPolyline; ((IGraphicsContainer)this.m_hookHelper.FocusMap).AddElement(pElement, 0); this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
/// <summary> /// 释放该类 /// </summary> public void Dispose() { ReleaseCommond(); CommondExecutedEvent = null; currentPoint = null; markerList = null; editPoint = null; pointList = null; layer = null; mapControl = null; lineElement = null; }
/// <summary> /// 创建图形元素 /// </summary> /// <param name="geometry">几何图形</param> /// <param name="lineColor">边界颜色</param> /// <param name="fillColor">填充颜色</param> /// <returns>图形元素</returns> public static IElement CreateElement(IGeometry geometry, IRgbColor lineColor, IRgbColor fillColor) { if (geometry == null || lineColor == null || fillColor == null) { return(null); } IElement element = null; // 判断图形的类型 if (geometry is IEnvelope) { element = new RectangleElementClass(); } else if (geometry is IPolygon) { element = new PolygonElementClass(); } else if (geometry is ICircularArc) { ISegment segment = geometry as ISegment; ISegmentCollection segmentCollection = new PolygonClass(); segmentCollection.AddSegment(segment, Type.Missing, Type.Missing); IPolygon polygon = segmentCollection as IPolygon; geometry = polygon as IGeometry; element = new CircleElementClass(); } else if (geometry is IPolyline) { element = new LineElementClass(); } if (element == null) { return(null); } element.Geometry = geometry; ISimpleFillSymbol symbol = new SimpleFillSymbolClass(); symbol.Outline.Color = lineColor; symbol.Color = fillColor; symbol.Style = esriSimpleFillStyle.esriSFSCross; if (symbol == null) { return(null); } IFillShapeElement fillShapeElement = element as IFillShapeElement; fillShapeElement.Symbol = symbol; return(element); }
private void AddPolyline(GraphicElement graphicElement, MilSpaceGraphicsTypeEnum graphicsType, IRgbColor color = null, LineType lineType = LineType.DefaultLine, bool doRefresh = false, bool persist = false, int width = 2) { IPolyline profileLine = graphicElement.Source; ILineElement lineElement = new LineElementClass(); var curList = allGraphics[graphicsType]; bool exists = curList.Any(ge => ge.ProfileId == graphicElement.ProfileId && ge.ElementId == graphicElement.ElementId && ge.LineId == graphicElement.LineId); if (!persist && exists) { return; } if (color == null) { color = grapchucsTypeColors[graphicsType](); } if (lineType == LineType.Line) { lineElement.Symbol = DefineProfileLineSymbol(graphicsType, color, width); } else { lineElement.Symbol = DefineProfileDecorationLineSymbol(graphicsType, color, width, lineType); } IElement elem = (IElement)lineElement; elem.Geometry = profileLine; graphicElement.Element = elem; DeleteGraphicsElement(graphicElement); graphics.AddElement(elem, 0); if (!exists) { curList.Add(graphicElement); } if (doRefresh) { activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } }
public MapGraphicTrackExtension() { ILineElement traceElement = new LineElementClass(); SetDefaultSymbol(traceElement); //add a tag to the trace line IElementProperties elemProps = (IElementProperties)traceElement; elemProps.Name = "{E63706E1-B13C-4184-8AB8-97F67FA052D4}"; bool showTrace = true; propSet = new PropertySetClass(); propSet.SetProperty("Line Element", traceElement); propSet.SetProperty("Show Trace", showTrace); persist = (IPersistStream)propSet; }
///<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, double width, esriSimpleLineStyle simpleLineStyle) { IElement element; ILineElement lineElement = new LineElementClass(); element = lineElement as IElement; ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbolClass(); simpleLineSymbol.Style = simpleLineStyle; simpleLineSymbol.Color = ColorSelection.GetColor(); simpleLineSymbol.Width = width; element.Geometry = geometry; ILineSymbol lineSymbol = simpleLineSymbol as ILineSymbol; lineElement.Symbol = lineSymbol; return element; }
public static IElement ConstructPolylineElement(IGeometry geometry, IColor color, esriSimple3DLineStyle style, double width) { ISimpleLine3DSymbol simpleLine3DSymbol = new SimpleLine3DSymbolClass(); simpleLine3DSymbol.Style = style; simpleLine3DSymbol.ResolutionQuality = HighResolution; ILineSymbol lineSymbol = simpleLine3DSymbol as ILineSymbol; lineSymbol.Color = color; lineSymbol.Width = width; ILine3DPlacement line3DPlacement = lineSymbol as ILine3DPlacement; line3DPlacement.Units = Units; ILineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; IElement element = lineElement as IElement; element.Geometry = geometry; return element; }
//���ƣȣ��ԣã� public static void HatchDraw(AxMapControl ppAxMapControl, ISimpleLineSymbol pHatchSymMajor, ISimpleLineSymbol pHatchSymMinor, ITextSymbol pTxtSym, IFeatureLayer pFeatLayer, bool bEnds, bool bEndsOnly, double dHatchLen, double dTxtInterval, double dHatchOffset, double dMajorAngle, bool bOverRideMajor, string graphicslayername) { //����ͼ��ͼ��ΪSEWER TV���ͼ�� IFeatureCursor pFeatCursor = pFeatLayer.Search(null, true); SetGraphicsLayer(ppAxMapControl, pFeatLayer.Name, graphicslayername); //����SEWER TV���ͼ��ͼ�� IGraphicsContainer pGraphicsContainer = ppAxMapControl.ActiveView.FocusMap.ActiveGraphicsLayer as IGraphicsContainer; //���ͼ��ͼ�� pGraphicsContainer.DeleteAllElements(); IFeature pFeature = pFeatCursor.NextFeature(); IPolyline pMajorHatchPL = new PolylineClass(); IPolyline pMinorHatchPL = new PolylineClass(); IPolyline pPL; IMAware pPLM; //IMCollection pMColl; IGeometryCollection pGeomColl; ILineElement pLineElement; IElement pElement = null; int cnt; IPath pPath; string txt; double txtlen; IPath pTxtPath; double angle; //IPoint pTxtPt; ISegmentCollection pSC; ISegment pSeg; ISegmentM pSegM; double m1 = 0; //double m2 = 0; //IPoint pFromPt; //IMarkerSymbol pMSym; IMask pMask; ITextElement pTextElement; ISegmentCollection pSegment; ISegmentCollection pPolyline; while (pFeature != null) { pPL = pFeature.Shape as IPolyline; pPLM = pPL as IMAware; if (pPLM.MAware) { if (bEndsOnly) { MakeHatchesEndsOnly(pPL, bEnds, pMajorHatchPL, pMinorHatchPL, dHatchLen, dTxtInterval, dHatchOffset); } else { } // Draw the major hatches if they are lines if (pHatchSymMajor is ILineSymbol) { pLineElement = new LineElementClass(); pLineElement.Symbol = pHatchSymMajor; pElement = pLineElement as IElement; pElement.Geometry = pMajorHatchPL as IGeometry; pGraphicsContainer.AddElement(pElement, 0); } // Draw the major hatches if they are markers and the text... pGeomColl = pMajorHatchPL as IGeometryCollection; cnt = pGeomColl.GeometryCount - 1; for (int j = 0; j <= cnt; j++) { pPath = pGeomColl.get_Geometry(j) as IPath; if (bOverRideMajor) angle = dMajorAngle; else angle = GetAngle(pPath) + dMajorAngle; pSC = pPath as ISegmentCollection; pSeg = pSC.get_Segment(0); pSegM = pSeg as ISegmentM; txt = Convert.ToString(Math.Round(m1, 1)); txtlen = pTxtSym.Size; angle = GetAngle(pPath as ICurve); if (ShouldFlip(angle)) { pTxtPath = MakeTextPath(pPath, txtlen * 2); angle += 180; pTxtSym.RightToLeft = false; pTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } else { //angle = angle; pTxtPath = MakeTextPath(pPath, txtlen); pTxtSym.RightToLeft = false; pTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } pTxtSym.Angle = angle; //Ϊ�ı�����MASK�����û�з��ţ�����Ϊ���� pMask = pTxtSym as IMask; pMask.MaskSize = 2; pMask.MaskStyle = esriMaskStyle.esriMSHalo; pTextElement = new TextElementClass(); pTextElement.Symbol = pTxtSym; pTextElement.Text = txt + " "; pElement = pTextElement as IElement; pSegment = pTxtPath as ISegmentCollection; pPolyline = new PolylineClass(); pPolyline.AddSegmentCollection(pSegment); pElement.Geometry = pPolyline as IGeometry; pGraphicsContainer.AddElement(pElement, 0); } } pFeature = pFeatCursor.NextFeature(); } }
public static void drawPolyline(IActiveView pActiveView, IPolyline pGeom) { try { IGraphicsContainer iGC = pActiveView as IGraphicsContainer; ILineSymbol ipLineSymbol = new CartographicLineSymbolClass(); ipLineSymbol.Width = 5; IRgbColor pRgbColor = new RgbColorClass(); pRgbColor.Red = 255; pRgbColor.Green = 0; pRgbColor.Blue = 0; ipLineSymbol.Color = pRgbColor as IColor; IElement pEle; ILineElement pLE; if (pGeom != null) { pEle = new LineElementClass() as IElement; pLE = pEle as ILineElement; pLE.Symbol = ipLineSymbol; pEle.Geometry = pGeom; iGC.AddElement(pEle, 0); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, pActiveView.Extent); } catch (Exception e) { MessageBox.Show(e.Message); } }
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为屏幕坐标 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作为图片的容器 pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //axMapControl.Refresh(); break; case "Line": ILineElement pLineElement; IElement pLElement; IPolyline pLine; pLineElement = new LineElementClass(); pLElement = pLineElement as IElement; RubberLineClass pRubberBandd = new RubberLineClass(); pLine = pRubberBandd.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolyline; pLElement.Geometry = pLine; pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器 pGraphicsContainer.AddElement(pLElement, 0);//把刚刚的element转到容器上 axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); 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; } }
private void AddLineElement(IGeometry pGeom, IGraphicsContainer pGraphicsContainer) { ISimpleLineSymbol pLineSym; pLineSym = new SimpleLineSymbolClass(); pLineSym.Color = getRGB(255, 0, 0); pLineSym.Width = 1; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; ILineElement plineEle; plineEle = new LineElementClass(); plineEle.Symbol = pLineSym; IElement pEles; pEles = plineEle as IElement; pEles.Geometry = pGeom as IPolyline; pGraphicsContainer.AddElement(pEles, 0); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <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; }
public bool onMapControlMouseDown() { IPolyline mainRoadPolyline = mapControl.TrackLine() as IPolyline; ILineElement mainRoadLineElement = new LineElementClass(); IElement element = mainRoadLineElement as IElement; element.Geometry = mainRoadPolyline; mainRoadList[mainRoadList.Count - 1].lineElement = mainRoadLineElement; mainRoadList[mainRoadList.Count - 1].updatePath(); GisUtil.DrawPolylineElement(mainRoadLineElement, mapControl); mapControlMouseDown = null; mainWindow.unmask(); return true; }
public static void MoveConnectionsToNewLine(IApplication app, double snapTol, List<MoveConnectionsDetails> moveConDetails) { IEditor editor = null; ESRI.ArcGIS.esriSystem.IStatusBar statusBar = null; ESRI.ArcGIS.esriSystem.IAnimationProgressor animationProgressor = null; ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = null; ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = null; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = null; ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = null; ICommandItem pCmdItem; IMxDocument pMxDoc = ((IMxDocument)app.Document); IGeometricNetwork pGN = null; IFeature pFeature = null; IPoint pTracePoint = null; ISimpleLineSymbol pSimpleLineSym = null; IRgbColor pRGBColor = null; IGraphicsContainer gc = null; IElement pMoveElemFirst = null; IElementProperties3 pMoveElemPropFirst = null; IElement element = null; IElementProperties3 elementProp = null; ILineElement lineElem = null; IJunctionFeature pJuncFeat = null; IFeatureLayer pSourceLayer = null; IFeature pSourceFeature = null; IFeature pMoveFeat = null; INetworkFeature pNetworkSourceFeature = null; IEdgeFeature iTargetEdgeFeat = null; IComplexEdgeFeature iCEdge = null; IFeatureClass pOraphFC = null; List<int> OIDs = new List<int>(); List<string> FeatLoc = new List<string>(); List<IObjectClass> FCs = new List<IObjectClass>(); IPolyline pL; IHitTest pHtTest = null;//= pPolyline as IHitTest; IPoint pHitPntOne = new PointClass(); double pHitDistOne = -1; int pHitPrtOne = -1; int pHitSegOne = -1; bool pHitSideOne = false; //IFeatureCursor pFeatCursor = null; IFeatureLayer pMainLayer = null; //IFeatureLayer pMainLayer = null; //IFeatureLayer pTapLayer = null; ILayer pLay = null; try { editor = Globals.getEditor(ref app); if (editor.EditState != esriEditState.esriStateEditing) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("MustBEditg"), A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_2")); return; } pTracePoint = pMxDoc.CurrentLocation; pFeature = Globals.GetNetworkAndFeatureAtLocation(pTracePoint, app, esriElementType.esriETEdge, out pGN, snapTol); if (pFeature == null) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("NoFtrFndOnClck")); return; } int idxDet = -1; for (int i = 0; i < moveConDetails.Count; i++) { //MoveConnectionsDetails conDet = moveConDetails[i]; bool FCorLayerTemp = true; pMainLayer = (IFeatureLayer)Globals.FindLayer(app, moveConDetails[i].LineLayer, ref FCorLayerTemp); if (pMainLayer != null) { if (pMainLayer.FeatureClass.ObjectClassID == pFeature.Class.ObjectClassID) { idxDet = i; break; } } } if (idxDet == -1) return; if (Globals.IsEditable(ref pFeature, ref editor) == false) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13b")); return; } if (pFeature.FeatureType != esriFeatureType.esriFTComplexEdge) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsMess_13c")); return; } pRGBColor = Globals.GetColor(255, 0, 0); pSimpleLineSym = Globals.CreateSimpleLineSymbol(pRGBColor, 2, esriSimpleLineStyle.esriSLSSolid); gc = pMxDoc.FocusMap as IGraphicsContainer; gc.Reset(); element = gc.Next(); while (element != null) { elementProp = element as IElementProperties3; if (elementProp.Name.Contains("MoveFeatureFlag")) { if (pMoveElemFirst == null) { pMoveElemFirst = element; pMoveElemPropFirst = elementProp; string[] firstVals = pMoveElemPropFirst.Name.ToString().Split(':'); if (firstVals[1] != pFeature.Class.ObjectClassID.ToString()) { MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13a")); return; } break; } } element = gc.Next(); } lineElem = new LineElementClass(); lineElem.Symbol = pSimpleLineSym; element = (IElement)lineElem; element.Geometry = pFeature.ShapeCopy; elementProp = element as IElementProperties3; elementProp.Name = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13a") + ": " + pFeature.Class.ObjectClassID.ToString() + ":" + pFeature.OID; elementProp.ReferenceScale = pMxDoc.FocusMap.ReferenceScale; gc.AddElement(element, 0); pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pFeature.Shape.Envelope); if (pMoveElemFirst == null) return; else { List<int> LayersToMoveIDs = new List<int>(); foreach (string Lay in moveConDetails[idxDet].LayersToMove) { bool FCorLayerTemp = true; pLay = Globals.FindLayer(app, Lay, ref FCorLayerTemp); if (pLay != null) { LayersToMoveIDs.Add(((IFeatureLayer)pLay).FeatureClass.ObjectClassID); } } statusBar = app.StatusBar; animationProgressor = statusBar.ProgressAnimation; animationProgressor.Show(); animationProgressor.Play(0, -1, -1); statusBar.set_Message(0, A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a")); // Create a CancelTracker trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = app.hWnd; stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = 4; stepProgressor.StepValue = 1; stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a"); // Create the ProgressDialog. This automatically displays the dialog progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = true; progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a"); progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13a"); progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressSpiral; System.Boolean boolean_Continue = true; stepProgressor.Step(); boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Step(); stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsLbl_13b"); //ProfileFindPath(); pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOffCommand", app); if (pCmdItem != null) { pCmdItem.Execute(); } string[] elemInfo = (elementProp = pMoveElemFirst as IElementProperties3).Name.Split(':'); pSourceLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap, elemInfo[1]) as IFeatureLayer; pSourceFeature = pSourceLayer.FeatureClass.GetFeature(Convert.ToInt32(elemInfo[2])); pNetworkSourceFeature = (INetworkFeature)pSourceFeature; iTargetEdgeFeat = (IEdgeFeature)pNetworkSourceFeature; iCEdge = (pNetworkSourceFeature) as IComplexEdgeFeature; pOraphFC = pGN.OrphanJunctionFeatureClass; editor.StartOperation(); pL = pSourceFeature.ShapeCopy as IPolyline; boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Step(); stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13b"); for (int i = 0; i < iCEdge.JunctionFeatureCount; i++) { pJuncFeat = iCEdge.get_JunctionFeature(i); if ((pJuncFeat as IFeature).Class.ObjectClassID != pOraphFC.ObjectClassID && LayersToMoveIDs.Contains((pJuncFeat as IFeature).Class.ObjectClassID)) { if (pL.FromPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.FromPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y) { FeatLoc.Add("From"); } else if (pL.ToPoint.X == ((pJuncFeat as IFeature).Shape as IPoint).X && pL.ToPoint.Y == ((pJuncFeat as IFeature).Shape as IPoint).Y) { FeatLoc.Add("To"); } else { FeatLoc.Add("Along"); } OIDs.Add((pJuncFeat as IFeature).OID); FCs.Add((pJuncFeat as IFeature).Class); } } boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Step(); stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13c"); pNetworkSourceFeature.Disconnect(); boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Step(); stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("GeoNetToolsProc_13d"); string msg = ""; List<IFeature> pM = new List<IFeature>(); for (int i = 0; i < OIDs.Count; i++) { pMoveFeat = (FCs[i] as IFeatureClass).GetFeature(OIDs[i]); esriGeometryHitPartType pSearchLoc; if (FeatLoc[i] == "From" || FeatLoc[i] == "To") { pSearchLoc = esriGeometryHitPartType.esriGeometryPartEndpoint; } else { pSearchLoc = esriGeometryHitPartType.esriGeometryPartBoundary; } pHtTest = pFeature.ShapeCopy as IHitTest; bool bHitOne = pHtTest.HitTest(pMoveFeat.Shape as IPoint, 50, pSearchLoc, pHitPntOne, ref pHitDistOne, ref pHitPrtOne, ref pHitSegOne, ref pHitSideOne); if (bHitOne != false) { if ((pMoveFeat.Shape as IPoint).Z != null && Globals.IsNumeric((pMoveFeat.Shape as IPoint).Z.ToString())) pHitPntOne.Z = (pMoveFeat.Shape as IPoint).Z; pMoveFeat.Shape = pHitPntOne; pM.Add(pMoveFeat); try { pMoveFeat.Store(); INetworkFeature netFeature = null; netFeature = pMoveFeat as INetworkFeature; netFeature.Connect(); } catch { if (msg == "") { msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b"); } else { msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (FCs[i] as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b"); } } } } ////foreach (IFeature pF in pM) ////{ //// try //// { //// pF.Store(); //// INetworkFeature netFeature = null; //// netFeature = pF as INetworkFeature; //// netFeature.Connect(); //// } //// catch //// { //// if (msg == "") //// { //// msg = A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b"); //// } //// else //// { //// msg = msg + "\n" + A4LGSharedFunctions.Localizer.GetString("FeatureIn") + (pF.Class as IFeatureClass).AliasName + A4LGSharedFunctions.Localizer.GetString("WithOID") + pMoveFeat.OID + A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13b"); //// } //// } //// if (msg != "") //// { //// MessageBox.Show(msg); //// } ////} //INetworkFeature pNetworkTargetFeature = (INetworkFeature)pFeature; // IFeatureLayer pTargetLayer = Globals.FindLayerByClassID(pMxDoc.FocusMap,pFeature.Class.CLSID.ToString()) as IFeatureLayer; boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { return; } stepProgressor.Step(); stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("Complete"); try { Globals.RemoveTraceGraphics(pMxDoc.FocusMap, true); } catch { } // unpress the UIToolControl button app.CurrentTool = null; app.RefreshWindow(); pMxDoc.ActiveView.Refresh(); return; } } catch (Exception ex) { try { editor.AbortOperation(); } catch { } MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsError_13c") + ex.Message); return; } finally { try { editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("GeoNetToolsDone_13a")); } catch { } if (progressDialog2 != null) progressDialog2.HideDialog(); progressDialog2 = null; pCmdItem = Globals.GetCommand("ArcGIS4LocalGovernment_AttributeAssistantSuspendOnCommand", app); if (pCmdItem != null) { pCmdItem.Execute(); } pLay = null; statusBar = null; animationProgressor = null; trackCancel = null; progressDialogFactory = null; stepProgressor = null; progressDialog2 = null; pCmdItem = null; pMxDoc = null; pGN = null; pFeature = null; pTracePoint = null; pSimpleLineSym = null; pRGBColor = null; gc = null; pMoveElemFirst = null; pMoveElemPropFirst = null; element = null; elementProp = null; lineElem = null; pJuncFeat = null; pSourceLayer = null; pSourceFeature = null; pMoveFeat = null; pNetworkSourceFeature = null; iTargetEdgeFeat = null; iCEdge = null; pOraphFC = null; OIDs = null; FeatLoc = null; FCs = null; pL = null; pHtTest = null;//= pPolyline as IHitTest; pHitPntOne = null; editor = null; } }
/// <summary> /// Adds a graphic element to the map graphics container /// </summary> /// <param name="geom">IGeometry</param> internal void AddGraphicToMap(IGeometry geom, IColor color, bool IsTempGraphic = false, esriSimpleMarkerStyle markerStyle = esriSimpleMarkerStyle.esriSMSCircle, esriRasterOpCode rasterOpCode = esriRasterOpCode.esriROPNOP) { if (geom == null || ArcMap.Document == null || ArcMap.Document.FocusMap == null) return; IElement element = null; double width = 2.0; geom.Project(ArcMap.Document.FocusMap.SpatialReference); if(geom.GeometryType == esriGeometryType.esriGeometryPoint) { // Marker symbols var simpleMarkerSymbol = new SimpleMarkerSymbol() as ISimpleMarkerSymbol; simpleMarkerSymbol.Color = color; simpleMarkerSymbol.Outline = true; simpleMarkerSymbol.OutlineColor = color; simpleMarkerSymbol.Size = 5; simpleMarkerSymbol.Style = markerStyle; var markerElement = new MarkerElement() as IMarkerElement; markerElement.Symbol = simpleMarkerSymbol; element = markerElement as IElement; } else if(geom.GeometryType == esriGeometryType.esriGeometryPolyline) { // create graphic then add to map var lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = color; lineSymbol.Width = width; if (IsTempGraphic && rasterOpCode != esriRasterOpCode.esriROPNOP) { lineSymbol.Width = 1; lineSymbol.ROP2 = rasterOpCode; } var le = new LineElementClass() as ILineElement; element = le as IElement; le.Symbol = lineSymbol; } if (element == null) return; IClone clone = geom as IClone; element.Geometry = clone as IGeometry; var mxdoc = ArcMap.Application.Document as IMxDocument; var av = mxdoc.FocusMap as IActiveView; var gc = av as IGraphicsContainer; // store guid var eprop = element as IElementProperties; eprop.Name = Guid.NewGuid().ToString(); if (this is LinesViewModel) GraphicsList.Add(new Graphic(GraphicTypes.Line, eprop.Name, geom, IsTempGraphic)); else if (this is CircleViewModel) GraphicsList.Add(new Graphic(GraphicTypes.Circle, eprop.Name, geom, IsTempGraphic)); else if (this is EllipseViewModel) GraphicsList.Add(new Graphic(GraphicTypes.Ellipse, eprop.Name, geom, IsTempGraphic)); else if (this is RangeViewModel) GraphicsList.Add(new Graphic(GraphicTypes.RangeRing, eprop.Name, geom, IsTempGraphic)); gc.AddElement(element, 0); //refresh map av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); if (!IsTempGraphic) RaisePropertyChanged(() => HasMapGraphics); }
private static void DrawLine(IGroupElement3 group, IPolyline line) { //LineGraphics (LineElementClass) will only accept IPolyline (not ILine) var element = new LineElementClass { Geometry = line }; group.AddElement(element); }
private void PathSolve_Click_1(object sender, EventArgs e) { SolvePath("Weight");//先解析路径 IPolyline ipPolyResult = PathPolyLine();//最后返回最短路径 clicked = false; IRgbColor color = new RgbColorClass(); color.Red = 255; IElement element = new LineElementClass(); ILineSymbol linesymbol = new SimpleLineSymbolClass(); linesymbol.Color = color as IColor; linesymbol.Width = 100; element.Geometry = m_ipPolyline; pGC.AddElement(element, 2); m_ipActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); CloseWorkspace(); }
/// <summary> /// 画线 /// <param name="arrPointAll">点坐标数组</param> ///<returns></returns> private void DrawLine2(ArrayList arrPointAll) { if (arrPointAll.Count <= 0)//点坐标数组不能为空 { return; } IActiveView activeView = this.axMapControl.ActiveView.FocusMap as IActiveView; //删除以前的element //DeleteOldElement(activeView.GraphicsContainer); // 获取IRGBColor接口 IRgbColor color = new RgbColor(); // 设置颜色属性 color.Red = 255; color.Transparency = 255; //点 IPoint pPoint = new PointClass(); //线样式 ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = color; lineSymbol.Style = esriSimpleLineStyle.esriSLSInsideFrame; lineSymbol.Width = 10; //线元素 ILineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; //创建线 IPolyline m_Polyline = new PolylineClass(); //点集合 IPointCollection m_PointCollection = new PolylineClass(); //点数组 ArrayList arrPoint = new ArrayList(); object missing = Type.Missing; for (int i = 0; i < arrPointAll.Count; i++) { //pPoint.PutCoords(int.Parse(arrPointAll[i].ToString()), int.Parse(arrPointAll[i].ToString())); pPoint.PutCoords(-1520445, 1038916); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); pPoint.PutCoords(389327, 1613427); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); } //QI for IPolyline m_Polyline = m_PointCollection as IPolyline; //放大地图 //折线范围 IEnvelope pEnvelope = m_Polyline.Envelope; //折线区域 IArea pArea = pEnvelope as IArea; pPoint = pArea.Centroid; // this.ChangeEnvelope(pPoint, 0.06, 0.06); //QI for IElement IElement element = lineElement as IElement; element.Geometry = m_Polyline; //加载线元素到地图 activeView.GraphicsContainer.AddElement(element, 0); //Refresh the graphics activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <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; }
private List<string> ExportSymbol(IStyleGallery sg,string symbolType, int col, int row, int size,int width, int labelsize, int label_h, int size_w, int size_h, double height, string cat, IPageLayout3 layout) { List<string> pdfpages = new List<string>(); IGraphicsContainer con = layout as IGraphicsContainer; IPage page = layout.Page; int r = 0; int c = 0; int p = 0; IEnumStyleGalleryItem items = sg.get_Items(symbolType, "", cat); IStyleGalleryItem item = items.Next(); while (item != null) { #region Symbol if (symbolType == "Marker Symbols") { IMarkerElement mele = new MarkerElementClass(); IPoint ptn = new PointClass(); ptn.PutCoords(c * size_w + size / 2, height - (r * size_h + size / 2)); IElement ele_i = mele as IElement; ele_i.Geometry = ptn; IMarkerSymbol sym_m = item.Item as IMarkerSymbol; sym_m.Size = size; mele.Symbol = sym_m; con.AddElement(ele_i, 0); } else if (symbolType == "Line Symbols") { ILineElement lele = new LineElementClass(); IPolyline line = new PolylineClass(); IPoint ptn_f = new PointClass(); ptn_f.PutCoords(c * size_w + size / 4, height - (r * size_h + size * 3 / 4)); IPoint ptn_t = new PointClass(); ptn_t.PutCoords(c * size_w + size * 3 / 4, height - (r * size_h + size / 4)); line.FromPoint = ptn_f; line.ToPoint = ptn_t; IElement ele_i = lele as IElement; ele_i.Geometry = line; ILineSymbol sym_l = item.Item as ILineSymbol; sym_l.Width = width; lele.Symbol = sym_l; con.AddElement(ele_i, 0); } else if (symbolType == "Fill Symbols") { IRectangleElement fele = new RectangleElementClass(); IFillShapeElement fsele = fele as IFillShapeElement; IEnvelope env_f = new EnvelopeClass(); env_f.PutCoords(c * size_w + size / 4, height - (r * size_h + size * 3 / 4), c * size_w + size * 3 / 4, height - (r * size_h + size / 4)); IElement ele_i = fele as IElement; ele_i.Geometry = env_f; IFillSymbol sym_f = item.Item as IFillSymbol; fsele.Symbol = sym_f; con.AddElement(ele_i, 0); } #endregion if (cbGrid.Checked) { #region Grid IEnvelope env_g = new EnvelopeClass(); env_g.PutCoords(c * size_w, height - r * size_h, c * size_w + size_w, height - r * size_h - size_h); IRectangleElement gele = new RectangleElementClass(); IElement ele_g = gele as IElement; ele_g.Geometry = env_g; IFillSymbol sym_g = new SimpleFillSymbolClass(); IRgbColor color_g = new RgbColorClass(); color_g.NullColor = true; sym_g.Color = color_g; IFillShapeElement fshp_g = ele_g as IFillShapeElement; fshp_g.Symbol = sym_g; con.AddElement(ele_g, 0); #endregion } #region Label ITextElement tele = new ParagraphTextElementClass(); IElement ele_t = tele as IElement; tele.Text = item.Name; IEnvelope env_l = new EnvelopeClass(); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); env_l.PutCoords(c * size_w, height - r * size_h - size_h + label_h, c * size_w + size_w, height - r * size_h - size_h); ele_t.Geometry = env_l; ITextSymbol sym_label = new TextSymbolClass(); sym_label.Size = labelsize/2; IRgbColor color = new RgbColorClass(); color.NullColor = true; ISimpleLineSymbol sym_border = new SimpleLineSymbolClass(); sym_border.Color = color; ISymbolBorder border = new SymbolBorderClass(); border.LineSymbol = sym_border; IFrameProperties fp = ele_t as IFrameProperties; fp.Border = border; con.AddElement(ele_t, 0); #endregion if (c < col - 1) { c++; } else { c = 0; if (r < row - 1) { r++; } else { IActiveView av = layout as IActiveView; string temp_pdf = System.IO.Path.GetTempFileName() + ".pdf"; ExportPDF(av, temp_pdf); pdfpages.Add(temp_pdf); con.DeleteAllElements(); r = 0; c = 0; p++; } } item = items.Next(); } if (con.Next() != null) { IActiveView av = layout as IActiveView; string temp_pdf = System.IO.Path.GetTempFileName() + ".pdf"; ExportPDF(av, temp_pdf); pdfpages.Add(temp_pdf); con.DeleteAllElements(); } return pdfpages; }
private void onMapControlMouseDown(Village village) { IPolyline innerRoadPolyline = mapControl.TrackLine() as IPolyline; //这里是不是要对画好的线做一下检查, 比如保证内部路穿过了小区区域. IPolygonElement villagePolygonElement = village.polygonElement; IPolygon villagePolygon = (villagePolygonElement as IElement).Geometry as IPolygon; IRelationalOperator innerRoadPolylineRelationalOperator = innerRoadPolyline as IRelationalOperator; IRelationalOperator villagePolygonRelationOperator = villagePolygon as IRelationalOperator; ITopologicalOperator villagePolygonTopologicalOperator = villagePolygon as ITopologicalOperator; IPolyline villageBoundaryPolyline = villagePolygonTopologicalOperator.Boundary as IPolyline; ITopologicalOperator villageBoundaryPolylineTopologicalOperator = villageBoundaryPolyline as ITopologicalOperator; IPointCollection pointCollection = villageBoundaryPolylineTopologicalOperator.Intersect(innerRoadPolyline, esriGeometryDimension.esriGeometry0Dimension) as IPointCollection; if (pointCollection.PointCount < 2) { Ut.M("内部路必须穿过小区"); mainWindow.unmask(); return; } innerRoadPolyline = villagePolygonTopologicalOperator.Intersect(innerRoadPolyline, esriGeometryDimension.esriGeometry1Dimension) as IPolyline; if (village.innerRoad.lineElement != null) { GisUtil.ErasePolylineElement(village.innerRoad.lineElement, mapControl); } ILineElement innerRoadLineElement = new LineElementClass(); IElement element = innerRoadLineElement as IElement; element.Geometry = innerRoadPolyline; village.innerRoad.lineElement = innerRoadLineElement; village.innerRoad.updatePath(); GisUtil.DrawPolylineElement(innerRoadLineElement, mapControl); mainWindow.unmask(); }
/// <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 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> /// ���Ƽ���ͼ�� /// </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.esriGeometryPolyline://Polyline�� ISimpleLineSymbol simpleLineSymbol = m_NewLineFeedback.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> /// 聚焦到目标地物 /// </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(); }
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>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 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); } }
private void DrawLine(DataSet ds, IRgbColor color) { IMxDocument doc = ArcMap.Document; IMap map = doc.FocusMap; IActiveView activeView = doc.ActiveView.FocusMap as IActiveView; IPoint pPoint = new PointClass(); //线样式 ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); lineSymbol.Color = color; lineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot; lineSymbol.Width = 2; //线元素 ILineElement lineElement = new LineElementClass(); lineElement.Symbol = lineSymbol; //创建线 IPolyline m_Polyline = new PolylineClass(); //点集合 IPointCollection m_PointCollection = new PolylineClass(); //点数组 ArrayList arrPoint = new ArrayList(); object missing = Type.Missing; //while (sqlread.Read()) //前进一条纪录 //{ // int i = sqlread.GetInt32(0); // double x = sqlread.GetDouble(1); // double y = sqlread.GetDouble(2); // int index = sqlread.GetInt32(3); // //标记 // IPoint pPoints = new PointClass(); // //调用GetProject2方法经纬度转换成米 // pPoints = GetProject(x, y); // CreateTextElment(pPoints.X, pPoints.Y, index); // pPoint.PutCoords(Convert.ToDouble(pPoints.X), Convert.ToDouble(pPoints.Y)); // m_PointCollection.AddPoint(pPoint, ref missing, ref missing); //} if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //画线 double dx = Convert.ToDouble(ds.Tables[0].Rows[i]["GISLongitude"]); double dy = Convert.ToDouble(ds.Tables[0].Rows[i]["GISLatitude"]); int index = Convert.ToInt32(ds.Tables[0].Rows[i]["Seq"]); IPoint pPoints = new PointClass(); //调用GetProject2方法经纬度转换成米 pPoints = GetProject(dx, dy); pPoint.PutCoords(Convert.ToDouble(pPoints.X), Convert.ToDouble(pPoints.Y)); m_PointCollection.AddPoint(pPoint, ref missing, ref missing); } } m_Polyline = m_PointCollection as IPolyline; //折线范围 IEnvelope pEnvelope = m_Polyline.Envelope; //折线区域 IArea pArea = pEnvelope as IArea; pPoint = pArea.Centroid; IElement element = lineElement as IElement; element.Geometry = m_Polyline; //加载线元素到地图 activeView.GraphicsContainer.AddElement(element, 0); activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); activeView.Refresh(); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { int index = Convert.ToInt32(ds.Tables[0].Rows[i]["Seq"]); double dx = Convert.ToDouble(ds.Tables[0].Rows[i]["GISLongitude"]); double dy = Convert.ToDouble(ds.Tables[0].Rows[i]["GISLatitude"]); //画标记 IPoint pPoints = new PointClass(); //调用GetProject2方法经纬度转换成米 pPoints = GetProject(dx, dy); if (!check_DatailInformation.Checked) { CreateTextElment(pPoints.X, pPoints.Y, index); } } } if (check_DatailInformation.Checked) { ShowInformation(ds); } activeView.Refresh(); }
public void onMapControlMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e, InnerRoad innerRoad) { IPolyline innerRoadPolyline = mapControl.TrackLine() as IPolyline; //这里是不是要对画好的线做一下检查, 比如保证内部路穿过了小区区域. ILineElement innerRoadLineElement = new LineElementClass(); IElement element = innerRoadLineElement as IElement; element.Geometry = innerRoadPolyline; innerRoad.lineElement = innerRoadLineElement; innerRoad.updatePath(); GisUtil.DrawPolylineElement(innerRoadLineElement, mapControl); mainWindow.unmask(); }