2025年测绘程序设计模拟赛一--地形图图幅编号及图廓点经纬度计算

想要在2026年参加这个比赛的,可以加入小编和其它大佬所建的群242845175一起来备赛,为2026年的比赛打基础,也可以私信小编,为你答疑解惑

一、读取文件

这里有两种文件需要读取,所以要额外处理

csharp 复制代码
internal class Read
{
    public static List<Point> Points = new List<Point>();
    public static List<Point> BLdms = new List<Point>();
    public static List<Point> Newmap = new List<Point>();
    public static List<Point> ReadfileBL(string filename)
    {
        string str;
        StreamReader sr = new StreamReader(filename);
        while(!sr.EndOfStream)
        {
            str = sr.ReadLine();
            string[]Buf= str.Split(new char[] { ',', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Point pt=new Point(Buf[0], double.Parse(Buf[1]), double.Parse(Buf[2]));
            Points.Add(pt);
            BLdms.Add(pt);
        }
        return Points;
    }

    public static List<Point> ReadfileNewmap(string filename)
    {
        string str;
        StreamReader sr = new StreamReader(filename);
        while (!sr.EndOfStream)
        {
            str = sr.ReadLine();
            string[] Buf = str.Split(new char[] { ',', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            Point pt = new Point(int.Parse(Buf[0]), Buf[1]);
            Points.Add(pt);
            Newmap.Add(pt);
        }
        return Points;
    }
}

二、度与dms之间的转化

csharp 复制代码
public static double dL_100w = dms_rad(6);
public static double dB_100w = dms_rad(4);
public static double dL_50w=dms_rad(3);
public static double dB_50w=dms_rad(2);
public static double dL_25w = dms_rad(1.30);
public static double dB_25w = dms_rad(1);
public static double dL_10w = dms_rad(0.30);
public static double dB_10w = dms_rad(0.20);
public static double dL_5w = dms_rad(0.15);
public static double dB_5w = dms_rad(0.10);
public static double dL_2d5w = dms_rad(0.073);
public static double dB_2d5w = dms_rad(0.05);
public static double dL_1w = dms_rad(0.0345);
public static double dB_1w = dms_rad(0.0230);
public static double dL_5k = dms_rad(0.01525);
public static double dB_5k = dms_rad(0.0115);
public static double dL_2k = dms_rad(0.00375);
public static double dB_2k = dms_rad(0.0025);
public static double dL_1k = dms_rad(0.001875);
public static double dB_1k = dms_rad(0.00125);
public static double dL_5b = dms_rad(0.0009375);
public static double dB_5b = dms_rad(0.000625);

//dms转化为度进制
public static double dms_rad(double dms)
{
    int a = (int)dms;
    double b = (int)((dms - a) * 100) * 60;
    double c = ((int)(dms * 10000 % 100) + b) / 3600;

    return (a+c);

}
//十进制转化为dms
public static double rad_dms(double rad)
{
    
    double d = (int)rad;
    double m = (int)((rad - d) * 60);
    double s = ((rad - d) * 60 - m) * 60;
    double dms = d + m / 100 + s / 10000;
    if (s >= 59.999)//出现了 115度30分60秒的结果错误
    {
        dms = dms - 0.0060 + 0.01;
        if (m + 1 >= 59.999)
        {
            dms = dms + 1 - 0.60;
        }
    }
    return dms;
}

三、经纬度转化为新版图幅

csharp 复制代码
 public static void avg()
 {
     double sumb = 0;
     double suml = 0;
     for (int i = 0; i < Read.BLdms.Count; i++)
     {
         
         sumb += Read.BLdms[i].B_dms;
         suml += Read.BLdms[i].L_dms;
     }
     Point avgpt = new Point("avg", sumb / Read.BLdms.Count, suml / Read.BLdms.Count);
     Read.BLdms.Add(avgpt);
 }

 public static void Selectnumber(double scale,out double dertaB,out double dertaL,out string sc)
 {
     dertaB = 0;
     dertaL = 0;
     sc = null;
     switch (scale)
     {
         case 1000000:
             dertaB = dB_100w;
             dertaL=dL_100w;
             sc = "A";
             break;
         case 500000:
             dertaB = dB_50w;
             dertaL=dL_50w;
             sc = "B";
             break;
         case 250000:
             dertaB = dB_25w;
             dertaL=dL_25w;
             sc = "C";
             break;
         case 100000:
             dertaB = dB_10w;
             dertaL=dL_10w;
             sc = "D";
             break;
         case 50000:
             dertaB = dB_5w;
             dertaL=dL_5w;
             sc = "E";
             break;
         case 25000:
             dertaB = dB_2d5w;
             dertaL=dL_2d5w;
             sc = "F";
             break;
         case 10000:
             dertaB = dB_1w;
             dertaL=dL_1w;
             sc = "G";
             break;
         case 5000:
             dertaB = dB_5k;
             dertaL = dL_5k;
             sc = "H";
             break;

         case 2000:
             dertaB = dB_2k;
             dertaL=dL_2k;
             sc = "I";
             break;
         case 1000:
             dertaB = dB_1k;
             dertaL=dL_1k;
             sc = "J";
             break;
         case 500:
             dertaB = dB_5b;
             dertaL=dL_5b;
             sc = "K";
             break;
     }

 }
 //把经纬度转化为新版图幅
 public static void Bl_newmap(Point point)
 {
     Selectnumber(point.scale, out double dertaB, out double dertaL,out string sc);
     int a = (int)(point.B_rad / 4) + 1;
     char c = (char)(a - 'A' + 1);
     int b = (int)(point.L_rad / 6) + 31;


     int m = (int)((point.L_rad % 6)/dertaL)+1;
     string e = m.ToString();

     string f = null;
     string h = null;

     int n =(int) (4/dertaB)-(int)((point.B_rad % 4)/dertaB);
     string g=n.ToString();
     if (point.scale == 1000 || point.scale == 500)
     {
          f = e.PadLeft(4, '0');
          h = g.PadLeft(4, '0');
     }
     else
     {
          f = e.PadLeft(3, '0');
          h = g.PadLeft(3, '0');
     }

     point.newmap=a.ToString()+b.ToString()+sc.ToString()+h.ToString()+f.ToString(); 

 }

四、新版图幅转化为西南角经纬度

csharp 复制代码
public static void Selectid(string id, out double dertaB, out double dertaL, out double scale)
{
    dertaB = 0;
    dertaL = 0;
    scale = 0;
    switch (id)
    {
        case "A":
            dertaB = dB_100w;
            dertaL = dL_100w;
            scale = 1000000;
            break;
        case "B":
            dertaB = dB_50w;
            dertaL = dL_50w;
            scale = 500000;
            break;
        case "C":
            dertaB = dB_25w;
            dertaL = dL_25w;
            scale = 250000;
            break;
        case "D":
            dertaB = dB_10w;
            dertaL = dL_10w;
            scale = 10000;
            break;
        case "E":
            dertaB = dB_5w;
            dertaL = dL_5w;
            scale=50000;
            break;
        case "F":
            dertaB = dB_2d5w;
            dertaL = dL_2d5w;
            scale = 25000;
            break;
        case "G":
            dertaB = dB_1w;
            dertaL = dL_1w;
            scale = 10000;
            break;
        case "H":
            dertaB = dB_5k;
            dertaL = dL_5k;
            scale = 5000;
            break;

        case "I":
            dertaB = dB_2k;
            dertaL = dL_2k;
            scale = 2000;
            break;
        case "J":
            dertaB = dB_1k;
            dertaL = dL_1k;
            scale = 1000;
            break;
        case "K":
            dertaB = dB_5b;
            dertaL = dL_5b;
            scale = 500;
            break;
    }

}

public static void Nmap_bl(Point point)
{
    string nem = point.newmap;
    int line_100 = (int)(nem[0] - 'A' + 1);
    int up_100=int.Parse(nem.Substring(1,2));
    point.lin_100=line_100;
    point.u_100=up_100;
    point. B_100=(line_100-1) * 4;
    point. L_100 = (up_100 - 31) * 6;
    string c = nem[3].ToString();
    Selectid(c, out double dertaB, out double dertaL, out double scale);
    point.scale = scale;
    int n=(int)(4/dertaB);
    double cc = 0;
    double d = 0;
    if (point.scale == 1000 || point.scale == 500)
    {
        cc=int.Parse(nem.Substring(4,4));
        d=int.Parse(nem.Substring(8, 4));
    }
    else
    {
        cc = int.Parse(nem.Substring(4, 3));
        d = int.Parse(nem.Substring(7, 3));
    }
    
    point.leftdownB=point.B_100+dertaB*(n-cc);
    point.leftdownL = point.L_100 + dertaL * (d - 1);

    point.rightdownB = point.leftdownB;
    point.rightdownL = point.leftdownL + dertaL;

    point.leftupB = point.leftdownB + dertaB;
    point.leftupL = point.leftdownL;

    point.rightupL = point.leftdownL + dertaL;
    point.rightupB=point.leftdownB + dertaB;
}

五、事件交互

csharp 复制代码
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        openFile.FileOk += openFile_FileOk;
    }
    public static List<Point> bBLdms= new List<Point>();
    public static List<Point> bNewmap= new List<Point>();
    public string report = null;
    

    private void openFile_FileOk(object sender, CancelEventArgs e)
    {

    }

    private void toolStripLabel1_Click(object sender, EventArgs e)
    {
        if(openFile.ShowDialog() == DialogResult.OK)
        {
            string file=openFile.FileName;
            Read.ReadfileBL(file);
            bBLdms=Read.BLdms;
            dataGridView1.RowCount = bBLdms.Count;
            for(int i=0;i<bBLdms.Count;i++) 
            {
                dataGridView1[0, i].Value = bBLdms[i].name;
                dataGridView1[2, i].Value = bBLdms[i].B_dms;
                dataGridView1[3, i].Value = bBLdms[i].L_dms;
            }

        }
    }

    private void toolStripLabel2_Click(object sender, EventArgs e)
    {
        if (openFile.ShowDialog() == DialogResult.OK)
        {
            string file = openFile.FileName;
            Read.ReadfileNewmap(file);
            bNewmap = Read.Newmap;
            dataGridView2.RowCount = bNewmap.Count;
            for (int i = 0; i < bNewmap.Count; i++)
            {
                dataGridView2[1, i].Value = bNewmap[i].ID;
                dataGridView2[4, i].Value = bNewmap[i].newmap;
                
            }

        }
    }

    private void toolStripLabel3_Click(object sender, EventArgs e)
    {
        Alth.avg();
        report +=  Read.BLdms[0].L_dms.ToString("F5")+"\n";
        report += Read.BLdms[2].B_dms.ToString("F5")+"\n";
        report += Read.BLdms[2].L_rad.ToString("F6")+"\n";
        report += Read.BLdms[2].B_rad.ToString("F6") + "\n";
        report += Alth.rad_dms(Read.BLdms[3].B_rad).ToString("F6") + "\n";
        report += Alth.rad_dms(Read.BLdms[3].L_rad).ToString("F6") + "\n";
        report += Read.BLdms[3].B_rad.ToString("F6") + "\n";
        report += Read.BLdms[3].L_rad.ToString("F6") + "\n";
        Read.BLdms[3].scale = 250000;
        Alth.Bl_newmap(Read.BLdms[3]);
        report += Read.BLdms[3].newmap.Substring(4, 3)+"\n";
        report += Read.BLdms[3].newmap.Substring(7, 3)+"\n";
        Read.BLdms[3].scale = 500;
        Alth.Bl_newmap(Read.BLdms[3]);
        report += Read.BLdms[3].newmap.Substring(4, 4) + "\n";
        report += Read.BLdms[3].newmap.Substring(8, 4) + "\n";
        richTextBox1.Text = report;

    }

    private void toolStripLabel5_Click(object sender, EventArgs e)
    {
        Alth.Nmap_bl(Read.Newmap[0]);
        report += Read.Newmap[0].lin_100 + "\n";
        report += Read.Newmap[0].u_100 + "\n";
        Alth.Nmap_bl(Read.Newmap[1]);
        report += Read.Newmap[1].lin_100 + "\n";
        report += Read.Newmap[1].u_100 + "\n";

        report += Read.Newmap[0].scale + "\n";
        report += Read.Newmap[1].scale + "\n";

        report += Alth.rad_dms(Read.Newmap[0].leftdownL).ToString("F5")+ "\n";
        report += Alth.rad_dms(Read.Newmap[0].leftdownB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[1].leftdownL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[1].leftdownB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[0].rightdownL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[0].rightdownB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[0].rightupL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[0].rightupB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[0].leftupL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[0].leftupB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[1].rightdownL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[1].rightdownB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[1].rightupL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[1].rightupB).ToString("F5") + "\n";

        report += Alth.rad_dms(Read.Newmap[1].leftupL).ToString("F5") + "\n";
        report += Alth.rad_dms(Read.Newmap[1].leftupB).ToString("F5") + "\n";
        richTextBox1.Text = report;
    }

    private void toolStripLabel4_Click(object sender, EventArgs e)
    {
        SaveFileDialog sf = new SaveFileDialog();
        sf.Filter = "文本数据|*.txt";
        sf.Title = "选择保存路径";
        sf.FileName = "result";
        if(sf.ShowDialog() == DialogResult.OK)
        {
            StreamWriter sw = new StreamWriter(sf.FileName);
            sw.Write(report);
            sw.Flush();
        }
    }
}

六、页面布局

七、结果

114.12353

35.30250

116.483333

35.506944

34.103300

116.022600

34.175833

116.040556

002

002

1095

0817

10

50

9

50

50000

10000

116.00000

39.50000

119.52300

32.40000

116.15000

39.50000

116.15000

40.00000

116.00000

40.00000

119.56150

32.40000

119.56150

32.42300

119.52300

32.42300

相关推荐
唐兴通个人2 分钟前
人工智能社会学数字社会学网络社会学讲授学者专家培训老师讲我们清华.....
经验分享
CodeCraft Studio6 小时前
PPT处理控件Aspose.Slides教程:在 C# 中将 PPTX 转换为 Markdown
开发语言·c#·powerpoint·markdown·ppt·aspose·ai大模型
IT90909 小时前
C#软件授权注册码模块源码及机器码注册码功能
c#·软件开发
M_Reus_1112 小时前
Groovy集合常用简洁语法
java·开发语言·windows
慕斯-ing13 小时前
SDK、JDK、JRE、JVM的区别
jvm·经验分享·jdk·sdk·jre
暴走十八步14 小时前
配置windows下apache+PHP环境
windows·php·apache
Pafey15 小时前
【Deepseek】Windows MFC/Win32 常用核心 API 汇总
c++·windows·mfc
YIN_尹17 小时前
零基础开发应用:cpolar+Appsmith平民化方案
经验分享
WAZYY061919 小时前
C#实现PDF合并、裁剪功能
开发语言·pdf·c#·pdf合并·pdf工具·pdf切割
开开心心就好20 小时前
文档格式转换软件 一键Word转PDF
开发语言·前端·数据库·pdf·c#·word