Example #1
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            IPolygon  pPoly;
            IEnvelope env = m_pMapControl.TrackRectangle() as ESRI.ArcGIS.Geometry.IEnvelope;

            pPoly = new PolygonClass();
            ESRI.ArcGIS.Geometry.IPointCollection pc = pPoly as ESRI.ArcGIS.Geometry.IPointCollection;
            object missing = Type.Missing;

            pc.AddPoint(env.UpperLeft, ref missing, ref missing);
            pc.AddPoint(env.UpperRight, ref missing, ref missing);
            pc.AddPoint(env.LowerRight, ref missing, ref missing);
            pc.AddPoint(env.LowerLeft, ref missing, ref missing);
            IFeatureLayer pFeaLayer;

            //             IRubberBand pRubberPoly = new RubberPolygonClass();
            //             pPoly = (IPolygon)pRubberPoly.TrackNew(m_Display, null);

            //遍历图层,查找选择框内的点要素,并标注
            for (int i = 0; i < m_arrPntLayer.Count; i++)
            {
                pFeaLayer = m_arrPntLayer[i] as IFeatureLayer;
                ArrayList features = PublicFunction.SearchFeature(pFeaLayer.FeatureClass, pPoly, esriSpatialRelEnum.esriSpatialRelContains, false);

                for (int j = 0; j < features.Count; j++)
                {
                    LabelPointFeature(features[j] as IFeature);
                }
            }
            this.m_pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
        }
Example #2
0
        public override void OnDblClick()
        {
            ITopologicalOperator pTopoOp;

            if (m_pPointColl != null)
            {
                switch (m_DrawType.ToString())
                {
                case "esriGeometryLine":
                    IPointCollection pPolyLine = new PolylineClass();
                    pPolyLine.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolyLine as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolyLine as IGeometry;
                    //ZQ   20110809
                    m_Geometry.SpatialReference = m_psurface.Domain.SpatialReference;
                    //m_Geometry.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                    ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl.PointCount < 3)
                    {
                        return;
                    }
                    IPointCollection pPolygon = new PolygonClass();
                    pPolygon.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolygon as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolygon as IGeometry;
                    //ZQ   20110809
                    m_Geometry.SpatialReference = m_psurface.Domain.SpatialReference;
                    //m_Geometry.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                    ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;
                }
                m_pPointColl = null;
            }
            //Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Example #3
0
        private void QueryBoundsFromGeom(int hDC, ref ESRI.ArcGIS.Display.IDisplayTransformation transform, ref ESRI.ArcGIS.Geometry.IPolygon boundary, ref ESRI.ArcGIS.Geometry.IPoint point)
        {
            // Calculate Size, XOffset and YOffset of the shape in Map units.
            double dMapXOffset = 0;
            double dMapSize = 0;
            double dMapYOffset = 0;

            dMapSize = PointsToMap(transform, m_dSize);
            if (m_dXOffset != 0)
                dMapXOffset = PointsToMap(transform, m_dXOffset);
            if (m_dYOffset != 0)
                dMapYOffset = PointsToMap(transform, m_dYOffset);
            point.PutCoords(point.X + dMapXOffset, point.Y + dMapYOffset);

            // Set up the device ratio.
            SetupDeviceRatio(hDC, transform);

            ESRI.ArcGIS.Geometry.IPointCollection ptColl = null;
            ESRI.ArcGIS.Geometry.ISegmentCollection segColl = null;
            double dVal = 0; // dVal is the measurement of the short side of a Triangles are based on.
            double dRad = 0;
            ptColl = (IPointCollection)boundary;
            segColl = (ISegmentCollection)boundary;
            dRad = dMapSize / 2;
            dVal = System.Math.Sqrt((dRad * dRad) / 2);
            object missing = System.Reflection.Missing.Value;
            ptColl.AddPoint(Utility.CreatePoint(point.X + dVal, point.Y - dVal), ref missing, ref missing);
            ptColl.AddPoint(Utility.CreatePoint(point.X - dVal, point.Y - dVal), ref missing, ref missing);
            ptColl.AddPoint(Utility.CreatePoint(point.X - dVal, point.Y + dVal), ref missing, ref missing);

            IPoint p = ptColl.get_Point(0);
            segColl.AddSegment((ISegment)Utility.CreateCircArc(point, ptColl.get_Point(2), ref p), ref missing, ref missing);

            //  Account for rotation also.
            ESRI.ArcGIS.Geometry.ITransform2D trans2D = null;
            if ((m_dAngle + m_dMapRotation) != 0)
            {
                trans2D = boundary as ITransform2D;
                trans2D.Rotate(point, Utility.Radians(m_dAngle + m_dMapRotation));
            }
        }
Example #4
0
        /// <summary>
        /// 双击表示绘制对象结束
        /// </summary>
        public override void OnDblClick()
        {
            ITopologicalOperator pTopoOp;

            if (m_pPointColl != null)
            {
                switch (m_DrawType.ToString())
                {
                case "esriGeometryLine":
                    IPointCollection pPolyLine = new PolylineClass();
                    pPolyLine.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolyLine as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolyLine as IGeometry;
                    m_Geometry.SpatialReference = m_sceneHookHelper.Scene.SpatialReference;
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                    EndDtrawd(true);    //触发结束事件
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl.PointCount < 3)
                    {
                        return;
                    }
                    IPointCollection pPolygon = new PolygonClass();
                    pPolygon.AddPointCollection(m_pPointColl);
                    pTopoOp = pPolygon as ITopologicalOperator;
                    pTopoOp.Simplify();
                    m_Geometry = pPolygon as IGeometry;
                    m_Geometry.SpatialReference = m_sceneHookHelper.Scene.SpatialReference;
                    Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                    EndDtrawd(true);  //触发结束事件
                    break;
                }
                m_pPointColl = null;
            }
            //Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
            m_sceneHookHelper.SceneGraph.RefreshViewers();
        }
