Ejemplo n.º 1
0
        public IGeometry DrawPolyline(ESRI.ArcGIS.Carto.IActiveView activeView)
        {
            if (activeView == null)
            {
                return(null);
            }
            ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = activeView.ScreenDisplay;

            // Constant
            screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
            ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor();
            rgbColor.Red = 255;

            ESRI.ArcGIS.Display.IColor            color            = rgbColor; // Implicit Cast
            ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol();
            simpleLineSymbol.Color = color;
            simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDot;

            ESRI.ArcGIS.Display.ISymbol     symbol     = (ESRI.ArcGIS.Display.ISymbol)simpleLineSymbol; // Explicit Cast
            ESRI.ArcGIS.Display.IRubberBand rubberBand = new RubberLine();
            ESRI.ArcGIS.Geometry.IGeometry  geometry   = rubberBand.TrackNew(screenDisplay, symbol);
            screenDisplay.SetSymbol(symbol);
            screenDisplay.DrawPolyline(geometry);
            screenDisplay.FinishDrawing();
            return(geometry);
        }
Ejemplo n.º 2
0
        private void line绘制线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 创建图形
            IPolyline   pPolyline   = new Polyline() as IPolyline;
            IRubberBand pRubberBand = new RubberLine();

            pPolyline = pRubberBand.TrackNew(axMapControl1.ActiveView.ScreenDisplay, null) as IPolyline;
            // 创建符号
            ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();

            pSimpleLineSymbol.Width = 2;
            pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            // pSimpleLineSymbol.Color = GetRGBColor(44, 44, 44);

            // 创建Element并赋值图形和符号
            ILineElement pLineElement = new LineElement() as ILineElement;
            IElement     pElement     = pLineElement as IElement;

            pElement.Geometry   = pPolyline;
            pLineElement.Symbol = pSimpleLineSymbol;
            // 添加到IGraphicsContainer容器
            IGraphicsContainer pGraphicsContainer = axMapControl1.Map as IGraphicsContainer;

            pGraphicsContainer.AddElement(pLineElement as IElement, 0);
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Ejemplo n.º 3
0
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

            //get line from drawing
            IRubberBand pRubber = new RubberLine();
            //IPolyline pPloyline = pRubber.TrackNew(pMxDoc.ActivatedView.ScreenDisplay, null) as IPolyline;

            //get lines from hard coded
            IPolyline pPloyline;

            //create points
            IPoint pPoint1 = new Point();

            pPoint1.X = -92.675984;
            pPoint1.Y = 194.232396;

            IPoint pPoint2 = new Point();

            pPoint2.X = -78.115341;
            pPoint2.Y = 133.077697;

            IPoint pPoint3 = new Point();

            pPoint3.X = 13.616707;
            pPoint3.Y = 0.090495;

            IPointCollection pPointCollection = new Polyline();

            pPointCollection.AddPoint(pPoint1);
            pPointCollection.AddPoint(pPoint2);
            pPointCollection.AddPoint(pPoint3);


            IFeatureLayer pFLayer = pMxDoc.FocusMap.Layer[0] as IFeatureLayer;

            IDataset       pDS  = pFLayer.FeatureClass as IDataset;
            IWorkspaceEdit pWSE = pDS.Workspace as IWorkspaceEdit;

            pWSE.StartEditing(false);
            pWSE.StartEditOperation();

            IFeature pFeature = pFLayer.FeatureClass.CreateFeature();

            pFeature.Shape = pPointCollection as IGeometry;
            pFeature.Store();

            pWSE.StopEditOperation();
            pWSE.StopEditing(true);

            pMxDoc.ActivatedView.Refresh();
        }
Ejemplo n.º 4
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            IMxDocument pMxdoc  = ArcMap.Application.Document as IMxDocument;
            IRubberBand pRubber = new RubberLine();
            IPolyline   pPolyline;// pRubber.TrackNew(pMxdoc.ActiveView.ScreenDisplay, null) as IPolyline;

            IPoint pPoint1 = new Point();

            pPoint1.X = -2140489.683;
            pPoint1.Y = 33264366.694;

            IPoint pPoint2 = new Point();

            pPoint2.X = 19727215.727;
            pPoint2.Y = 27942068.023;

            IPoint pPoint3 = new Point();

            pPoint3.X = 30400767.253;
            pPoint3.Y = 14570156.281;


            IPointCollection pPointCollection = new Polyline();

            pPointCollection.AddPoint(pPoint1);
            pPointCollection.AddPoint(pPoint2);
            pPointCollection.AddPoint(pPoint3);


            IFeatureLayer  pFLayer = pMxdoc.FocusMap.Layer[0] as IFeatureLayer;
            IDataset       pDS     = pFLayer.FeatureClass as IDataset;
            IWorkspaceEdit pWSE    = pDS.Workspace as IWorkspaceEdit;

            pWSE.StartEditing(false);
            pWSE.StartEditOperation();

            IFeature pFeature = pFLayer.FeatureClass.CreateFeature();

            pFeature.Shape = pPointCollection as IGeometry;
            pFeature.Store();
            pWSE.StopEditOperation();
            pWSE.StopEditing(true);

            pMxdoc.ActiveView.Refresh();
        }
