Beispiel #1
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add LHSBCrePoint.OnMouseDown implementation
            IRubberBand ipRubber = new RubberPointClass();
            IGeometry   ipGeo    = ipRubber.TrackNew(m_hookHelper.ActiveView.ScreenDisplay,
                                                     null);
            IFeatureLayer layer = null;

            for (int i = 0; i < m_hookHelper.FocusMap.LayerCount; i++)
            {
                layer = (IFeatureLayer)m_hookHelper.FocusMap.get_Layer(i);
                if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint)
                {
                    break;
                }
                layer = null;
            }
            if (layer != null)
            {
                IFeature feature = layer.FeatureClass.CreateFeature();
                feature.Shape = ipGeo;
                feature.Store();
                m_hookHelper.ActiveView.Refresh();
            }
        }
Beispiel #2
0
        public override void OnClick()
        {
            IRubberBand ipRubberRec = new RubberPointClass();
            IPoint      po          = ipRubberRec.TrackNew(m_hookHelper.ActiveView.ScreenDisplay, null) as IPoint;
            object      lidan       = null;

            GetPixValue(selectLayer as IRasterLayer, po, out lidan);

            MessageBox.Show("¤ы╦пох:" + lidan.ToString());
        }
        /// <summary>
        /// 绘制点要素
        /// </summary>
        /// <param name="view">活动视图</param>
        /// <param name="symbol">点样式SimpleSymbolHelper</param>
        /// <returns></returns>
        public static IGeometry DreawPoint(IActiveView view, ISymbol symbol)
        {
            //初始rubberband
            IRubberBand band   = new RubberPointClass();
            IGeometry   newGeo = band.TrackNew(view.ScreenDisplay, symbol);

            if (newGeo == null)
            {
                return(null);
            }
            return(newGeo);
        }
Beispiel #4
0
        public void points()
        {
            string strs = "Marker";
            switch (strs)
            {
                case "Marker":

                    IMarkerElement pMarkerElement;//对于点,线,面的element定义这里都不一样,他是可实例化的类,而IElement是实例化的类,必须通过 IMarkerElement 初始化负值给 IElement 。
                    IElement pMElement;
                    IPoint pPoint=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE
                    pMarkerElement = new MarkerElementClass();

                    pMElement = pMarkerElement as IElement;

                    RubberPointClass pRubberBand = new RubberPointClass();//你的RUBBERBAND随着你的图形耳边
                    //pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint;
                    ////pPoint = pRubberBand.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPoint;
                    //pPoint.X = 101;
                    //pPoint.Y = 37;

                    // pPoint.PutCoords(Convert.ToDouble(101), Convert.ToDouble(37));
                    //pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 200);
                    // pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));

                   // pPoint = axMapControl.ToMapPoint(334, 344);
                    //pPoint.X = pPoint.X;
                    //pPoint.Y = pPoint.Y;

                    /*00000000000000000000000000000000000经纬度转换坐标*/
                    //IGlobeDisplay m_globeDisplay = axGlobeControl1.GlobeDisplay;

                    //// IGlobeDisplay pGlobeDisplay = axGlobeControl1.GlobeDisplay;

                    ////axGlobeControl1.GlobeDisplay.ActiveViewer;
                    //ISceneViewer sceneViewer = m_globeDisplay.ActiveViewer;
                    //IGlobeViewUtil globeViewUtil = (IGlobeViewUtil)sceneViewer.Camera;

                    //int winX, winY;
                    ////globeViewUtil.GeographicToWindow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text), 0, out winX, out winY);

                    ////pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标

                    //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(0, 0);//x,y为屏幕坐标
                    ////pPoint.X = Convert.ToDouble(textBox1.Text);
                    ////pPoint.Y = Convert.ToDouble(textBox2.Text);
                    //pPoint.PutCoords(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));//x,y地理坐标

                    //axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(pPoint, out winX, out winY);
                    // int mx = winX;
                    //int my = winY;
                    //pPoint=axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(200, 400);//x,y为屏幕坐标

                    //调用GetProject2方法经纬度转换成米
                    pPoint = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));

                    //pPoint.PutCoords(Convert.ToDouble(textBox3.Text), Convert.ToDouble(textBox4.Text));
                    /*00000000000000000000000000000000000*/

                   // pPoint = axMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(mx, my);

                    //pPoint.PutCoords(mx, my);
                    //pPoint.X = mx;
                    //pPoint.Y = my;

                    //ISpatialReferenceFactory pSRF = new SpatialReferenceEnvironmentClass();
                    //pPoint.SpatialReference = pSRF.CreateProjectedCoordinateSystem(2414);
                    //pPoint.Project(pSRF.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_Beijing1954));

                    pMElement.Geometry = pPoint;//把你在屏幕中画好的图形付给 IElement 储存

                    IGraphicsContainer pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器
                   // axMapControl.get_Layer(0)

                    // ILayer pLayer = this.axMapControl.get_Layer(1);//所要加的层

                    pGraphicsContainer.AddElement(pMElement, 0);//显示储存在 IElement 中图形,这样就持久化了。
                    axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                    //axMapControl.Refresh();
                    break;

                case "Line":

                    //ILineElement pLineElement;
                    //IElement pLElement;

                    //IPolyline pLine;
                    // IGraphicsContainer pGraphicsContainerl = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器
                    //pLineElement = new LineElementClass();
                    //pLElement = pLineElement as IElement;

                    //RubberLineClass pRubberBandd = new RubberLineClass();
                    //pLine = pRubberBandd.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolyline;

                    //pLElement.Geometry = pLine;

                    //pGraphicsContainerl = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器

                    //pGraphicsContainerl.AddElement(pLElement, 0);//把刚刚的element转到容器上
                    //axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

                    //00000000000
                    //调用GetProject2方法经纬度转换成米
                    IPoint pPointl=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE
                    pPointl = GetProject2(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox2.Text));

                    IPoint pPointl2=new PointClass();//你画的图形式什么就是什么,特别的是LINE则需要定义为POLYLINE
                    pPointl2 = GetProject2(-120, 40);

                    //创建一个Line对象
                    ILine pLine2 = new LineClass();

                    //Polyline pLine2 = new PolylineClass();
                    //设置Line对象的起始终止点
                    pLine2.PutCoords(pPointl, pPointl2);

                    //IPointCollection pMultipoint = new MultipointClass();
                    //object o=Type.Missing;
                    //pMultipoint.AddPoint(pPointl, ref o, ref o);
                    //pMultipoint.AddPoint(pPointl2, ref o, ref o);

                      axMapControl.ActiveView.Refresh();//刷新当前视图
                    break;
                case "Fill":
                    IFillShapeElement pFillShapeElement;
                    IElement pgonElemnt;

                    IPolygon pPolygon;
                    pFillShapeElement = new PolygonElementClass();
                    pgonElemnt = pFillShapeElement as IElement;//Element

                    RubberPolygonClass pRubberBand3 = new RubberPolygonClass();//在屏幕上画个多边形
                    pPolygon = pRubberBand3.TrackNew(axMapControl.ActiveView.ScreenDisplay, null) as IPolygon;

                    pgonElemnt.Geometry = pPolygon;//把这个多边形转成Element

                    pGraphicsContainer = axMapControl.ActiveView as IGraphicsContainer;//把地图的当前view作为图片的容器

                    //pGraphicsContainer.DeleteAllElements ();
                    pGraphicsContainer.AddElement(pgonElemnt, 0);//把刚刚的element转到容器上
                    axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    break;
            }
        }