Example #5
0
        /// <summary>
        /// 获取点击地图上的点
        /// </summary>
        /// <param name="Button"></param>
        /// <param name="Shift"></param>
        /// <param name="X"></param>
        /// <param name="Y"></param>
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();;
                ISceneGraph pSceneGraph = m_sceneHookHelper.SceneGraph;
                object      pOwner;
                object      pObject;
                object      before   = Type.Missing;
                object      after    = Type.Missing;
                object      StepSize = Type.Missing;
                IDisplay3D  pDisplay;
                pSceneGraph.Locate(pSceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pMapPoint, out pOwner, out pObject); //获取鼠标点击的位置并转化为地理坐标
                if (pMapPoint == null)
                {
                    return;
                }
                pMapPoint.Z = pMapPoint.Z / m_sceneHookHelper.Scene.ExaggerationFactor;
                pMapPoint.Z = m_psurface.GetElevation(pMapPoint);
                pMapPoint.SpatialReference = pSceneGraph.Scene.SpatialReference;
                pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D;
                pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置
                IGeometry pGeom = null;
                Cls3DMarkDraw.DeleteAllElementsWithName(m_sceneHookHelper.Scene, sPolyOutlineName);
                //根据绘制对象类型的不同定义不同的类型
                switch (m_DrawType.ToString())
                {
                case "esriGeometryPoint":
                    m_Geometry = pMapPoint;
                    break;

                case "esriGeometryLine":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolylineClass();
                        pGeom        = new PolylineClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolygonClass();
                        pGeom        = new PolygonClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;
                }

                //BeginDrawed(true);

                IGroupElement pGroup = null;
                if (m_pPointColl.PointCount == 1)
                {
                    //当为一个点时绘制点
                    Cls3DMarkDraw.AddSimpleGraphic(pMapPoint, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                }
                else if (m_DrawType.ToString() == "esriGeometryLine")
                {
                    pGeom = m_pPointColl as IGeometry;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                    m_pPointColl = pGeom as IPointCollection;
                }
                else
                {
                    ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator;
                    pGeom = pTopo.Boundary;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    Cls3DMarkDraw.AddSimpleGraphic(pGeom, Cls3DMarkDraw.getRGB(71, 61, 255), 4, sPolyOutlineName, m_sceneHookHelper.Scene, pGroup);
                }

                m_sceneHookHelper.SceneGraph.RefreshViewers();
            }
            catch
            {
                return;
            }
        }
Example #6
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                ESRI.ArcGIS.Geometry.IPoint pMapPoint = new ESRI.ArcGIS.Geometry.PointClass();;
                object before   = Type.Missing;
                object after    = Type.Missing;
                object StepSize = Type.Missing;
                m_hookHelper.FocusMap.SpatialReference = m_psurface.Domain.SpatialReference;
                pMapPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
                if (pMapPoint == null)
                {
                    return;
                }
                pMapPoint.Project(m_psurface.Domain.SpatialReference);
                pMapPoint.Z = m_psurface.GetElevation(pMapPoint);

                //pMapPoint.SpatialReference = m_hookHelper.FocusMap.SpatialReference;
                //pDisplay = m_sceneHookHelper.SceneGraph as IDisplay3D;
                //pDisplay.FlashLocation(pMapPoint);//闪烁显示被点击的位置

                IGeometry pGeom = null;
                ClsMarkDraw.DeleteAllElementsWithName(m_hookHelper.FocusMap, sPolyOutlineName);
                //根据绘制对象类型的不同定义不同的类型
                switch (m_DrawType.ToString())
                {
                case "esriGeometryPoint":
                    m_Geometry = pMapPoint;
                    break;

                case "esriGeometryLine":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolylineClass();
                        pGeom        = new PolylineClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;

                case "esriGeometryPolygon":
                    if (m_pPointColl == null)
                    {
                        m_pPointColl = new PolygonClass();
                        pGeom        = new PolygonClass();
                    }
                    m_pPointColl.AddPoint(pMapPoint, ref before, ref after);
                    break;
                }

                //BeginDrawed(true);

                IGroupElement pGroup = null;
                if (m_pPointColl.PointCount == 1)
                {
                    //当为一个点时绘制点
                    ClsMarkDraw.AddSimpleGraphic(pMapPoint, ClsMarkDraw.getRGB(71, 61, 255), 3, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                }
                else if (m_DrawType.ToString() == "esriGeometryLine")
                {
                    pGeom = m_pPointColl as IGeometry;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                    m_pPointColl = pGeom as IPointCollection;
                }
                else
                {
                    ITopologicalOperator pTopo = m_pPointColl as ITopologicalOperator;
                    pGeom = pTopo.Boundary;
                    pGeom.SpatialReference = pMapPoint.SpatialReference;
                    m_psurface.InterpolateShape(pGeom, out pGeom, ref StepSize);
                    ClsMarkDraw.AddSimpleGraphic(pGeom, ClsMarkDraw.getRGB(71, 61, 255), 2, sPolyOutlineName, m_hookHelper.FocusMap, pGroup);
                }

                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
            catch
            {
                return;
            }
        }
