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

相关推荐
yngsqq1 小时前
cad c#二次开发 图层封装 获取当前层
java·数据库·c#
测试界1 小时前
部署Web UI自动化测试平台:SeleniumFlaskTester
windows·selenium·flask
智者知已应修善业3 小时前
【51单片机6位数码管密码锁】2022-10-15
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
呉師傅4 小时前
奔图P2500NW打印机手机无线连接方法
运维·网络·windows·智能手机·计算机外设·电脑
lixy5795 小时前
wpf 动态转圈等待提示框
c#·wpf
南無忘码至尊5 小时前
Unity编辑器工具:一键为场景中所有MeshRenderer对象添加指定脚本
unity·c#·游戏引擎·游戏开发
Cx330❀5 小时前
【数据结构初阶】--单链表(二)
数据结构·经验分享·算法·leetcode
海绵宝宝汉堡包5 小时前
未给任务“Fody.WeavingTask”的必需参数“IntermediateDir”赋值。 WpfTreeView
c#
枯萎穿心攻击6 小时前
算法入门第一篇:算法核心:复杂度分析与数组基础
算法·unity·矩阵·c#·游戏引擎