コード例 #1
0
        private void LineQuery()
        {
            IFdeCursor cursor = null;
            IRowBuffer row    = null;

            try
            {
                IGeometry geo = this._drawTool.GetGeo();
                if (geo == null || geo.GeometryType != gviGeometryType.gviGeometryPolyline)
                {
                    return;
                }
                IPolyline line = geo as IPolyline;
                IPolyline l    = line.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline;
                if (l.Length > 500)
                {
                    XtraMessageBox.Show("横断面线超过500米,分析效率很低,请重新绘制", "提示");
                    return;
                }
                WaitForm.Start("正在进行横断面分析...", "请稍后");
                DF3DApplication app = DF3DApplication.Application;
                if (app == null || app.Current3DMapControl == null)
                {
                    return;
                }

                List <MajorClass> list = LogicDataStructureManage3D.Instance.GetAllMajorClass();
                if (list == null)
                {
                    return;
                }
                string        road1   = "";
                string        road2   = "";
                bool          bAlert  = false;
                double        hmax    = double.MinValue;
                double        hmin    = double.MaxValue;
                List <PPLine> pplines = new List <PPLine>();
                foreach (MajorClass mc in list)
                {
                    foreach (SubClass sc in mc.SubClasses)
                    {
                        if (!sc.Visible3D)
                        {
                            continue;
                        }
                        string[] arrFc3DId = mc.Fc3D.Split(';');
                        if (arrFc3DId == null)
                        {
                            continue;
                        }
                        foreach (string fc3DId in arrFc3DId)
                        {
                            DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc3DId);
                            if (dffc == null)
                            {
                                continue;
                            }
                            IFeatureClass fc  = dffc.GetFeatureClass();
                            FacilityClass fac = dffc.GetFacilityClass();
                            if (fc == null || fac == null || fac.Name != "PipeLine")
                            {
                                continue;
                            }

                            IFieldInfoCollection fields = fc.GetFields();
                            int indexShape = fields.IndexOf("Shape");
                            if (indexShape == -1)
                            {
                                continue;
                            }
                            int indexFootPrint = fields.IndexOf("FootPrint");
                            if (indexFootPrint == -1)
                            {
                                continue;
                            }
                            DFDataConfig.Class.FieldInfo fiDiameter = fac.GetFieldInfoBySystemName("Diameter");
                            if (fiDiameter == null)
                            {
                                continue;
                            }
                            int indexDiameter = fields.IndexOf(fiDiameter.Name);
                            if (indexDiameter == -1)
                            {
                                continue;
                            }
                            DFDataConfig.Class.FieldInfo fiRoad = fac.GetFieldInfoBySystemName("Road");
                            int indexRoad = -1;
                            if (fiRoad != null)
                            {
                                indexRoad = fields.IndexOf(fiRoad.Name);
                            }
                            DFDataConfig.Class.FieldInfo fiHLB = fac.GetFieldInfoBySystemName("HLB");
                            int indexHLB = -1;
                            if (fiHLB != null)
                            {
                                indexHLB = fields.IndexOf(fiHLB.Name);
                            }
                            int indexClassify = fields.IndexOf(mc.ClassifyField);

                            ISpatialFilter pSpatialFilter = new SpatialFilter();
                            pSpatialFilter.Geometry      = l;
                            pSpatialFilter.GeometryField = "FootPrint";
                            pSpatialFilter.SpatialRel    = gviSpatialRel.gviSpatialRelIntersects;
                            pSpatialFilter.WhereClause   = mc.ClassifyField + " = '" + sc.Name + "'";

                            cursor = fc.Search(pSpatialFilter, false);
                            while ((row = cursor.NextRow()) != null)
                            {
                                if (indexRoad != -1 && !row.IsNull(indexRoad))
                                {
                                    if (road2 == "")
                                    {
                                        road1 = row.GetValue(indexRoad).ToString();
                                        road2 = row.GetValue(indexRoad).ToString();
                                    }
                                    else
                                    {
                                        road1 = row.GetValue(indexRoad).ToString();
                                        if (road1 != road2)
                                        {
                                            if (!bAlert)
                                            {
                                                XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线横断面图。", "提示");
                                                bAlert = true;
                                            }
                                            continue;
                                        }
                                    }
                                }


                                double startSurfHeight = double.MaxValue;
                                double endSurfHeight   = double.MaxValue;
                                if (!app.Current3DMapControl.Terrain.IsRegistered)
                                {
                                    DFDataConfig.Class.FieldInfo fiStartSurfHeight = fac.GetFieldInfoBySystemName("StartSurfHeight");
                                    if (fiStartSurfHeight == null)
                                    {
                                        continue;
                                    }
                                    int indexStartSurfHeight = fields.IndexOf(fiStartSurfHeight.Name);
                                    if (indexStartSurfHeight == -1)
                                    {
                                        continue;
                                    }
                                    DFDataConfig.Class.FieldInfo fiEndSurfHeight = fac.GetFieldInfoBySystemName("EndSurfHeight");
                                    if (fiEndSurfHeight == null)
                                    {
                                        continue;
                                    }
                                    int indexEndSurfHeight = fields.IndexOf(fiEndSurfHeight.Name);
                                    if (indexEndSurfHeight == -1)
                                    {
                                        continue;
                                    }
                                    if (!row.IsNull(indexStartSurfHeight))
                                    {
                                        startSurfHeight = double.Parse(row.GetValue(indexStartSurfHeight).ToString());
                                    }
                                    if (!row.IsNull(indexEndSurfHeight))
                                    {
                                        endSurfHeight = double.Parse(row.GetValue(indexEndSurfHeight).ToString());
                                    }
                                }
                                if (!row.IsNull(indexShape) && !row.IsNull(indexFootPrint))
                                {
                                    object objFootPrint = row.GetValue(indexFootPrint);
                                    object objShape     = row.GetValue(indexShape);
                                    if (objFootPrint is IPolyline && objShape is IPolyline)
                                    {
                                        IPolyline polylineFootPrint = objFootPrint as IPolyline;
                                        IPolyline polylineShape     = objShape as IPolyline;
                                        IGeometry geoIntersect      = (geo as ITopologicalOperator2D).Intersection2D(polylineFootPrint);
                                        if (geoIntersect == null)
                                        {
                                            continue;
                                        }
                                        PPLine ppline = new PPLine();
                                        if (indexClassify == -1 || row.IsNull(indexClassify))
                                        {
                                            ppline.facType = mc.Name;
                                        }
                                        else
                                        {
                                            ppline.facType = row.GetValue(indexClassify).ToString();
                                        }
                                        if (!row.IsNull(indexDiameter))
                                        {
                                            string diameter = row.GetValue(indexDiameter).ToString();
                                            if (diameter.Trim() == "")
                                            {
                                                continue;
                                            }
                                            ppline.dia = diameter;
                                            int indexDia = diameter.IndexOf('*');
                                            if (indexDia != -1)
                                            {
                                                ppline.isrect = true;
                                                int  iDia1;
                                                bool bDia1 = int.TryParse(diameter.Substring(0, indexDia), out iDia1);
                                                if (!bDia1)
                                                {
                                                    continue;
                                                }
                                                int  iDia2;
                                                bool bDia2 = int.TryParse(diameter.Substring(indexDia + 1, diameter.Length - indexDia - 1), out iDia2);
                                                if (!bDia2)
                                                {
                                                    continue;
                                                }
                                                ppline.gj.Add(iDia1);
                                                ppline.gj.Add(iDia2);
                                            }
                                            else
                                            {
                                                ppline.isrect = false;
                                                int  iDia;
                                                bool bDia = int.TryParse(diameter, out iDia);
                                                if (!bDia)
                                                {
                                                    continue;
                                                }
                                                ppline.gj.Add(iDia);
                                                ppline.gj.Add(iDia);
                                            }
                                        }
                                        int hlb = 0;
                                        if (indexHLB != -1 && !row.IsNull(indexHLB))
                                        {
                                            string strhlb = row.GetValue(indexHLB).ToString();
                                            if (strhlb.Contains("内"))
                                            {
                                                hlb = 1;
                                            }
                                            else if (strhlb.Contains("外"))
                                            {
                                                hlb = -1;
                                            }
                                            else
                                            {
                                                hlb = 0;
                                            }
                                            ppline.hlb = hlb;
                                        }
                                        #region  交点为一个
                                        if (geoIntersect.GeometryType == gviGeometryType.gviGeometryPoint) //交点为1个
                                        {
                                            IPoint ptIntersect = geoIntersect as IPoint;
                                            ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z);
                                            ppline.clh        = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint);
                                            if (ppline.clh > hmax)
                                            {
                                                hmax = ppline.clh;
                                            }
                                            if (ppline.clh < hmin)
                                            {
                                                hmin = ppline.clh;
                                            }

                                            if (app.Current3DMapControl.Terrain.IsRegistered)
                                            {
                                                ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase);
                                            }
                                            else
                                            {
                                                ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight)
                                                             * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X)
                                                                         + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length;
                                            }
                                            if (ppline.cgh > hmax)
                                            {
                                                hmax = ppline.cgh;
                                            }
                                            if (ppline.cgh < hmin)
                                            {
                                                hmin = ppline.cgh;
                                            }
                                            // 辅助画图
                                            ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z);
                                            pplines.Add(ppline);
                                        }
                                        #endregion

                                        #region 交点为多个
                                        else if (geoIntersect.GeometryType == gviGeometryType.gviGeometryMultiPoint) //交点为多个
                                        {
                                            IMultiPoint multiPts = geoIntersect as IMultiPoint;
                                            for (int m = 0; m < multiPts.GeometryCount; m++)
                                            {
                                                IPoint ptIntersect = multiPts.GetPoint(m);
                                                ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z);
                                                ppline.clh        = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint);
                                                if (ppline.clh > hmax)
                                                {
                                                    hmax = ppline.clh;
                                                }
                                                if (ppline.clh < hmin)
                                                {
                                                    hmin = ppline.clh;
                                                }

                                                if (app.Current3DMapControl.Terrain.IsRegistered)
                                                {
                                                    ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase);
                                                }
                                                else
                                                {
                                                    ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight)
                                                                 * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X)
                                                                             + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length;
                                                }
                                                if (ppline.cgh > hmax)
                                                {
                                                    hmax = ppline.cgh;
                                                }
                                                if (ppline.cgh < hmin)
                                                {
                                                    hmin = ppline.cgh;
                                                }

                                                // 辅助画图
                                                ppline.startPt = new PPPoint(l.StartPoint.X, l.StartPoint.Y, l.StartPoint.Z);
                                                pplines.Add(ppline);
                                            }
                                        }
                                        #endregion

                                        else
                                        {
                                            continue;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                WaitForm.Stop();
                if (pplines.Count < 2)
                {
                    XtraMessageBox.Show("相交管线少于2个", "提示");
                    return;
                }
                pplines.Sort(new PPLineCompare());
                double spacesum = 0.0;
                for (int i = 1; i < pplines.Count; i++)
                {
                    PPLine line1 = pplines[i - 1];
                    PPLine line2 = pplines[i];
                    line2.space = Math.Sqrt((line1.interPoint.X - line2.interPoint.X) * (line1.interPoint.X - line2.interPoint.X)
                                            + (line1.interPoint.Y - line2.interPoint.Y) * (line1.interPoint.Y - line2.interPoint.Y));
                    spacesum += line2.space;
                }
                ;
                var                str1    = (pplines[0].interPoint.X / 1000).ToString("0.00");
                var                str2    = (pplines[0].interPoint.Y / 1000).ToString("0.00");
                string             mapNum  = str2 + "-" + str1;
                string             mapName = SystemInfo.Instance.SystemFullName + "横断面图";
                FrmSectionAnalysis dialog  = new FrmSectionAnalysis("横断面分析结果", 0);
                dialog.SetInfo(mapName, mapNum, pplines, hmax, hmin, spacesum, road2);
                dialog.Show();
            }
            catch (Exception ex)
            {
                WaitForm.Stop();
            }
            finally
            {
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }
                if (row != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                    row = null;
                }
            }
        }