Example #7
0
        private string serializeGeo(ESRI.ArcGIS.Geometry.IGeometry geo, Boolean ESRISerialize)
        {
            if (ESRISerialize)
            {
                System.String xmlNodeName = "NodeName";
                System.String elementURI  = "http://www.esri.com/schemas/ArcGIS/10";

                // Create xml writer
                ESRI.ArcGIS.esriSystem.IXMLWriter xmlWriter = new ESRI.ArcGIS.esriSystem.XMLWriterClass();

                // Create xml stream
                ESRI.ArcGIS.esriSystem.IXMLStream xmlStream = new ESRI.ArcGIS.esriSystem.XMLStreamClass();

                // Explicit Cast for IStream and then write to stream
                xmlWriter.WriteTo((ESRI.ArcGIS.esriSystem.IStream)xmlStream);

                // Serialize
                ESRI.ArcGIS.esriSystem.IXMLSerializer xmlSerializer = new ESRI.ArcGIS.esriSystem.XMLSerializerClass();


                xmlSerializer.WriteObject(xmlWriter, null, null, xmlNodeName, elementURI, geo);

                return(xmlStream.SaveToString());
            }
            else
            {
                switch (geo.GeometryType)
                {
                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                {
                    ESRI.ArcGIS.Geometry.IPoint pPnt = (ESRI.ArcGIS.Geometry.IPoint)geo;

                    return("<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>");

                    //break;
                }

                case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                {
                    string lineString = "<PathArray>";
                    ESRI.ArcGIS.Geometry.IPolyline           pPly = (ESRI.ArcGIS.Geometry.IPolyline)geo;
                    ESRI.ArcGIS.Geometry.IGeometryCollection pGC  = (ESRI.ArcGIS.Geometry.IGeometryCollection)pPly;
                    for (int i = 0; i < pGC.GeometryCount; i++)
                    {
                        lineString = lineString + "<Path><PointArray>";
                        //ESRI.ArcGIS.Geometry.IGeometry pGeo2 = pGC.get_Geometry(i);
                        // ESRI.ArcGIS.Geometry.IPath pPath = (ESRI.ArcGIS.Geometry.IPath)pGC.get_Geometry(i);
                        ESRI.ArcGIS.Geometry.IPointCollection pPointCol = (ESRI.ArcGIS.Geometry.IPointCollection)pGC.get_Geometry(i);
                        for (int j = 0; j < pPointCol.PointCount; j++)
                        {
                            ESRI.ArcGIS.Geometry.IPoint pPathPoint = pPointCol.get_Point(j);

                            lineString = lineString + "<Point><X>" + pPathPoint.X + "</X><Y>" + pPathPoint.Y + "</Y></Point>";
                        }
                        // string tr = pGeo2.GeometryType.ToString();
                        lineString = lineString + "</PointArray></Path>";
                    }
                    lineString = lineString + "</PathArray>";
                    return(lineString);

                    // return "<Point><X>" + pPnt.X + "</X><Y>" + pPnt.Y + "</Y></Point>";
                    //     break;
                }

                default:
                {
                    return("");
                    //   break;
                }
                }
            }
        }
 private void DrawPolygon(ESRI.ArcGIS.Geometry.IPointCollection pPointCollection, ESRI.ArcGIS.Controls.AxMapControl axMapControl)
 {
     ESRI.ArcGIS.Geometry.IPolygon pPolygon;
     pPolygon = (ESRI.ArcGIS.Geometry.IPolygon)pPointCollection;
     axMapControl.DrawShape(pPolygon);
 }