//求SewerElev字段中的最大值 private double FindSEmaxValue() { double maxSE = 0; for (int i = 0; i <= m_pSewerElevArray.Count - 1; i++) { clsProfileStruct pProfileData = m_pSewerElevArray.get_Element(i) as clsProfileStruct; if (pProfileData.dSewerElev > maxSE) { maxSE = pProfileData.dSewerElev; } } return(maxSE); }
//求SewerElev字段中的最小值 private double FindSEminValue() { clsProfileStruct pProfileData = m_pSewerElevArray.get_Element(0) as clsProfileStruct; double minSE = pProfileData.dSewerElev; for (int i = 0; i <= m_pSewerElevArray.Count - 1; i++) { pProfileData = m_pSewerElevArray.get_Element(i) as clsProfileStruct; if (pProfileData.dSewerElev < minSE) { minSE = pProfileData.dSewerElev; } } return(minSE); }
private void frmDrawProfile_Paint(object sender, PaintEventArgs e) { //取得记录数量 int count = m_pSewerElevArray.Count; //计算图表宽度 int wd = 80 + 20 * (count - 1); //设置最小宽度 if (wd < 800) { wd = 800; } //生成Bitmap对象 //生成绘图对象 Graphics g = e.Graphics; //定义黑色画笔 Pen Bp = new Pen(Color.Black); //定义红色画笔 Pen Rp = new Pen(Color.Red); //定义银灰色画笔 Pen Sp = new Pen(Color.Silver); //定义大标题字体 Font Bfont = new Font("Arial", 12, FontStyle.Bold); //定义一般字体 Font font = new Font("Arial", 6); //定义大点的字体 Font Tfont = new Font("Arial", 9); //绘制底色 g.DrawRectangle(new Pen(Color.White, 400), 0, 0, wd, 400); //定义黑色过度型笔刷 LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, wd, 400), Color.Black, Color.Black, 1.2F, true); //定义兰色过度型笔刷 LinearGradientBrush Bluebrush = new LinearGradientBrush(new Rectangle(0, 0, wd, 400), Color.Blue, Color.Blue, 1.2F, true); //绘制大标题 g.DrawString("管线高程剖面曲线图", Bfont, brush, 40, 5); //绘制边框 g.DrawRectangle(Bp, 0, 0, wd - 1, 400 - 1); //绘制竖坐标线 int i = 0; for (i = 0; i < count; i++) { g.DrawLine(Sp, 40 + 20 * i, 60, 40 + 20 * i, 360); } //绘制竖坐标标签 for (i = 0; i < count; i++) { clsProfileStruct s = m_pSewerElevArray.get_Element(i) as clsProfileStruct; string st = s.M.ToString(); g.DrawString(st, font, brush, 30 + 20 * i, 370); } //绘制横坐标线 for (i = 0; i < 10; i++) { g.DrawLine(Sp, 40, 60 + 30 * i, 40 + 20 * (count - 1), 60 + 30 * i); int s = 500 - 50 * i * 5; g.DrawString(s.ToString(), font, brush, 10, 60 + 30 * i); } //绘制竖坐标轴 g.DrawLine(Bp, 40, 55, 40, 360); //绘制横坐标轴 g.DrawLine(Bp, 40, 360, 45 + 20 * (count - 1), 360); //定义曲线转折点 Point[] p = new Point[count]; for (i = 0; i < count; i++) { clsProfileStruct s = m_pSewerElevArray.get_Element(i) as clsProfileStruct; p[i].X = 40 + 20 * i; p[i].Y = 360 - Convert.ToInt32(s.Z) / 5; } //绘制曲线 g.DrawLines(Rp, p); for (i = 0; i < count; i++) { clsProfileStruct s = m_pSewerElevArray.get_Element(i) as clsProfileStruct; g.DrawString(s.Z.ToString(), font, Bluebrush, p[i].X, p[i].Y - 10); g.DrawRectangle(Rp, p[i].X - 1, p[i].Y - 1, 2, 2); } }
//根据多段线和阀门数组创建高程剖面 public static void ProfileCreateGraph(MainFrm pMainFrm, IPolyline pPolyline, IArray pSewerElevArray) { AxMapControl axMap = pMainFrm.getMapControl(); IZ pPolylineZ = pPolyline as IZ; IRasterLayer pRasterLyr = FindRasterLayer("Elevation", pMainFrm); //获得表面进行插值 ISurface pSurface = GetSurface(pRasterLyr); //创建Polyline z-ware; IZAware pZAwareLineZ = pPolyline as IZAware; pZAwareLineZ.ZAware = true; //'* work around for InterpolateFromSurface sometimes flipping polyline IPoint pPtOrigFrom = pPolyline.FromPoint; IPoint pPtOrigTo = pPolyline.ToPoint; //添加Z值到多边形上 pPolylineZ.InterpolateFromSurface(pSurface); if (pPolyline.FromPoint.X != pPtOrigFrom.X || pPolyline.FromPoint.Y != pPtOrigFrom.Y) pPolyline.ReverseOrientation(); //添加M值到线上 IMSegmentation pMSegmentation = pPolyline as IMSegmentation; IMAware pMAware = pPolyline as IMAware; pMAware.MAware = true; pMSegmentation.SetMsAsDistance(false); //创建表格 ITable pTable = ProfileCreateTable(); int i=0; if (pTable != null) { //在图层列表控件中要确保该表格还不存在,如果存在则删除它 IStandaloneTableCollection pStandAloneTabColl = axMap.ActiveView.FocusMap as IStandaloneTableCollection; for ( i = 0; i<=pStandAloneTabColl.StandaloneTableCount - 1; i++) { if (pStandAloneTabColl.get_StandaloneTable(i).Name == "xxprofiletable") pStandAloneTabColl.RemoveStandaloneTable(pStandAloneTabColl.get_StandaloneTable(i)); } //创建一个新的独立表,并把它添加到地图集合中 IStandaloneTable pStandAloneTab = new StandaloneTableClass(); pStandAloneTab.Table = pTable; pStandAloneTabColl = axMap.ActiveView.FocusMap as IStandaloneTableCollection; pStandAloneTabColl.AddStandaloneTable(pStandAloneTab); pTable = pStandAloneTab as ITable; //为两个字段设置别名 ITableFields pTableFields = pStandAloneTab as ITableFields; IFieldInfo pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("Z")); pFieldInfo.Alias = "Ground Elevation"; pFieldInfo = pTableFields.get_FieldInfo(pTableFields.FindField("SewerElev")); pFieldInfo.Alias = "Sewer Line Elevation"; //为表格获得一个插入光标 ICursor pCursor=pTable.Insert(true); IRowBuffer pRowBuff; // IPointCollection pPtCollection = pPolyline as IPointCollection; IEnumVertex pEnumVertex = pPtCollection.EnumVertices; pEnumVertex.Reset(); IPoint pPT; int iPartIndex; int iVertexIndex; i = 0; //添加节点XYZ到新表格中 pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex); while (pPT != null) { pRowBuff = pTable.CreateRowBuffer(); pRowBuff.set_Value(pRowBuff.Fields.FindField("X"),pPT.X); pRowBuff.set_Value(pRowBuff.Fields.FindField("Y"),pPT.Y); pRowBuff.set_Value(pRowBuff.Fields.FindField("Z"),pPT.Z); pRowBuff.set_Value( pRowBuff.Fields.FindField("M"),pPT.M); pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), Convert.ToDouble(pSewerElevArray.get_Element(i))); pCursor.InsertRow(pRowBuff); pEnumVertex.Next(out pPT, out iPartIndex, out iVertexIndex); i = i + 1; } pCursor.Flush(); pCursor = null; pCursor = pTable.Search(null, false); IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = "SewerElev <> -99"; ICursor pCursorSewerElev = pTable.Search(pQueryFilter, false); pCursor = null; pCursor = pTable.Update(null, false); pRowBuff = pCursor.NextRow(); double m = 0; double Mmin=0; double Mmax=0; double deltaM=0; double deltaSewerElev=0; double sewerelev=0; double newZ=0; int j = 0; double minSewerElev=0; double maxSewerElev=0; IRow pRowSewerElev; while (pRowBuff != null) { if (Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("SewerElev"))) == -99) { m = Convert.ToDouble(pRowBuff.get_Value(pRowBuff.Fields.FindField("M"))); newZ = (((m - Mmin) / deltaM) * deltaSewerElev) + sewerelev; pRowBuff.set_Value(pRowBuff.Fields.FindField("SewerElev"), newZ); pCursor.UpdateRow(pRowBuff as IRow); } else { if (j == 0) { pRowSewerElev = pCursorSewerElev.NextRow(); minSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev"))); Mmin = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"))); pRowSewerElev = pCursorSewerElev.NextRow(); maxSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev"))); Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"))); } else { pRowSewerElev = pCursorSewerElev.NextRow(); if (pRowSewerElev != null) { minSewerElev = maxSewerElev; Mmin = Mmax; maxSewerElev =Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("SewerElev"))); Mmax = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"))); } } deltaSewerElev = maxSewerElev - minSewerElev; deltaM = Mmax - Mmin; sewerelev = minSewerElev; j = j + 1; } pRowBuff = pCursor.NextRow() as IRowBuffer; } pCursor.Flush(); //从表格中创建图形 m_SewerElevStructArray = new ArrayClass(); pCursor = null; pCursor = pTable.Search(null, false); pRowSewerElev = null; pRowSewerElev = pCursor.NextRow(); while (pRowSewerElev != null) { clsProfileStruct pProfileDataStruct = new clsProfileStruct(); pProfileDataStruct.M = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("M"))); pProfileDataStruct.Z = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Z"))); pProfileDataStruct.dSewerElev = Convert.ToDouble(pRowSewerElev.get_Value(pRowSewerElev.Fields.FindField("Sewerelev"))); m_SewerElevStructArray.Add(pProfileDataStruct); pRowSewerElev = pCursor.NextRow(); } frmDrawProfile frmDrawProfile1 = new frmDrawProfile(m_SewerElevStructArray); frmDrawProfile1.Show(); } }