コード例 #2
0
ファイル: UCPipeVertical.cs プロジェクト: wwcc19870805/DIFGIS
        private void btnAnalysis_Click(object sender, EventArgs e)
        {
            try
            {
                if (this._dt.Rows.Count < 2)
                {
                    XtraMessageBox.Show("点数少于2个", "提示");
                    return;
                }
                IPoint startPt = this._dt.Rows[0]["InterPoint"] as IPoint;
                if (startPt == null)
                {
                    return;
                }

                WaitForm.Start("正在进行纵断面分析...", "请稍后");
                DF3DApplication app = DF3DApplication.Application;
                if (app == null || app.Current3DMapControl == null)
                {
                    return;
                }

                string        road1   = "";
                string        road2   = "";
                bool          bAlert  = false;
                double        hmax    = double.MinValue;
                double        hmin    = double.MaxValue;
                List <PPLine> pplines = new List <PPLine>();
                foreach (DataRow dr in this._dt.Rows)
                {
                    IFeatureClass fc = dr["FeatureClass"] as IFeatureClass;
                    MajorClass    mc = dr["PipeType"] as MajorClass;
                    if (fc == null || mc == null)
                    {
                        continue;
                    }
                    DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fc.GuidString);
                    if (dffc == null)
                    {
                        continue;
                    }
                    FacilityClass fac = dffc.GetFacilityClass();
                    if (fac == null || fac.Name != "PipeLine")
                    {
                        continue;
                    }

                    IFieldInfoCollection fields = fc.GetFields();
                    int indexShape = fields.IndexOf("Shape");
                    if (indexShape == -1)
                    {
                        continue;
                    }
                    int indexFootPrint = fields.IndexOf("FootPrint");
                    if (indexFootPrint == -1)
                    {
                        continue;
                    }
                    DFDataConfig.Class.FieldInfo fiDiameter = fac.GetFieldInfoBySystemName("Diameter");
                    if (fiDiameter == null)
                    {
                        continue;
                    }
                    int indexDiameter = fields.IndexOf(fiDiameter.Name);
                    if (indexDiameter == -1)
                    {
                        continue;
                    }
                    DFDataConfig.Class.FieldInfo fiRoad = fac.GetFieldInfoBySystemName("Road");
                    int indexRoad = -1;
                    if (fiRoad != null)
                    {
                        indexRoad = fields.IndexOf(fiRoad.Name);
                    }
                    DFDataConfig.Class.FieldInfo fiHLB = fac.GetFieldInfoBySystemName("HLB");
                    int indexHLB = -1;
                    if (fiHLB != null)
                    {
                        indexHLB = fields.IndexOf(fiHLB.Name);
                    }
                    int indexClassify = fields.IndexOf(mc.ClassifyField);

                    int        fid    = int.Parse(dr["Fid"].ToString());
                    IFdeCursor cursor = null;
                    IRowBuffer row    = null;
                    try
                    {
                        IQueryFilter filter = new QueryFilter();
                        filter.WhereClause = "oid=" + fid;
                        cursor             = fc.Search(filter, false);
                        if ((row = cursor.NextRow()) != null)
                        {
                            if (indexRoad != -1 && !row.IsNull(indexRoad))
                            {
                                if (road2 == "")
                                {
                                    road1 = row.GetValue(indexRoad).ToString();
                                    road2 = row.GetValue(indexRoad).ToString();
                                }
                                else
                                {
                                    road1 = row.GetValue(indexRoad).ToString();
                                    if (road1 != road2)
                                    {
                                        if (!bAlert)
                                        {
                                            XtraMessageBox.Show("跨越多条道路,当前只绘制在【" + road2 + "】上的管线纵断面图。", "提示");
                                            bAlert = true;
                                        }
                                        continue;
                                    }
                                }
                            }


                            double startSurfHeight = double.MaxValue;
                            double endSurfHeight   = double.MaxValue;
                            if (!app.Current3DMapControl.Terrain.IsRegistered)
                            {
                                DFDataConfig.Class.FieldInfo fiStartSurfHeight = fac.GetFieldInfoBySystemName("StartSurfHeight");
                                if (fiStartSurfHeight == null)
                                {
                                    continue;
                                }
                                int indexStartSurfHeight = fields.IndexOf(fiStartSurfHeight.Name);
                                if (indexStartSurfHeight == -1)
                                {
                                    continue;
                                }
                                DFDataConfig.Class.FieldInfo fiEndSurfHeight = fac.GetFieldInfoBySystemName("EndSurfHeight");
                                if (fiEndSurfHeight == null)
                                {
                                    continue;
                                }
                                int indexEndSurfHeight = fields.IndexOf(fiEndSurfHeight.Name);
                                if (indexEndSurfHeight == -1)
                                {
                                    continue;
                                }
                                if (!row.IsNull(indexStartSurfHeight))
                                {
                                    startSurfHeight = double.Parse(row.GetValue(indexStartSurfHeight).ToString());
                                }
                                if (!row.IsNull(indexEndSurfHeight))
                                {
                                    endSurfHeight = double.Parse(row.GetValue(indexEndSurfHeight).ToString());
                                }
                            }
                            if (!row.IsNull(indexShape) && !row.IsNull(indexFootPrint))
                            {
                                object objFootPrint = row.GetValue(indexFootPrint);
                                object objShape     = row.GetValue(indexShape);
                                if (objFootPrint is IPolyline && objShape is IPolyline)
                                {
                                    IPolyline polylineFootPrint = objFootPrint as IPolyline;
                                    IPolyline polylineShape     = objShape as IPolyline;
                                    PPLine    ppline            = new PPLine();
                                    if (indexClassify == -1 || row.IsNull(indexClassify))
                                    {
                                        ppline.facType = mc.Name;
                                    }
                                    else
                                    {
                                        ppline.facType = row.GetValue(indexClassify).ToString();
                                    }
                                    if (!row.IsNull(indexDiameter))
                                    {
                                        string diameter = row.GetValue(indexDiameter).ToString();
                                        if (diameter.Trim() == "")
                                        {
                                            continue;
                                        }
                                        ppline.dia = diameter;
                                        int indexDia = diameter.IndexOf('*');
                                        if (indexDia != -1)
                                        {
                                            ppline.isrect = true;
                                            int  iDia1;
                                            bool bDia1 = int.TryParse(diameter.Substring(0, indexDia), out iDia1);
                                            if (!bDia1)
                                            {
                                                continue;
                                            }
                                            int  iDia2;
                                            bool bDia2 = int.TryParse(diameter.Substring(indexDia + 1, diameter.Length - indexDia - 1), out iDia2);
                                            if (!bDia2)
                                            {
                                                continue;
                                            }
                                            ppline.gj.Add(iDia1);
                                            ppline.gj.Add(iDia2);
                                        }
                                        else
                                        {
                                            ppline.isrect = false;
                                            int  iDia;
                                            bool bDia = int.TryParse(diameter, out iDia);
                                            if (!bDia)
                                            {
                                                continue;
                                            }
                                            ppline.gj.Add(iDia);
                                            ppline.gj.Add(iDia);
                                        }
                                    }
                                    int hlb = 0;
                                    if (indexHLB != -1 && !row.IsNull(indexHLB))
                                    {
                                        string strhlb = row.GetValue(indexHLB).ToString();
                                        if (strhlb.Contains("内"))
                                        {
                                            hlb = 1;
                                        }
                                        else if (strhlb.Contains("外"))
                                        {
                                            hlb = -1;
                                        }
                                        else
                                        {
                                            hlb = 0;
                                        }
                                        ppline.hlb = hlb;
                                    }
                                    IPoint ptIntersect = dr["InterPoint"] as IPoint;
                                    ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y, ptIntersect.Z);
                                    ppline.clh        = GetInterPointHeight(ptIntersect, polylineShape, polylineFootPrint);
                                    if (ppline.clh > hmax)
                                    {
                                        hmax = ppline.clh;
                                    }
                                    if (ppline.clh < hmin)
                                    {
                                        hmin = ppline.clh;
                                    }
                                    if (app.Current3DMapControl.Terrain.IsRegistered)
                                    {
                                        ppline.cgh = app.Current3DMapControl.Terrain.GetElevation(ptIntersect.X, ptIntersect.Y, Gvitech.CityMaker.RenderControl.gviGetElevationType.gviGetElevationFromDatabase);
                                    }
                                    else
                                    {
                                        ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight)
                                                     * Math.Sqrt((polylineFootPrint.StartPoint.X - ptIntersect.X) * (polylineFootPrint.StartPoint.X - ptIntersect.X)
                                                                 + (polylineFootPrint.StartPoint.Y - ptIntersect.Y) * (polylineFootPrint.StartPoint.Y - ptIntersect.Y)) / polylineFootPrint.Length;
                                    }
                                    if (ppline.cgh > hmax)
                                    {
                                        hmax = ppline.cgh;
                                    }
                                    if (ppline.cgh < hmin)
                                    {
                                        hmin = ppline.cgh;
                                    }
                                    // 辅助画图
                                    ppline.startPt = new PPPoint(startPt.X, startPt.Y, startPt.Z);
                                    pplines.Add(ppline);
                                }
                            }
                        }
                    }
                    catch (Exception ex) { }
                    finally
                    {
                        if (cursor != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                            cursor = null;
                        }
                        if (row != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                            row = null;
                        }
                    }
                }
                WaitForm.Stop();
                if (pplines.Count < 2)
                {
                    XtraMessageBox.Show("点数少于2个", "提示");
                    return;
                }
                pplines.Sort(new PPLineCompare());
                double spacesum = 0.0;
                for (int i = 1; i < pplines.Count; i++)
                {
                    PPLine line1 = pplines[i - 1];
                    PPLine line2 = pplines[i];
                    line2.space = Math.Sqrt((line1.interPoint.X - line2.interPoint.X) * (line1.interPoint.X - line2.interPoint.X)
                                            + (line1.interPoint.Y - line2.interPoint.Y) * (line1.interPoint.Y - line2.interPoint.Y));
                    spacesum += line2.space;
                }
                ;
                var                str1    = (pplines[0].interPoint.X / 1000).ToString("0.00");
                var                str2    = (pplines[0].interPoint.Y / 1000).ToString("0.00");
                string             mapNum  = str2 + "-" + str1;
                string             mapName = SystemInfo.Instance.SystemFullName + "纵断面图";
                FrmSectionAnalysis dialog  = new FrmSectionAnalysis("纵断面分析结果", 1);
                dialog.SetInfo(mapName, mapNum, pplines, hmax, hmin, spacesum, road2);
                dialog.Show();
            }
            catch (Exception ex)
            {
                WaitForm.Stop();
            }
            finally
            {
            }
        }