Beispiel #5
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 RubberPointClass();
                    break;

                case dsGeometryType.dsGTLine:
                    rubberBand = new RubberLineClass();
                    break;

                case dsGeometryType.dsGTPolyline:
                    rubberBand = new RubberLineClass();
                    break;

                case dsGeometryType.dsGTRectangle:
                    rubberBand = new RubberEnvelopeClass();
                    break;

                case dsGeometryType.dsGTCircle:
                    rubberBand = new RubberCircleClass();
                    break;

                case dsGeometryType.dsGTEllipse:
                    rubberBand = new RubberEnvelopeClass();
                    break;

                case dsGeometryType.dsGTPolygon:
                    rubberBand = new RubberPolygonClass();
                    break;

                case dsGeometryType.dsGTRectangularPolygon:
                    rubberBand = new RubberRectangularPolygonClass();
                    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);
        }
        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            if (ArcMap.Document.SelectedLayer == null)
            {
                System.Windows.Forms.MessageBox.Show("Select a layer before continuing.");
                return;
            }

            IFeatureLayer ifl_active = (IFeatureLayer)ArcMap.Document.SelectedLayer;

            try
            {
                IRgbColor rgbColor = new RgbColorClass();
                rgbColor.Red = 255;

                IColor color = rgbColor; // Implicit Cast
                ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
                simpleMarkerSymbol.Color = rgbColor;
                simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSX;

                ISymbol symbol = simpleMarkerSymbol as ISymbol; // Dynamic Cast

                IScreenDisplay screenDisplay = ArcMap.Document.ActiveView.ScreenDisplay;
                IRubberBand2 rubberBand = new RubberPointClass();

                IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);

                if (geometry == null) return;

                try
                {
                    screenDisplay.SetSymbol(symbol);
                    screenDisplay.DrawPoint(geometry);
                    screenDisplay.FinishDrawing();
                }
                catch (Exception iii)
                {
                }

                IGeoDataset igd_dest = (IGeoDataset)ifl_active.FeatureClass;

                geometry.SpatialReference = ArcMap.Document.FocusMap.SpatialReference;

                if (igd_dest.SpatialReference.Name != geometry.SpatialReference.Name)
                {
                    geometry.Project(igd_dest.SpatialReference);
                }

                ITopologicalOperator ito = (ITopologicalOperator)geometry;

                IMap mp = ArcMap.Document.FocusMap;
                ISpatialReference isr = igd_dest.SpatialReference;

                IProjectedCoordinateSystem ipcs = (IProjectedCoordinateSystem)isr;
                ILinearUnit ilu = ipcs.CoordinateUnit;

                string input = Microsoft.VisualBasic.Interaction.InputBox("Enter radius to use (in the units of the target NWI layer: " + ((ilu.Name.IndexOf("Foot", StringComparison.CurrentCultureIgnoreCase) > -1) ? "feet" : ilu.Name.ToLower() + "s") + ") ", "Radius for Buffered Clip", "500");
                double distance = double.Parse(input);

                IGeometry circle = ito.Buffer(distance);

                DoClip(ArcMap.Document.ActiveView, ifl_active, circle);
            }
            catch (Exception e)
            {
                //System.Windows.Forms.MessageBox.Show("Exception: " + e.Message + "\n\n" + e.StackTrace );
                SelectArrowToolOnToolbar();
            }
            finally
            {
                //System.Windows.Forms.MessageBox.Show("Return");
            }
        }