Ejemplo n.º 5
0
        public static void NewLineElement(IMap pMap, IPolyline pPolyLine)
        {
            IActiveView        pActiveView           = pMap as IActiveView;
            IGraphicsContainer activeView            = (IGraphicsContainer)pActiveView;
            RubberLine         rubberLineClass       = new RubberLine();
            ISimpleLineSymbol  simpleLineSymbolClass = new SimpleLineSymbol();
            IRgbColor          rgbColorClass         = new RgbColor();

            rgbColorClass.Red           = (0);
            rgbColorClass.Green         = (255);
            rgbColorClass.Blue          = (255);
            simpleLineSymbolClass.Color = (rgbColorClass);
            simpleLineSymbolClass.Width = (8);
            simpleLineSymbolClass.Style = (esriSimpleLineStyle)(2);
            LineElement lineElementClass = new LineElement();

            ((IElement)lineElementClass).Geometry = (pPolyLine);
            activeView.AddElement(lineElementClass, 0);
            pActiveView.PartialRefresh((esriViewDrawPhase)8, null, null);
        }
Ejemplo n.º 6
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            IMxDocument pmxdoc    = ArcMap.Application.Document as IMxDocument;
            IRubberBand pRubber   = new RubberLine();
            IPolyline   pPolyline = pRubber.TrackNew(pmxdoc.ActiveView.ScreenDisplay, null) as IPolyline;

            IElement     pElement     = new LineElement();
            ILineElement pLineElement = pElement as ILineElement;

            pLineElement.Symbol = new SimpleLineSymbol();
            pElement.Geometry   = pPolyline;

            IElementProperties pElementProp = pElement as IElementProperties;

            pElementProp.Name = "Hussein Element " + ++i;

            IGraphicsContainer pgc = pmxdoc.ActiveView.GraphicsContainer;

            pgc.AddElement(pElement, 0);
            pmxdoc.ActiveView.Refresh();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 屏幕上绘画几何形状
        /// </summary>
        /// <param name="screenDisplay">ESRI屏幕显示接口</param>
        /// <param name="geomType">几何形状类型的枚举类</param>
        /// <returns>ESRI几何形状接口</returns>
        public static IGeometry ScreenTrackGeometry(IScreenDisplay screenDisplay, DsGeometryType geomType)
        {
            IGeometry trackGeom = null;

            if (screenDisplay != null)
            {
                IRubberBand rubberBand = null;
                switch (geomType)
                {
                case DsGeometryType.dsGTPoint:
                    rubberBand = new RubberPoint();
                    break;

                case DsGeometryType.dsGTLine:
                    rubberBand = new RubberLine();
                    break;

                case DsGeometryType.dsGTPolyline:
                    rubberBand = new RubberLine();
                    break;

                case DsGeometryType.dsGTRectangle:
                    rubberBand = new RubberEnvelope();
                    break;

                case DsGeometryType.dsGTCircle:
                    rubberBand = new RubberCircle();
                    break;

                case DsGeometryType.dsGTEllipse:
                    rubberBand = new RubberEnvelope();
                    break;

                case DsGeometryType.dsGTPolygon:
                    rubberBand = new RubberPolygon();
                    break;

                case DsGeometryType.dsGTRectangularPolygon:
                    rubberBand = new RubberRectangularPolygon();
                    break;

                default:
                    break;
                }
                if (rubberBand != null)
                {
                    trackGeom = rubberBand.TrackNew(screenDisplay, null);
                }
                if (geomType == DsGeometryType.dsGTEllipse)
                {
                    trackGeom = ConvertEnvelopeToEllipticArc(trackGeom);
                }
                else if ((geomType == DsGeometryType.dsGTLine) ||
                         (geomType == DsGeometryType.dsGTPolyline) ||
                         (geomType == DsGeometryType.dsGTPolygon))
                {
                    if (trackGeom is ITopologicalOperator)
                    {
                        (trackGeom as ITopologicalOperator).Simplify();
                    }
                }
            }
            return(trackGeom);
        }