C# 如何利用钻孔数据绘制地面剖面?

C# 如何利用钻孔数据绘制地面剖面?,c#,winforms,graphics,drawing,C#,Winforms,Graphics,Drawing,我有一个winform来输入钻孔数据(图1): 使用输入数据I绘制接地剖面图(当前图)(图2): 但这并没有达到预期的效果。(期望结果)(图3) 点集合的代码如下所示 List<Point> DrawGraph(DataSet dSet, TextureBrush tb,double twentyPerc,double maxSpace, float onePtYSpace, Font ft,int bH_count, List<Point> lastlayerP)

我有一个winform来输入钻孔数据(图1):

使用输入数据I绘制接地剖面图(当前图)(图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); }
列出DrawGraph(数据集dSet、TextureBrush tb、double twentyPerc、double maxSpace、float onePtYSpace、Font ft、int bH_计数、列出lastlayerP)
{
List LAYERNDPOS=新列表();
List layerStartPos=新列表();
对于(int i=0;i-1;j--)
{
p阵列[ind]=层位置元素(j);
ind++;
}
drawBH.FillPolygon(tb,pArray);
返回位置;
}
绘制配置文件的代码如下所示

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); }
试试看
{              
drawBHArea();
清晰(颜色:白色);
钢笔黑色钢笔=新钢笔(颜色为黑色);
笔盖=新笔(颜色:黑色,3);
capPen.SetLineCap(LineCap.NoAnchor、LineCap.arrowsanchor、DashCap.Flat);
双倍最大高度=106;
双最大宽度=400;
drawBH.DrawRectangle(blackPen,2,28,float.Parse((maxWidth-40.ToString()),float.Parse((maxheight.ToString());
drawBH.FillRectangle(brushs.LightGray,2,28,float.Parse((maxWidth-40.ToString()),float.Parse((maxheight.ToString()));
FontFamily fM=新FontFamily(“Maiandra GD”);
Font ft=新字体(fM、8、GraphicsUnit.Point);
StringFormat st=新的StringFormat();
拉丝。拉丝(卡彭,370,70,370,110);
拉丝。拉丝(卡彭,200,150,280,150);
drawBH.DrawString(“标高”+Environment.NewLine+“GL-(m)”,英尺,画笔。黑色,float.Parse((maxWidth-30.ToString()),float.Parse((maxheight+10.ToString()),st);
drawBH.DrawString(“长度(m)”,英尺,画笔.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());
双twentyPerc=最大空间/10.0;
串[]层={“填料”、“冲积层”、“风化土”、“风化岩”、“软岩”、“中岩”、“硬岩”};
List LAYERNDPOS=新列表();
foreach(分层铺管)
{
数据集dSet=新数据集();
sqlQuery=“从钻孔信息中选择*,其中地层=”+lay+”;
command=newsqlitecommand(sqlQuery,m_dbConnection);
dA=新的SQLiteDataAdapter(命令);
dA.填充(数据集);
if(dSet.Tables[0].Rows.Count==0)
{
打破
}
质构性结核;
开关(铺设)
{
案例“填充”:
tb=新的TextureBrush(Properties.Resources.Fill);
打破
“冲积层”案例:
tb=新纹理树丛(Properties.Resources.Alluvium);
打破
案例“风化土壤”:
tb=新的TextureBrush(Properties.Resources.WSoil);
打破
“风化岩石”案例:
tb=新的TextureBrush(Properties.Resources.WRock);
打破
“软岩”案例:
tb=新的TextureBrush(Properties.Resources.SRock);
打破
“中等岩石”案例:
tb=新的TextureBrush(Properties.Resources.WRock);
打破
违约:
tb=新的TextureBrush(Properties.Resources.SRock);
打破
}
layerEndPos=绘图图(数据集、tb、twentyPerc、最大空间、onePtYSpace、英尺、BHU计数、layerEndPos);
}
m_dbConnection.Close();
}
捕获(例外情况除外)
{MessageBox.Show(例如Message);}
问题似乎出现在各个层的多边形的点集合中。如何更新代码以获得准确的结果