コード例 #3
0
        private void DrawHDM()
        {
            try
            {
                if (this.bmp != null)
                {
                    this.bmp.Dispose();
                    this.bmp = null;
                }
                if (this.g != null)
                {
                    this.g.Dispose();
                    this.bmp = null;
                }
                this.bmp = new Bitmap(this.bmpWidth, this.bmpheight);
                this.g   = Graphics.FromImage(bmp);
                this.g.Clear(Color.White);

                // 外廓线
                Pen pen            = new Pen(Color.Black, 4);
                int outlineXOrigin = left;
                int outlineYOrigin = top + titleHeight;
                int outlineWidth   = this.bmpWidth - outlineXOrigin - right;
                int outlineHeight  = this.bmpheight - outlineYOrigin - bottom;
                this.g.DrawRectangle(pen, outlineXOrigin, outlineYOrigin, outlineWidth, outlineHeight);

                // 标题
                Font       font      = new Font("黑体", 16);
                SolidBrush brush     = new SolidBrush(Color.Black);
                SizeF      vSizeF    = g.MeasureString(this.mapname, font);
                int        pxMapName = (int)vSizeF.Width;
                g.DrawString(this.mapname, font, brush, outlineXOrigin + (outlineWidth - pxMapName) / 2, 3);
                // 所在道路
                font = new Font("Times New Roman", 9);
                g.DrawString("所在道路:" + roadname, font, brush, outlineXOrigin, outlineYOrigin - 20);
                // 断面号
                string tempMapNum = "断面号:" + mapnum;
                vSizeF = g.MeasureString(tempMapNum, font);
                int pxMapNum = (int)vSizeF.Width;
                g.DrawString(tempMapNum, font, brush, outlineXOrigin + outlineWidth - pxMapNum, outlineYOrigin - 20);
                // 表格线
                pen = new Pen(Color.Black, 3);
                int tableXOrigin = outlineXOrigin + outlineInterval;
                int tableYEnd    = this.bmpheight - bottom - outlineInterval;
                int tableYOrigin = tableYEnd - tableHeight;
                int tableXEnd    = this.bmpWidth - tableXOrigin - right + outlineInterval;
                int rowHeight    = tableHeight / rowCount;
                this.g.DrawLine(pen, tableXOrigin, tableYOrigin, tableXEnd, tableYOrigin);
                this.g.DrawLine(pen, tableXOrigin, tableYEnd, tableXEnd, tableYEnd);
                this.g.DrawLine(pen, tableXOrigin, tableYOrigin, tableXOrigin, tableYEnd);
                this.g.DrawLine(pen, tableXEnd, tableYOrigin, tableXEnd, tableYEnd);
                pen = new Pen(Color.Black, 2);
                for (int i = 1; i <= rowCount - 1; i++)
                {
                    this.g.DrawLine(pen, tableXOrigin, tableYOrigin + rowHeight * i, tableXEnd, tableYOrigin + rowHeight * i);
                }
                this.g.DrawLine(pen, tableXOrigin + leftYAxis, tableYOrigin, tableXOrigin + leftYAxis, tableYEnd);
                // 表格文字
                font = new Font("Times New Roman", 11);
                g.DrawString("地面高程(m)", font, brush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 0 + 15);
                g.DrawString("管线高程(m)", font, brush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 1 + 15);
                g.DrawString("规   格(mm)", font, brush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 2 + 15);
                g.DrawString("间    距(m)", font, brush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 3 + 15);
                g.DrawString("总    长(m)", font, brush, (float)tableXOrigin + 5, (float)tableYOrigin + rowHeight * 4 + 15);

                //绘图
                int drawXOrigin1 = tableXOrigin + leftYAxis;
                int drawYOrigin1 = outlineYOrigin + outlineInterval;
                int drawXEnd1    = tableXEnd;
                int drawYEnd1    = tableYOrigin;
                this.g.DrawLine(pen, drawXOrigin1, drawYOrigin1, drawXOrigin1, drawYEnd1);
                int    drawXOrigin = drawXOrigin1 + interval;
                int    drawYOrigin = drawYOrigin1 + 2 * interval;
                int    drawXEnd    = drawXEnd1 - 2 * interval;
                int    drawYEnd    = drawYEnd1 - interval;
                int    drawWidth   = drawXEnd - drawXOrigin;
                int    drawHeight  = drawYEnd - drawYOrigin;
                double scaleX      = distsum / drawWidth;
                double scaleY      = (hmax - hmin) / drawHeight;
                double scaleXReal  = scaleX * g.DpiX / 0.0254;
                double scaleYReal  = scaleY * g.DpiY / 0.0254;
                g.DrawString("比例尺", font, brush, drawXOrigin1 + (drawXEnd1 - drawXOrigin1) / 2 - 120, drawYOrigin1 + 10);
                g.DrawString("水平 1:" + scaleXReal.ToString("0"), font, brush, drawXOrigin1 + (drawXEnd1 - drawXOrigin1) / 2 - 60, drawYOrigin1);
                g.DrawString("垂直 1:" + scaleYReal.ToString("0"), font, brush, drawXOrigin1 + (drawXEnd1 - drawXOrigin1) / 2 - 60, drawYOrigin1 + 20);
                // 刻度
                font = new Font("Times New Roman", 9);
                int ihmax = int.Parse(Math.Ceiling(hmax).ToString());
                int ihmin = int.Parse(Math.Ceiling(hmin).ToString());
                int deth  = ihmax - ihmin;
                if (deth <= 10)
                {
                    for (int i = ihmin; i <= ihmax; i = i + 1)
                    {
                        float dialY = (float)(drawYOrigin + (hmax - i) / scaleY);
                        g.DrawLine(pen, drawXOrigin1 - 4, dialY, drawXOrigin1, dialY);
                        g.DrawString(i.ToString("0.0"), font, brush, drawXOrigin1 - 30, dialY - 5);
                    }
                }
                else if (deth < 20 && deth > 10)
                {
                    for (int i = ihmin; i <= ihmax; i = i + 2)
                    {
                        float dialY = (float)(drawYOrigin + (hmax - i) / scaleY);
                        g.DrawLine(pen, drawXOrigin1 - 4, dialY, drawXOrigin1, dialY);
                        g.DrawString(i.ToString("0.0"), font, brush, drawXOrigin1 - 30, dialY - 5);
                    }
                }
                else
                {
                    double intervalDial = deth / 10 * 10.0 / dialCount;
                    for (int i = 0; i <= dialCount; i++)
                    {
                        float  dialY     = (float)(drawYOrigin + i * intervalDial);
                        double dialValue = hmax - i * intervalDial * scaleY;
                        g.DrawLine(pen, drawXOrigin1 - 4, dialY, drawXOrigin1, dialY);
                        g.DrawString(dialValue.ToString("0.0"), font, brush, drawXOrigin1 - 30, dialY - 5);
                    }
                }

                // 管线
                RotateText rotate = new RotateText();
                rotate.Graphics = g;
                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Center;
                format.LineAlignment = StringAlignment.Center;
                PPLine pt0 = this.pplines[0];
                foreach (PPLine pt in this.pplines)
                {
                    PPPoint ptInter = pt.interPoint;
                    double  dis     = Math.Sqrt((ptInter.X - pt0.interPoint.X) * (ptInter.X - pt0.interPoint.X) + (ptInter.Y - pt0.interPoint.Y) * (ptInter.Y - pt0.interPoint.Y));
                    int     pxx     = int.Parse(Math.Ceiling(dis / scaleX).ToString());
                    int     pxy     = int.Parse(Math.Ceiling((pt.clh - hmin) / scaleY).ToString());
                    int     ippw    = 10;
                    int     ipph    = 10;
                    int     ppw     = int.Parse(Math.Ceiling(pt.gj[0] * 0.001 / scaleX).ToString());
                    int     pph     = int.Parse(Math.Ceiling(pt.gj[1] * 0.001 / scaleY).ToString());
                    //if (ppw > ippw) ippw = ppw;
                    //if (pph > ipph) ipph = pph;
                    int detStandard = 0;// 内底or外顶
                    if (pt.hlb == 1)
                    {
                        detStandard += ipph / 2;
                    }
                    else if (pt.hlb == -1)
                    {
                        detStandard -= ipph / 2;
                    }
                    int ppcx = drawXOrigin + pxx - ippw / 2;
                    int ppcy = drawYEnd - pxy - ipph / 2 + detStandard;
                    pen = new Pen(Color.DarkBlue, 2);
                    if (pt.isrect)
                    {
                        g.DrawRectangle(pen, ppcx, ppcy, ippw, ipph);
                    }
                    else
                    {
                        g.DrawEllipse(pen, ppcx, ppcy, ippw, ipph);
                    }
                    pen           = new Pen(Color.Black, 1);
                    pen.DashStyle = DashStyle.Dash;
                    g.DrawLine(pen, drawXOrigin + pxx, drawYEnd - pxy, drawXOrigin + pxx, tableYEnd - rowHeight);

                    font  = new Font("Times New Roman", 8);
                    brush = new SolidBrush(Color.DarkBlue);
                    if (pt.hlb == 1)
                    {
                        g.DrawString(pt.facType, font, brush, ppcx + ippw / 2 + 3, ppcy + 3);
                    }
                    else if (pt.hlb == -1)
                    {
                        g.DrawString(pt.facType, font, brush, ppcx + ippw / 2 + 3, ppcy + ipph + 3);
                    }
                    else if (pt.hlb == 0)
                    {
                        g.DrawString(pt.facType, font, brush, ppcx + ippw / 2 + 3, ppcy + ipph / 2 + 3);
                    }

                    rotate.DrawString(pt.clh.ToString("0.000"), font, brush, new PointF(ppcx - 3, tableYOrigin + rowHeight * 1 + 20), format, -90f);
                    if (pt.isrect)
                    {
                        rotate.DrawString(pt.dia, font, brush, new PointF(ppcx - 3, tableYOrigin + rowHeight * 2 + 20), format, -90f);
                    }
                    else
                    {
                        rotate.DrawString("DN" + pt.dia, font, brush, new PointF(ppcx - 3, tableYOrigin + rowHeight * 2 + 20), format, -90f);
                    }

                    brush = new SolidBrush(Color.Sienna);
                    rotate.DrawString(pt.cgh.ToString("0.000"), font, brush, new PointF(ppcx - 3, tableYOrigin + rowHeight * 0 + 20), format, -90f);
                }
                int gxx0 = 0;
                int gxy0 = 0;
                int pxy0 = 0;
                for (int i = 0; i < this.pplines.Count; i++)
                {
                    PPLine  pt      = this.pplines[i];
                    PPPoint ptInter = pt.interPoint;
                    double  dis     = Math.Sqrt((ptInter.X - pt0.interPoint.X) * (ptInter.X - pt0.interPoint.X) + (ptInter.Y - pt0.interPoint.Y) * (ptInter.Y - pt0.interPoint.Y));
                    int     gxx     = int.Parse(Math.Ceiling(dis / scaleX).ToString());
                    int     gxy     = int.Parse(Math.Ceiling((pt.cgh - hmin) / scaleY).ToString());
                    int     pxy     = int.Parse(Math.Ceiling((pt.clh - hmin) / scaleY).ToString());
                    if (i == 0)
                    {
                        // 标识
                        font  = new Font("Times New Roman", 9);
                        brush = new SolidBrush(Color.Sienna);
                        g.DrawString("地面", font, brush, drawXOrigin1 - 60, drawYEnd - gxy - 5);
                        font  = new Font("Times New Roman", 9);
                        brush = new SolidBrush(Color.DarkBlue);
                        g.DrawString("管线", font, brush, drawXOrigin1 - 60, drawYEnd - pxy - 5);

                        gxx0 = gxx;
                        gxy0 = gxy;
                        pxy0 = pxy;
                    }
                    else
                    {
                        if (this._type == 1)
                        {
                            pen = new Pen(Color.DarkBlue, 3);
                            g.DrawLine(pen, drawXOrigin + gxx0, drawYEnd - pxy0, drawXOrigin + gxx, drawYEnd - pxy);
                        }
                        //间距
                        double space    = pt.space;
                        string strspace = space.ToString("0.00");
                        vSizeF = g.MeasureString(strspace, font);
                        int pxspace = (int)vSizeF.Width;
                        g.DrawString(strspace, font, brush, drawXOrigin + (gxx + gxx0) / 2 - pxspace / 2, (float)tableYOrigin + rowHeight * 3 + 12);
                        //地面线
                        pen = new Pen(Color.Sienna, 3);
                        g.DrawLine(pen, drawXOrigin + gxx0, drawYEnd - gxy0, drawXOrigin + gxx, drawYEnd - gxy);
                        gxx0 = gxx;
                        gxy0 = gxy;
                    }
                }
                //总长
                string strdistnum = this.distsum.ToString("0.00");
                vSizeF = g.MeasureString(strdistnum, font);
                int pxdistnum = (int)vSizeF.Width;
                g.DrawString(strdistnum, font, brush, (drawXOrigin + drawXEnd) / 2 - pxdistnum / 2, (float)tableYOrigin + rowHeight * 4 + 12);
            }
            catch (Exception ex)
            {
            }
        }