Ejemplo n.º 1
0
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IMxDocument pMxDoc = ArcMap.Application.Document as IMxDocument;

            IRubberBand pRabber = new RubberPolygon();

            //get polygon from screen
            IPolygon pPolygon = pRabber.TrackNew(pMxDoc.ActiveView.ScreenDisplay, null) as IPolygon;

            //get cordinate from hard coded
            //IPolygon pPolygon ;

            //IPoint pPoint1 = new Point();
            //pPoint1.X = -120.730273;
            //pPoint1.Y = 224.928212;

            //IPoint pPoint2 = new Point();
            //pPoint2.X = -25.280158;
            //pPoint2.Y = 27942068.023;

            //IPoint pPoint3 = new Point();
            //pPoint3.X = -117.895121;
            //pPoint3.Y = 150.269211;



            //IPointCollection pPointCollection = new Polygon();
            //pPointCollection.AddPoint(pPoint1);
            //pPointCollection.AddPoint(pPoint2);
            //pPointCollection.AddPoint(pPoint3);
            //pPointCollection.AddPoint(pPoint1);

            //pPolygon = pPointCollection as IPolygon;


            ////fix when draw wrong draw
            //IArea pArea = pPolygon as IArea;
            //if (pArea.Area < 0)
            //{
            //    pPolygon.ReverseOrientation();
            //}


            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 = pPolygon;
            pFeature.Store();

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

            pMxDoc.ActiveView.Refresh();
        }
Ejemplo n.º 2
0
        public void createDrawPolygon()
        {
            // 创建图形
            IPolygon    pPolygon    = new Polygon() as IPolygon;
            IRubberBand pRubberBand = new RubberPolygon();

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

            pSimpleLineSymbol.Width = 2;
            pSimpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
            //pSimpleLineSymbol.Color = GetRGBColor(46, 24, 63);// Common.GetRGBColor(46, 24, 63);

            ISimpleFillSymbol pSimpleFillSymbol = new SimpleFillSymbol();

            //pSimpleFillSymbol.Color = GetRGBColor(11, 200, 145);
            pSimpleFillSymbol.Outline = pSimpleLineSymbol;
            // 创建Element并赋值图形和符号
            IFillShapeElement pPolygonElement = new PolygonElement() as IFillShapeElement;
            IElement          pElement        = (IElement)pPolygonElement;

            pElement.Geometry      = pPolygon;
            pPolygonElement.Symbol = pSimpleFillSymbol;

            // 添加到IGraphicsContainer容器
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)axMapControl1.Map;

            pGraphicsContainer.AddElement((IElement)pPolygonElement, 0);
            axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Ejemplo n.º 3
0
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            IMxDocument pMxDoc  = ArcMap.Application.Document as IMxDocument;
            IRubberBand pRubber = new RubberPolygon();
            IPolygon    pPolygon;
            // IPolygon pPolygon = pRubber.TrackNew(pMxDoc.ActiveView.ScreenDisplay, null) as IPolygon;



            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 Polygon();

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

            pPolygon = pPointCollection as IPolygon;

            IArea pArea = pPolygon as IArea;

            if (pArea.Area < 0)
            {
                pPolygon.ReverseOrientation();
            }

            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 = pPolygon;
            pFeature.Store();
            pWSE.StopEditOperation();
            pWSE.StopEditing(true);

            pMxDoc.ActiveView.Refresh();
        }
Ejemplo n.º 4
0
        public static void NewPolygonElement(IMap pMap, IPolygon pPolygon)
        {
            IActiveView        pActiveView           = pMap as IActiveView;
            IGraphicsContainer activeView            = (IGraphicsContainer)pActiveView;
            RubberPolygon      rubberPolygonClass    = new RubberPolygon();
            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);
            PolygonElement polygonElementClass = new PolygonElement();

            polygonElementClass.Geometry = (pPolygon);
            activeView.AddElement(polygonElementClass, 0);
            pActiveView.PartialRefresh((esriViewDrawPhase)8, null, null);
        }
