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; PPLine2D pt0 = this.pplines[0]; foreach (PPLine2D 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++) { PPLine2D 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) { } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; if (app == null || app.Current2DMapControl == null) { return; } IActiveView m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; try { if (button == 1) { ISimpleLineSymbol pLineSym = new SimpleLineSymbol(); IRgbColor pColor = new RgbColorClass(); pColor.Red = 255; pColor.Green = 255; pColor.Blue = 0; pLineSym.Color = pColor; pLineSym.Style = esriSimpleLineStyle.esriSLSSolid; pLineSym.Width = 2; IRubberBand pRubberBand; pRubberBand = new RubberLineClass(); IGeometry pLine = pRubberBand.TrackNew(m_Display, null); object symbol = pLineSym as object; app.Current2DMapControl.DrawShape(pLine, ref symbol); if ((pLine as IPolyline).Length > 500) { XtraMessageBox.Show("横断面线超过500米,分析效率很低,请重新绘制", "提示"); return; } WaitForm.Start("正在进行横断面分析...", "请稍后"); pGeo = pLine; if (pGeo == null) { return; } string road1 = ""; string road2 = ""; bool bAlert = false; double hmax = double.MinValue; double hmin = double.MaxValue; List <PPLine2D> pplines = new List <PPLine2D>(); IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass()) { foreach (SubClass sc in mc.SubClasses) { if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } foreach (string fc2DId in arrFc2DId) { DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); if (fc == null) { continue; } FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } //查找管径长宽字段,获得该要素类下字段索引值,若为圆管,则长宽相等 DFDataConfig.Class.FieldInfo fiDia = facc.GetFieldInfoBySystemName("Diameter"); DFDataConfig.Class.FieldInfo fiDia1 = facc.GetFieldInfoBySystemName("Diameter1"); DFDataConfig.Class.FieldInfo fiDia2 = facc.GetFieldInfoBySystemName("Diameter2"); int indexDia = fc.Fields.FindField(fiDia.Name); int indexDiaWith = fc.Fields.FindField(fiDia1.Name); int indexDiaHeight = fc.Fields.FindField(fiDia2.Name); if (indexDiaWith == -1 || indexDiaHeight == -1 || indexDia == -1) { continue; } //查找道路字段索引 DFDataConfig.Class.FieldInfo fiRoad = facc.GetFieldInfoBySystemName("Road"); int indexRoad = fc.Fields.FindField(fiRoad.Name); //查找管线高类别索引 DFDataConfig.Class.FieldInfo fiHLB = facc.GetFieldInfoBySystemName("HLB"); int indexHLB = fc.Fields.FindField(fiHLB.Name); //二级分类名索引 int indexClassify = fc.Fields.FindField(mc.ClassifyField); ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = UpOrDown.DecorateWhereClasuse(fc) + mc.ClassifyField + " = '" + sc.Name + "'"; int count = fc.FeatureCount(pSpatialFilter); if (count == 0) { continue; } pFeatureCursor = fc.Search(pSpatialFilter, true); while ((pFeature = pFeatureCursor.NextFeature()) != null) { if (indexRoad != -1) { if (road2 == "") { road1 = pFeature.get_Value(indexRoad).ToString(); road2 = pFeature.get_Value(indexRoad).ToString(); } else { road1 = pFeature.get_Value(indexRoad).ToString(); if (road1 != road2) { if (!bAlert) { XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线横断面图。", "提示"); bAlert = true; } continue; } } } //查找管线的起点终点地面高 double startSurfHeight = double.MaxValue; double endSurfHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartSurfHeight = facc.GetFieldInfoBySystemName("StartSurfH"); if (fiStartSurfHeight == null) { continue; } int indexStartSurfHeight = pFeature.Fields.FindField(fiStartSurfHeight.Name); if (indexStartSurfHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndSurfHeight = facc.GetFieldInfoBySystemName("EndSurfH"); if (fiEndSurfHeight == null) { continue; } int indexEndSurfHeight = pFeature.Fields.FindField(fiEndSurfHeight.Name); if (indexEndSurfHeight == -1) { continue; } //若管线属性地面高字段为null,则从DEM取值 if (pFeature.get_Value(indexStartSurfHeight).ToString() == "" || pFeature.get_Value(indexEndSurfHeight).ToString() == "") { startSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).FromPoint); endSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).ToPoint); } else { startSurfHeight = Convert.ToDouble(pFeature.get_Value(indexStartSurfHeight).ToString()); endSurfHeight = Convert.ToDouble(pFeature.get_Value(indexEndSurfHeight).ToString()); } //查找管线起点高程和终点高程 double startDepthHeight = double.MaxValue; double endDepthHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartDepthHeight = facc.GetFieldInfoBySystemName("StartHeight2D"); if (fiStartDepthHeight == null) { continue; } int indexStartDepthHeight = pFeature.Fields.FindField(fiStartDepthHeight.Name); if (indexStartDepthHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndDepthHeight = facc.GetFieldInfoBySystemName("EndHeight"); if (fiEndDepthHeight == null) { continue; } int indexEndDepthHeight = pFeature.Fields.FindField(fiEndDepthHeight.Name); if (indexEndDepthHeight == -1) { continue; } startDepthHeight = Convert.ToDouble(pFeature.get_Value(indexStartDepthHeight).ToString()); endDepthHeight = Convert.ToDouble(pFeature.get_Value(indexEndDepthHeight).ToString()); //计算管线和断面的交点 IGeometry ppGeo = pFeature.Shape; ITopologicalOperator pTopo = ppGeo as ITopologicalOperator; IGeometry geoIntersect = pTopo.Intersect(pGeo, esriGeometryDimension.esriGeometry0Dimension); if (geoIntersect == null) { continue; } PPLine2D ppline = new PPLine2D(); if (indexClassify == -1) { ppline.facType = mc.Name; } else { ppline.facType = pFeature.get_Value(indexClassify).ToString(); } //查找管线的管径,判断其是方管还是圆管 string diameter = pFeature.get_Value(indexDia).ToString(); string diameter1 = pFeature.get_Value(indexDiaWith).ToString(); string diameter2 = pFeature.get_Value(indexDiaHeight).ToString(); if (diameter.Trim() == "") { continue; } ppline.dia = diameter; int indexSplit = diameter.IndexOf('*'); if (indexSplit != -1) { ppline.isrect = true; int iDia1; bool bDia1 = int.TryParse(diameter.Substring(0, indexSplit), out iDia1); if (!bDia1) { continue; } int iDia2; bool bDia2 = int.TryParse(diameter.Substring(indexSplit + 1, diameter.Length - indexSplit - 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) { string strhlb = pFeature.get_Value(indexHLB).ToString(); if (strhlb.Contains("内")) { hlb = 1; } else if (strhlb.Contains("外")) { hlb = -1; } else { hlb = 0; } ppline.hlb = hlb; } #region 交点为一个 if (geoIntersect.GeometryType == esriGeometryType.esriGeometryPoint) { IPolyline polyline = pFeature.Shape as IPolyline; IPoint ptIntersect = geoIntersect as IPoint; ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y); ppline.clh = GetInterPointHeight(ptIntersect, polyline, startDepthHeight, endDepthHeight); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polyline.FromPoint.X - ptIntersect.X) * (polyline.FromPoint.X - ptIntersect.X) + (polyline.FromPoint.Y - ptIntersect.Y) * (polyline.FromPoint.Y - ptIntersect.Y)) / polyline.Length; if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 IPolyline l = pGeo as IPolyline; ppline.startPt = new PPPoint(l.FromPoint.X, l.FromPoint.Y); pplines.Add(ppline); } #endregion #region 交点为多个 else if (geoIntersect.GeometryType == esriGeometryType.esriGeometryMultipoint) { IPolyline polyline = pFeature.Shape as IPolyline; IPointCollection geoCol = geoIntersect as IPointCollection; for (int i = 0; i < geoCol.PointCount; i++) { IPoint ptIntersect = geoCol.get_Point(i); ppline.interPoint = new PPPoint(ptIntersect.X, ptIntersect.Y); ppline.clh = GetInterPointHeight(ptIntersect, polyline, startDepthHeight, endDepthHeight); if (ppline.clh > hmax) { hmax = ppline.clh; } if (ppline.clh < hmin) { hmin = ppline.clh; } ppline.cgh = startSurfHeight + (endSurfHeight - startSurfHeight) * Math.Sqrt((polyline.FromPoint.X - ptIntersect.X) * (polyline.FromPoint.X - ptIntersect.X) + (polyline.FromPoint.Y - ptIntersect.Y) * (polyline.FromPoint.Y - ptIntersect.Y)) / polyline.Length; if (ppline.cgh > hmax) { hmax = ppline.cgh; } if (ppline.cgh < hmin) { hmin = ppline.cgh; } // 辅助画图 IPolyline l = pGeo as IPolyline; ppline.startPt = new PPPoint(l.FromPoint.X, l.FromPoint.Y); pplines.Add(ppline); } } else { continue; } #endregion } } } } WaitForm.Stop(); if (pplines.Count < 2) { XtraMessageBox.Show("相交管线少于2个", "提示"); return; } pplines.Sort(new PPLineCompare2D()); double spacesum = 0.0; for (int i = 1; i < pplines.Count; i++) { PPLine2D line1 = pplines[i - 1]; PPLine2D 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 { WaitForm.Stop(); } }
public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY) { DF2DApplication app = DF2DApplication.Application; if (app == null || app.Current2DMapControl == null) { return; } IActiveView m_ActiveView = app.Current2DMapControl.ActiveView; IScreenDisplay m_Display = app.Current2DMapControl.ActiveView.ScreenDisplay; IGeometry pGeo = null; IFeatureCursor pFeatureCursor = null; IFeature pFeature = null; try { if (button == 1) { PointClass searchPoint = new PointClass(); searchPoint.PutCoords(mapX, mapY); pGeo = PublicFunction.DoBuffer(searchPoint, PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate)); if (pGeo == null) { return; } WaitForm.Start("正在进行纵断面分析...", "请稍后"); string road1 = ""; string road2 = ""; bool bAlert = false; double hmax = double.MinValue; double hmin = double.MaxValue; List <PPLine2D> pplines = new List <PPLine2D>(); bool haveone = false; List <MajorClass> listMC = LogicDataStructureManage2D.Instance.GetAllMajorClass(); foreach (MajorClass mc in listMC) { if (haveone) { break; } foreach (SubClass sc in mc.SubClasses) { if (haveone) { break; } if (!sc.Visible2D) { continue; } string[] arrFc2DId = mc.Fc2D.Split(';'); if (arrFc2DId == null) { continue; } foreach (string fc2DId in arrFc2DId) { if (haveone) { break; } DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); if (dffc == null) { continue; } IFeatureClass fc = dffc.GetFeatureClass(); FacilityClass facc = dffc.GetFacilityClass(); if (facc.Name != "PipeLine") { continue; } if (fc == null || pGeo == null) { continue; } ISpatialFilter pSpatialFilter = new SpatialFilter(); pSpatialFilter.Geometry = pGeo; pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; pSpatialFilter.WhereClause = UpOrDown.DecorateWhereClasuse(fc) + sc.Parent.ClassifyField + " = '" + sc.Name + "'"; pFeatureCursor = fc.Search(pSpatialFilter, true); if (pFeatureCursor == null) { continue; } pFeature = pFeatureCursor.NextFeature(); if (pFeature == null) { continue; } //查找管径长宽字段,获得该要素类下字段索引值,若为圆管,则长宽相等 DFDataConfig.Class.FieldInfo fiDia = facc.GetFieldInfoBySystemName("Diameter"); DFDataConfig.Class.FieldInfo fiDia1 = facc.GetFieldInfoBySystemName("Diameter1"); DFDataConfig.Class.FieldInfo fiDia2 = facc.GetFieldInfoBySystemName("Diameter2"); int indexDia = fc.Fields.FindField(fiDia.Name); int indexDiaWith = fc.Fields.FindField(fiDia1.Name); int indexDiaHeight = fc.Fields.FindField(fiDia2.Name); if (indexDiaWith == -1 || indexDiaHeight == -1 || indexDia == -1) { continue; } //查找道路字段索引 DFDataConfig.Class.FieldInfo fiRoad = facc.GetFieldInfoBySystemName("Road"); int indexRoad = fc.Fields.FindField(fiRoad.Name); //查找管线高类别索引 DFDataConfig.Class.FieldInfo fiHLB = facc.GetFieldInfoBySystemName("HLB"); int indexHLB = fc.Fields.FindField(fiHLB.Name); //二级分类名索引 int indexClassify = fc.Fields.FindField(mc.ClassifyField); if (indexRoad != -1) { if (road2 == "") { road1 = pFeature.get_Value(indexRoad).ToString(); road2 = pFeature.get_Value(indexRoad).ToString(); } else { road1 = pFeature.get_Value(indexRoad).ToString(); if (road1 != road2) { if (!bAlert) { XtraMessageBox.Show("横断面线跨越多条道路,当前只绘制在【" + road2 + "】上的管线纵断面图。", "提示"); bAlert = true; } continue; } } } //查找管线的起点终点地面高 double startSurfHeight = double.MaxValue; double endSurfHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartSurfHeight = facc.GetFieldInfoBySystemName("StartSurfH"); if (fiStartSurfHeight == null) { continue; } int indexStartSurfHeight = pFeature.Fields.FindField(fiStartSurfHeight.Name); if (indexStartSurfHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndSurfHeight = facc.GetFieldInfoBySystemName("EndSurfH"); if (fiEndSurfHeight == null) { continue; } int indexEndSurfHeight = pFeature.Fields.FindField(fiEndSurfHeight.Name); if (indexEndSurfHeight == -1) { continue; } //若管线属性地面高字段为null,则从DEM取值 if (pFeature.get_Value(indexStartSurfHeight).ToString() == "" || pFeature.get_Value(indexEndSurfHeight).ToString() == "") { startSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).FromPoint); endSurfHeight = ReadDemRaster.GetH((pFeature.Shape as IPolyline).ToPoint); } else { startSurfHeight = Convert.ToDouble(pFeature.get_Value(indexStartSurfHeight).ToString()); endSurfHeight = Convert.ToDouble(pFeature.get_Value(indexEndSurfHeight).ToString()); } //查找管线起点高程和终点高程 double startDepthHeight = double.MaxValue; double endDepthHeight = double.MaxValue; DFDataConfig.Class.FieldInfo fiStartDepthHeight = facc.GetFieldInfoBySystemName("StartHeight2D"); if (fiStartDepthHeight == null) { continue; } int indexStartDepthHeight = pFeature.Fields.FindField(fiStartDepthHeight.Name); if (indexStartDepthHeight == -1) { continue; } DFDataConfig.Class.FieldInfo fiEndDepthHeight = facc.GetFieldInfoBySystemName("EndHeight"); if (fiEndDepthHeight == null) { continue; } int indexEndDepthHeight = pFeature.Fields.FindField(fiEndDepthHeight.Name); if (indexEndDepthHeight == -1) { continue; } startDepthHeight = Convert.ToDouble(pFeature.get_Value(indexStartDepthHeight).ToString()); endDepthHeight = Convert.ToDouble(pFeature.get_Value(indexEndDepthHeight).ToString()); //查找管线的管径,判断其是方管还是圆管 string diameter = pFeature.get_Value(indexDia).ToString(); string diameter1 = pFeature.get_Value(indexDiaWith).ToString(); string diameter2 = pFeature.get_Value(indexDiaHeight).ToString(); IPolyline pline = pFeature.Shape as IPolyline; IPoint startpoint = pline.FromPoint; IPoint endpoint = pline.ToPoint; IPoint[] points = new IPoint[] { startpoint, endpoint }; for (int i = 0; i < points.Length; i++) { PPLine2D ppline = new PPLine2D(); if (indexClassify == -1) { ppline.facType = mc.Name; } else { ppline.facType = pFeature.get_Value(indexClassify).ToString(); } if (diameter.Trim() == "") { continue; } ppline.dia = diameter; int indexSplit = diameter.IndexOf('*'); if (indexSplit != -1) { ppline.isrect = true; int iDia1; bool bDia1 = int.TryParse(diameter.Substring(0, indexSplit), out iDia1); if (!bDia1) { continue; } int iDia2; bool bDia2 = int.TryParse(diameter.Substring(indexSplit + 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) { string strhlb = pFeature.get_Value(indexHLB).ToString(); if (strhlb.Contains("内")) { hlb = 1; } else if (strhlb.Contains("外")) { hlb = -1; } else { hlb = 0; } ppline.hlb = hlb; } ppline.interPoint = new PPPoint(points[i].X, points[i].Y); if (i == 0) { ppline.clh = startDepthHeight; UpdateH(ppline.clh, ref hmax, ref hmin); ppline.cgh = startSurfHeight; UpdateH(ppline.cgh, ref hmax, ref hmin); } else { ppline.clh = endDepthHeight; UpdateH(ppline.clh, ref hmax, ref hmin); ppline.cgh = endSurfHeight; UpdateH(ppline.cgh, ref hmax, ref hmin); } // 辅助画图 double deltaX = points[1].X - points[0].X; double deltaY = points[1].Y - points[0].Y; ppline.startPt = new PPPoint(points[0].X - deltaX, points[0].Y - deltaY); pplines.Add(ppline); } } } } WaitForm.Stop(); pplines.Sort(new PPLineCompare2D()); double spacesum = 0.0; for (int i = 1; i < pplines.Count; i++) { PPLine2D line1 = pplines[i - 1]; PPLine2D 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 (System.Exception ex) { WaitForm.Stop(); } finally { if (pFeatureCursor != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); pFeatureCursor = null; } if (pFeature != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature); pFeature = null; } } }