private void DrawNodeLabels(IFeature feature, IntersectPipe ip)
        {
            if (feature == null)
            {
                return;
            }
            IPolyline pline = feature.Shape as IPolyline;
            IPoint    p     = pline.FromPoint;

            dblStartX = p.X;
            dblStartY = p.Y;
            IPoint p1      = new PointClass();
            IPoint p2      = new PointClass();
            IPoint p3      = new PointClass();
            IPoint p4      = new PointClass();
            IPoint p5      = new PointClass();
            IPoint p6      = new PointClass();
            IPoint p7      = new PointClass();
            IPoint p8      = new PointClass();
            double yOffset = 1.5;
            double xOffset = 1.0;

            p1.PutCoords(p.X, p.Y + nHeight * fields.Length / 2 - yOffset);
            p2.PutCoords(p.X + xOffset, p.Y + nHeight * fields.Length - yOffset);
            p3.PutCoords(p2.X + nWidth, p2.Y);
            p4.PutCoords(p2.X + 2 * nWidth, p2.Y);
            p7.PutCoords(p2.X, p2.Y - nHeight * fields.Length);
            p6.PutCoords(p3.X, p7.Y);
            p5.PutCoords(p4.X, p7.Y);
            p8.PutCoords(p2.X, p1.Y);

            //画线
            DrawLine(p, p1);
            DrawLine(p1, p8);
            DrawLine(p8, p2);
            DrawLine(p2, p3);
            DrawLine(p3, p4);
            DrawLine(p4, p5);
            DrawLine(p5, p6);
            DrawLine(p6, p7);
            DrawLine(p7, p8);
            DrawLine(p3, p6);

            DrawNodeInfo(p2, ip);
        }
