我有一个winform输入钻孔数据(图1):
使用输入数据绘制一个地面轮廓(当前曲线)(图2):
但是它不符合期望的结果。 (理想结果)(图3)。
点收集的代码如下
List<Point> DrawGraph(DataSet dSet, TextureBrush tb,double twentyPerc,double maxSpace, float onePtYSpace, Font ft,int bH_count, List<Point> lastlayerP)
{
List<Point> layerEndPos = new List<Point>();
List<Point> layerStartPos = new List<Point>();
for (int i = 0; i < dSet.Tables[0].Rows.Count; i++)
{
string bhName = dSet.Tables[0].Rows[i][0].ToString();
float bh_Elevation = float.Parse(dSet.Tables[0].Rows[i][3].ToString());
float layerStart = float.Parse(dSet.Tables[0].Rows[i][6].ToString());
float layerEnd = float.Parse(dSet.Tables[0].Rows[i][7].ToString()) - layerStart;
Point pt = new Point();
int jumpBH = 0;
if ("BH- " + ((i + 1).ToString()) != bhName)
{
if (lastlayerP.Count != 0)
{
string[] str = bhName.Split(' ');
int bhn = int.Parse(str[1]);
layerStartPos.Add(lastlayerP[bhn - 2]);
layerEndPos.Add(lastlayerP[bhn - 2]);
jumpBH = bhn - (i + 1);
}
}
float bhXPos = bH_count == 0 ? float.Parse((twentyPerc / 2).ToString()) : float.Parse(((maxSpace * (i + jumpBH)) + twentyPerc).ToString());
if (lastlayerP.Count == 0)
{
StringFormat st = new StringFormat();
drawBH.DrawString(bhName, ft, Brushes.Black, bhXPos - 10, 15, st);
}
pt.X = (int)Math.Round(bhXPos);
float YPos = (bh_Elevation + layerStart) * onePtYSpace;
pt.Y = (int)Math.Round(YPos+30);
layerStartPos.Add(pt);
YPos = (bh_Elevation + layerStart + layerEnd) * onePtYSpace;
pt.Y = (int)Math.Round(YPos + 30);
layerEndPos.Add(pt);
}
Point[] PtArray = new Point[layerEndPos.Count + layerStartPos.Count];
int ind = 0;
foreach (Point pt in layerStartPos)
{
PtArray[ind] = pt;
ind++;
}
for (int j = layerEndPos.Count - 1; j > -1; j--)
{
PtArray[ind] = layerEndPos.ElementAt(j);
ind++;
}
drawBH.FillPolygon(tb, PtArray);
return layerEndPos;
}
绘制轮廓的代码如下
try
{
drawBHArea();
drawBH.Clear(Color.White);
Pen blackPen = new Pen(Color.Black);
Pen capPen = new Pen(Color.Black, 3);
capPen.SetLineCap(LineCap.NoAnchor, LineCap.ArrowAnchor, DashCap.Flat);
double maxheight = 106;
double maxWidth = 400;
drawBH.DrawRectangle(blackPen, 2, 28, float.Parse((maxWidth - 40).ToString()), float.Parse((maxheight).ToString()));
drawBH.FillRectangle(Brushes.LightGray, 2, 28, float.Parse((maxWidth - 40).ToString()), float.Parse((maxheight).ToString()));
FontFamily fM = new FontFamily("Maiandra GD");
Font ft = new Font(fM, 8, GraphicsUnit.Point);
StringFormat st = new StringFormat();
drawBH.DrawLine(capPen, 370, 70, 370, 110);
drawBH.DrawLine(capPen, 200, 150, 280, 150);
drawBH.DrawString("Elevation" +Environment.NewLine + "GL- (m)", ft, Brushes.Black, float.Parse((maxWidth - 30).ToString()), float.Parse((maxheight + 10).ToString()), st);
drawBH.DrawString("Length (m)", ft, Brushes.Black, float.Parse((maxWidth/2 - 55).ToString()), float.Parse((maxheight + 35).ToString()), st);
double maxSpace = maxWidth / double.Parse(bH_count.ToString());
float onePtYSpace = float.Parse((maxheight / 70).ToString());
double twentyPerc = maxSpace / 10.0;
string[] layers = { "Fill", "Alluvium", "Weathered Soil", "Weathered Rock", "Soft Rock", "Medium Rock", "Hard Rock" };
List<Point> layerEndPos = new List<Point>();
foreach (string lay in layers)
{
DataSet dSet = new DataSet();
sqlQuery = "select * from BoreholeInformation where Strata = '"+lay+"'";
command = new SQLiteCommand(sqlQuery, m_dbConnection);
dA = new SQLiteDataAdapter(command);
dA.Fill(dSet);
if (dSet.Tables[0].Rows.Count == 0)
{
break;
}
TextureBrush tb;
switch (lay)
{
case "Fill":
tb = new TextureBrush(Properties.Resources.Fill);
break;
case "Alluvium":
tb = new TextureBrush(Properties.Resources.Alluvium);
break;
case "Weathered Soil":
tb = new TextureBrush(Properties.Resources.WSoil);
break;
case "Weathered Rock":
tb = new TextureBrush(Properties.Resources.WRock);
break;
case "Soft Rock":
tb = new TextureBrush(Properties.Resources.SRock);
break;
case "Medium Rock":
tb = new TextureBrush(Properties.Resources.WRock);
break;
default:
tb = new TextureBrush(Properties.Resources.SRock);
break;
}
layerEndPos = DrawGraph(dSet, tb, twentyPerc, maxSpace, onePtYSpace,ft,bH_count,layerEndPos);
}
m_dbConnection.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
问题似乎在各个图层的多边形的点集合中。如何更新代码以获得准确的结果?