Ejemplo n.º 5
0
        public static void NewPolygonElementTran(IMap pMap, IPolygon pPolygon, bool bRefresh)
        {
            IActiveView        pActiveView           = pMap as IActiveView;
            IGraphicsContainer activeView            = (IGraphicsContainer)pActiveView;
            RubberPolygon      rubberPolygonClass    = new RubberPolygon();
            ISimpleLineSymbol  simpleLineSymbolClass = new SimpleLineSymbol();
            IRgbColor          rgbColorClass         = new RgbColor();

            rgbColorClass.Red          = (0);
            rgbColorClass.Green        = (255);
            rgbColorClass.Blue         = (255);
            rgbColorClass.Transparency = (1);
            IRgbColor rgbColor = new RgbColor();

            rgbColor.Red                = (255);
            rgbColor.Green              = (0);
            rgbColor.Blue               = (0);
            rgbColor.Transparency       = (1);
            simpleLineSymbolClass.Color = (rgbColorClass);
            simpleLineSymbolClass.Width = (8);
            simpleLineSymbolClass.Style = esriSimpleLineStyle.esriSLSSolid;
            ISimpleFillSymbol simpleFillSymbolClass = new SimpleFillSymbol();

            ((ISymbol)simpleFillSymbolClass).ROP2    = (esriRasterOpCode)(10);
            simpleFillSymbolClass.Color              = (rgbColorClass);
            simpleFillSymbolClass.Color.Transparency = (1);
            IElement polygonElementClass = new PolygonElement();

            polygonElementClass.Geometry = (pPolygon);
            (polygonElementClass as IFillShapeElement).Symbol = (simpleFillSymbolClass);
            activeView.AddElement(polygonElementClass, 0);
            if (bRefresh)
            {
                pActiveView.Refresh();
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public override void OnMouseDown(
			int button,
			int shift,
			int x,
			int y
			)
        {
            try
            {

                IPolygon pPoly;
                IGraphicsContainer pGraCont;
                IRubberBand pRubberPoly;

                // QI for the IGraphicsContainerSelect interface on the document's activeview
                pGraCont = (IGraphicsContainer)ext.FocusMap;

                // Create a new RubberPolygon
                pRubberPoly = new RubberPolygon();

                // Check which mouse button was pressed...
                if (1 == button)
                { // If button 1 (left) then create a new polygon (TrackNew)

                    // Return a new Polygon from the tracker object using TrackNew
                    pPoly = (IPolygon)pRubberPoly.TrackNew(((IActiveView)pGraCont).ScreenDisplay, null);
                    if (pPoly != null)
                    {
                        pPoly.SpatialReference = this.ext.FocusMap.SpatialReference;

                        if (see == null)
                        {
                            see = new SEE();
                        }
                        see.Expand(pPoly, this.ext);

                        SEEUserInterfaceUtils.updateAcetate(see, featureClass, ext);

                        if (SEEUserInterfaceUtils.isUserDone())
                        {
                            var geometryCollection = see.Shape as IGeometryCollection;
                            bool isMulti = geometryCollection != null && geometryCollection.GeometryCount > 1;

                            if (isMulti)
                            {
                                MessageBox.Show("Multipolygons cannot be processed with SUITT at this time. Please ensure your SEE Area of Interest is a single polygon feature.");
                            }
                            else finishTransaction();
                        }
                    }
                }

                // Refresh the activeview
                ((IActiveView)ext.FocusMap).Refresh();

            }
            catch (CancelException ex)
            {
                Logger.Write("User Canceled SEE Operation: " + ex.Message + Environment.NewLine + ex.StackTrace);
                // cancelled

                in_click = false;
                this.endHourGlass();

                app.CurrentTool = null;
            }
            catch (HandledException he)
            {
                Logger.Write(he);
                in_click = false;
                this.endHourGlass();

                app.CurrentTool = null;
            }
            catch (Exception e)
            {

                MessageBox.Show(e.Message + " : " + e.StackTrace,
                    "EXCEPTION", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                in_click = false;

                if (this.ext.TransactionManager.Current() != null)
                {
                    try
                    {
                        this.ext.TransactionManager.Close();
                    }
                    catch (Exception ex)
                    {
                        // ignored
                        System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); //ajw: added
                    }
                }

                this.endHourGlass();
            }
            finally
            {
                app.CurrentTool = null;
            }
        }