Example #2
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            IScreenDisplay pScr = m_pActiveView.ScreenDisplay;
            //跟踪画线
            IRubberBand pRB = new RubberLineClass();

            m_pGeoTrack = pRB.TrackNew(pScr, null);
            if ((m_pGeoTrack as IPointCollection).PointCount != 2)
            {
                XtraMessageBox.Show("请使用鼠标制定两点确定扯旗的管线");
                return;
            }
            Element.DeleteElement(m_pActiveView.GraphicsContainer, "cq");
            Element.AddGraphics(m_pActiveView.GraphicsContainer, m_pGeoTrack, GetDefaultSymbol(esriGeometryType.esriGeometryPolyline), "dmx");
            IElement pElement = Element.GetElementByName(m_pMapControl.ActiveView.GraphicsContainer, "cq");

            if (pElement != null)
            {
                m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }

            IFeature             pFeature;
            IGeometry            pGeo;
            IGeometry            pPipeLineGeo;
            IFeatureClass        pFeatureClass;
            IFeatureCursor       pFeaCur;
            ITopologicalOperator pTopo;
            string classify   = "";
            string startNo    = "";
            string endNo      = "";
            string material   = "";
            string coverstyle = "";
            string diameter   = "";
            string road       = "";
            double distance;

            m_IntersectPipes = new List <IntersectPipe>();



            string[] sysFields = new string[] { "Classify", "StartNo", "EndNo", "Material", "CoverStyle", "Diameter", "Road" };
            string[] fields    = new string[] { "类别", "起点号", "终点号", "材质", "埋设方式", "管径", "所在道路" };
            try
            {
                foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                {
                    WaitForm.Start("正在查询...", "请稍后");
                    string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组
                    if (arrFc2DId == null)
                    {
                        continue;
                    }

                    foreach (SubClass sc in mc.SubClasses)
                    {
                        if (!sc.Visible2D)
                        {
                            continue;
                        }
                        foreach (string fc2DId in arrFc2DId)                                                      //遍历二级子类所对应的要素类ID
                        {
                            DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC
                            if (dffc == null)
                            {
                                continue;
                            }
                            FacilityClass fcc = dffc.GetFacilityClass();
                            if (fcc.Name != "PipeLine")
                            {
                                continue;
                            }
                            IFeatureLayer fl = dffc.GetFeatureLayer();

                            ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                            pSpatialFilter.Geometry    = m_pGeoTrack;
                            pSpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                            pSpatialFilter.WhereClause = "SMSCODE =  '" + sc.Name + "'";
                            IFeatureClass fc = dffc.GetFeatureClass();
                            pFeaCur = fc.Search(pSpatialFilter, false);
                            while ((pFeature = pFeaCur.NextFeature()) != null)
                            {
                                foreach (string field in sysFields)
                                {
                                    DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field);
                                    if (fi == null)
                                    {
                                        continue;
                                    }
                                    int    index = fc.Fields.FindField(fi.Name);
                                    object obj   = pFeature.get_Value(index);
                                    switch (field)
                                    {
                                    case "Classify":
                                        classify = obj.ToString();
                                        break;

                                    case "StartNo":
                                        startNo = obj.ToString();
                                        break;

                                    case "EndNo":
                                        endNo = obj.ToString();
                                        break;

                                    case "Material":
                                        material = obj.ToString();
                                        break;

                                    case "CoverStyle":
                                        coverstyle = obj.ToString();
                                        break;

                                    case "Diameter":
                                        diameter = obj.ToString();
                                        break;

                                    case "Road":
                                        road = obj.ToString();
                                        break;
                                    }
                                }
                                IPolyline            pline    = m_pGeoTrack as IPolyline;
                                IPoint               point1   = pline.ToPoint;
                                ITopologicalOperator topo     = pFeature.Shape as ITopologicalOperator;
                                IGeometry            geo      = topo.Intersect(m_pGeoTrack, esriGeometryDimension.esriGeometry0Dimension);
                                IPointCollection     pointCol = geo as IPointCollection;
                                IPoint               point2   = pointCol.get_Point(pointCol.PointCount - 1);
                                distance = GetDistanceOfTwoPoints(point1, point2);
                                IntersectPipe interPipe = new IntersectPipe(pFeature, fl, distance, classify, startNo, endNo, material, coverstyle, diameter, road);
                                m_IntersectPipes.Add(interPipe);
                            }
                        }
                    }
                }
                if (m_IntersectPipes.Count == 0)
                {
                    return;
                }
                List <IntersectPipe> orderList = m_IntersectPipes.OrderBy(i => i.Distance).ToList <IntersectPipe>();
                DrawPipeLabels();

                int n = 0;
                foreach (IntersectPipe interPipe in orderList)
                {
                    WaitForm.SetCaption("正在输出属性,请稍后...");
                    DrawPipeInfo(interPipe, n);
                    ++n;
                }
                WaitForm.Stop();
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
Example #3
0
        private void DrawPipeInfo(IntersectPipe interPipe, int i)
        {
            try
            {
                IGraphicsContainer pGraContainer = m_pMapControl.Map as IGraphicsContainer;
                IPoint             pAnnoPnt      = new PointClass();
                ITextSymbol        sym           = new TextSymbolClass();
                stdole.IFontDisp   myfont        = (stdole.IFontDisp) new stdole.StdFontClass();
                myfont.Name = "华文细黑";
                sym.Font    = myfont;
                myfont.Bold = true;
                sym.Size    = 8 /*SystemInfo.Instance.TextSize*/;
                ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbolClass();
                IFeatureRenderer  FeatureRenderer   = new SimpleRendererClass();
                IGeoFeatureLayer  geolyr            = interPipe.FeaLayer as IGeoFeatureLayer;
                if (geolyr == null)
                {
                    return;
                }
                FeatureRenderer = geolyr.Renderer;
                //获取此图层的Symbol
                pSimpleLineSymbol = (ISimpleLineSymbol)FeatureRenderer.get_SymbolByFeature(interPipe.Feature);
                sym.Color         = pSimpleLineSymbol.Color;

                //类别
                sym.Text = interPipe.Classify;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                ITextElement pTextElement = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                IElement pElement = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);

                //起点点号
                sym.Text = interPipe.StartNo;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 2, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);
                //终点点号
                sym.Text = interPipe.EndNo;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 3, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);

                //材质
                sym.Text = interPipe.Material;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 4, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);
                //埋设方式
                sym.Text = interPipe.Coverstyle;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 5, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);

                //管径
                sym.Text = interPipe.Diameter;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 6, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3

                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);

                //所在道路
                sym.Text = interPipe.Road;
                if (sym.Text == null)
                {
                    return;
                }
                pAnnoPnt.PutCoords(dblStartX + nWidth * 7, dblStartY + nHeight * (m_IntersectPipes.Count - (i + 1)));//居中显示,并位于表格边线以上m_dblTableHeadWidth/5*3
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);
            }
            catch (System.Exception ex)
            {
            }
        }
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication    app = DF2DApplication.Application;
            IGraphicsContainer gc  = app.Current2DMapControl.Map as IGraphicsContainer;

            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            m_pActiveView = app.Current2DMapControl.ActiveView;
            m_Display     = app.Current2DMapControl.ActiveView.ScreenDisplay;
            IFeatureCursor pFeaCur;
            IFeature       pFeature;
            string         classify   = "";
            string         startNo    = "";
            string         endNo      = "";
            string         material   = "";
            string         coverstyle = "";
            string         diameter   = "";
            string         road       = "";
            bool           have       = false;

            try
            {
                if (button == 1)
                {
                    IRubberBand band = new RubberRectangularPolygonClass();
                    m_pGeoTrack = band.TrackNew(m_Display, null);

                    if (m_pGeoTrack.IsEmpty)
                    {
                        IPoint searchPoint = new PointClass();
                        searchPoint.PutCoords(mapX, mapY);
                        m_pGeoTrack = DF2DPipe.Class.PublicFunction.DoBuffer(searchPoint, DF2DPipe.Class.PublicFunction.ConvertPixelsToMapUnits(m_pActiveView, GlobalValue.System_Selection_Option().Tolerate));
                        //m_ActiveView.FocusMap.SelectByShape(geo, s, false);
                    }
                    WaitForm.Start("正在查询...", "请稍后");
                    foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                    {
                        if (have)
                        {
                            break;
                        }
                        string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组
                        if (arrFc2DId == null)
                        {
                            continue;
                        }
                        foreach (SubClass sc in mc.SubClasses)
                        {
                            if (have)
                            {
                                break;
                            }
                            if (!sc.Visible2D)
                            {
                                continue;
                            }
                            foreach (string fc2DId in arrFc2DId)                                                      //遍历二级子类所对应的要素类ID
                            {
                                DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC
                                if (dffc == null)
                                {
                                    continue;
                                }
                                FacilityClass fcc = dffc.GetFacilityClass();
                                if (fcc.Name != "PipeLine")
                                {
                                    continue;
                                }
                                IFeatureLayer  fl             = dffc.GetFeatureLayer();
                                IFeatureClass  fc             = dffc.GetFeatureClass();
                                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                                pSpatialFilter.Geometry    = m_pGeoTrack;
                                pSpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                                pSpatialFilter.WhereClause = "SMSCODE =  '" + sc.Name + "'";
                                pFeaCur  = fc.Search(pSpatialFilter, false);
                                pFeature = pFeaCur.NextFeature();
                                if (pFeature == null)
                                {
                                    continue;
                                }
                                foreach (string field in sysFields)
                                {
                                    DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field);
                                    if (fi == null)
                                    {
                                        continue;
                                    }
                                    int    index = fc.Fields.FindField(fi.Name);
                                    object obj   = pFeature.get_Value(index);
                                    switch (field)
                                    {
                                    case "Classify":
                                        classify = obj.ToString();
                                        break;

                                    case "StartNo":
                                        startNo = obj.ToString();
                                        break;

                                    case "EndNo":
                                        endNo = obj.ToString();
                                        break;

                                    case "Material":
                                        material = obj.ToString();
                                        break;

                                    case "CoverStyle":
                                        coverstyle = obj.ToString();
                                        break;

                                    case "Diameter":
                                        diameter = obj.ToString();
                                        break;

                                    case "Road":
                                        road = obj.ToString();
                                        break;
                                    }
                                }
                                m_IntersectPipe = new IntersectPipe(pFeature, fl, 0, classify, startNo, endNo, material, coverstyle, diameter, road);
                                have            = true;
                            }
                        }
                    }
                }
                if (m_IntersectPipe == null)
                {
                    XtraMessageBox.Show("请重新获取单个管线");
                    WaitForm.Stop();
                }
                WaitForm.SetCaption("正在输出属性,请稍后...");
                DrawNodeLabels(m_IntersectPipe.Feature, m_IntersectPipe);
                WaitForm.Stop();
            }
            catch (System.Exception ex)
            {
            }
        }
        private void DrawNodeInfo(IPoint point, IntersectPipe ip)
        {
            IGraphicsContainer pGraContainer = m_pMapControl.Map as IGraphicsContainer;
            ITextElement       pTextElement;
            IElement           pElement;
            IPoint             pAnnoPnt = new PointClass();
            ITextSymbol        sym      = new TextSymbolClass();

            stdole.IFontDisp myfont = (stdole.IFontDisp) new stdole.StdFontClass();
            myfont.Name = "华文细黑";
            sym.Font    = myfont;

            myfont.Bold = true;
            sym.Size    = 8;//SystemInfo.Instance.TextSize;

            Color  color  = ColorTranslator.FromHtml(SystemInfo.Instance.TextColor);
            IColor pColor = new RgbColorClass();

            pColor.RGB = color.B * 65536 + color.G * 256 + color.R;
            sym.Color  = pColor;

            double xoffset = 4;
            double yoffset = 1.5;
            int    i       = 0;

            foreach (string fi in fields)
            {
                sym.Text = fi;
                pAnnoPnt.PutCoords(point.X + xoffset, point.Y - yoffset - i * nHeight);
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);

                switch (fi)
                {
                case "类别":
                    sym.Text = ip.Classify;
                    break;

                case "起点号":
                    sym.Text = ip.StartNo;
                    break;

                case "终点号":
                    sym.Text = ip.EndNo;
                    break;

                case "材质":
                    sym.Text = ip.Material;
                    break;

                case "埋设方式":
                    sym.Text = ip.Coverstyle;
                    break;

                case "管径":
                    sym.Text = ip.Diameter;
                    break;

                case "所在道路":
                    sym.Text = ip.Road;
                    break;
                }
                pAnnoPnt.PutCoords(point.X + xoffset + nWidth, point.Y - yoffset - i * nHeight);
                pTextElement           = new TextElementClass();
                pTextElement.ScaleText = true;
                pTextElement.Text      = sym.Text;
                pTextElement.Symbol    = sym;
                pElement          = (IElement)pTextElement;
                pElement.Geometry = pAnnoPnt;
                pGraContainer.AddElement(pElement, 0);
                i++;
                (m_pMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, m_pMapControl.Extent);
            }
        }