}//DataType方法,判断导入数据类型 public static void Importfile(StreamReader f, Graphics g, int Height, int Width) { while (f.Peek() > -1) //判断文件有没有读取完 { string tmp = f.ReadLine(); //读取第一行信息 switch (Funcs.DataType(tmp)) //根据数据类型绘制 { case 1: //为实体点 { string temp = f.ReadLine(); //再读一行字符串,判断是否为空,不为空就录入 while (temp != null && temp != ",,,") { //实例化实体点并加入实体点集 Realpoint realpoint = new Realpoint(temp); MyGlo.rplist.Add(realpoint); temp = f.ReadLine(); } //while } //case 1 break; case 2: //为注记点 { string temp = f.ReadLine(); while (temp != null && temp != ",,,") { Notepoint notepoint = new Notepoint(temp); MyGlo.nplist.Add(notepoint); temp = f.ReadLine(); } } //case 2 break; case 3: //为常规线 { string temp = f.ReadLine(); List <Basepoint> bt_temp = new List <Basepoint>(); while (temp != null && temp != ",,,") { Linkpoint linkpoint = new Linkpoint(temp); bt_temp.Add(linkpoint); temp = f.ReadLine(); } Lineshape lineshape = new Lineshape(bt_temp, tmp); //实例化线对象 MyGlo.llist.Add(lineshape); //加入列表 } //case3 break; case 4: //为弧线 { string temp = f.ReadLine(); List <Basepoint> bt_temp = new List <Basepoint>(); while (temp != null && temp != ",,,") { Linkpoint linkpoint = new Linkpoint(temp); bt_temp.Add(linkpoint); temp = f.ReadLine(); } Lineshape lineshape = new Lineshape(bt_temp, tmp); MyGlo.llist.Add(lineshape); } break; //case4 case 5: { string temp = f.ReadLine(); List <Basepoint> bt_temp = new List <Basepoint>(); while (temp != null && temp != ",,,") { Linkpoint linkpoint = new Linkpoint(temp); bt_temp.Add(linkpoint); temp = f.ReadLine(); } Lineshape lineshape = new Lineshape(bt_temp, tmp); MyGlo.llist.Add(lineshape); } break; //case5 case 6: { string temp = f.ReadLine(); List <Basepoint> bt_temp = new List <Basepoint>(); while (temp != null && temp != ",,,") { Linkpoint linkpoint = new Linkpoint(temp); bt_temp.Add(linkpoint); temp = f.ReadLine(); } Lineshape lineshape = new Lineshape(bt_temp, tmp); MyGlo.llist.Add(lineshape); } break; //case6 }//switch Funcs.Update(g, Width, Height); }//while } //importfile,导入roi
private void pictureBox1_Click(object sender, EventArgs e) { try { //距离量测 if (bool_cul == true) { if (bool_dis == true) { p = pictureBox1.PointToClient(MousePosition); bool_dis = false; } else { Point p2 = pictureBox1.PointToClient(MousePosition); object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height); if (obj == null) { float d = DouglasPeuker.Distance(p2.X, p2.Y, p.X, p.Y); MessageBox.Show("未选中目标,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else { if (obj is Realpoint) { Point temp_p; temp_p = Funcs.CoorTransform((obj as Realpoint).Map_X, (obj as Realpoint).Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y); MessageBox.Show("选中实体点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else if (obj is Notepoint) { Point temp_p; temp_p = Funcs.CoorTransform((obj as Notepoint).Map_X, (obj as Notepoint).Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y); MessageBox.Show("选中注记点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else if (obj is Lineshape) { if ((obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '1' && (obj as Lineshape).CoorList.Count == 2) { if ((p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[0].Map_Y && p.Y >= (obj as Lineshape).CoorList[1].Map_Y) || (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y) || (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X && p.Y >= (obj as Lineshape).CoorList[1].Map_Y && p.Y <= (obj as Lineshape).CoorList[0].Map_Y) || (p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y)) { Point temp_p1, temp_p2; temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height); temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y, temp_p2.X, temp_p2.Y); MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else { Point temp_p1, temp_p2; temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height); temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height); float d = Math.Min(DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y), DouglasPeuker.Distance(p.X, p.Y, temp_p2.X, temp_p2.Y)); MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } } else { MessageBox.Show("暂不支持曲线/面和多点线/面,请选择两点直线段,如果想求点到多段线的最小距离可以使用点线关系工具", "提示"); NoActive(); } } } } } //点点关系,写的看不下去,可使用basepoint简化 if (bool_dd == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdd(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择两点"); NoActive(); } } //点线关系 if (bool_dx == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdx(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择一点和一条直线"); NoActive(); } } //点面关系 if (bool_dm == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdm(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择一点和一直线面"); NoActive(); } } //删除对象 if (bool_del == true) { Point p2 = pictureBox1.PointToClient(MousePosition); object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height); Funcs.Del(obj, pictureBox1); NoActive(); this.Cursor = Cursors.Default; } //符号绘制 if (fuhao1 == true) { Graphics g = pictureBox1.CreateGraphics(); Funcs.Daoxiandian(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height); NoActive(); } if (fuhao2 == true) { Graphics g = pictureBox1.CreateGraphics(); Funcs.Jiaotang(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height); NoActive(); } } catch { MessageBox.Show("未知错误"); } }
public static void Rdd(object o, object pictureBox1, Point p2) {//点与点关系判断 object obj = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); if (o is Realpoint) { if (obj is Realpoint) { float d = DouglasPeuker.Distance((o as Realpoint).Map_X, (o as Realpoint).Map_Y, (obj as Realpoint).Map_X, (obj as Realpoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is Notepoint) { float d = DouglasPeuker.Distance((o as Realpoint).Map_X, (o as Realpoint).Map_Y, (obj as Notepoint).Map_X, (obj as Notepoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is null || obj is Lineshape) { MessageBox.Show("只能判断实体点和注记点的关系", "关系显示:"); } } else if (o is Notepoint) { if (obj is Realpoint) { float d = DouglasPeuker.Distance((o as Notepoint).Map_X, (o as Notepoint).Map_Y, (obj as Realpoint).Map_X, (obj as Realpoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is Notepoint) { float d = DouglasPeuker.Distance((o as Notepoint).Map_X, (o as Notepoint).Map_Y, (obj as Notepoint).Map_X, (obj as Notepoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is null) { MessageBox.Show("只能判断实体点和注记点的关系", "关系显示:"); } } }