private void button2_Click(object sender, EventArgs e) { try { foreach (var line in MyGlo.llist) { if (line.ID[1] != '2' && line.ID[1] != '4') { DouglasPeuker.after.Add(line.CoorList[0]); DouglasPeuker.DP(0, line.CoorList.Count(), (float)Convert.ToDouble(this.textBox1.Text), line.CoorList); line.CoorList.Clear(); //速度太慢,是否有更快的DEEP COPE方法 foreach (var pt in DouglasPeuker.after) { line.CoorList.Add(pt); } DouglasPeuker.after.Clear(); } } this.Owner.Refresh(); } catch (Exception) { MessageBox.Show("输入错误"); } }
public static object choice(int x, int y, int width, int height) {//是否被选中 foreach (var rpt in MyGlo.rplist) { Point temp_p = Funcs.CoorTransform(rpt.Map_X, rpt.Map_Y, width, height); if (Math.Pow(x - temp_p.X, 2) + Math.Pow(y - temp_p.Y, 2) <= 25) { return(rpt); } } foreach (var npt in MyGlo.nplist) { Point temp_p = CoorTransform(npt.Map_X, npt.Map_Y, width, height); if (Math.Pow(x - temp_p.X, 2) + Math.Pow(y - temp_p.Y, 2) <= 25) { return(npt); } } foreach (var line in MyGlo.llist) { for (int i = 0; i < line.CoorList.Count - 1; i++) { Point p1 = CoorTransform(line.CoorList[i].Map_X, line.CoorList[i].Map_Y, width, height); Point p2 = CoorTransform(line.CoorList[i + 1].Map_X, line.CoorList[i + 1].Map_Y, width, height); if ((x <= p1.X + 6 && x >= p2.X - 6 && y <= p1.Y + 6 && y >= p2.Y - 6) || (x >= p1.X - 6 && x <= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6) || (x >= p1.X + 6 && x <= p2.X - 6 && y >= p2.Y + 6 && y <= p1.Y - 6) || (x <= p1.X - 6 && x >= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6)) { float dis = DouglasPeuker.Distance(x, y, p1.X, p1.Y, p2.X, p2.Y); if (dis <= 5) { return(line); } } } if (line.ID[1] == '3') { Point p1 = CoorTransform(line.CoorList[0].Map_X, line.CoorList[0].Map_Y, width, height); Point p2 = CoorTransform(line.CoorList[line.CoorList.Count - 1].Map_X, line.CoorList[line.CoorList.Count - 1].Map_Y, width, height); if ((x <= p1.X + 6 && x >= p2.X - 6 && y <= p1.Y + 6 && y >= p2.Y - 6) || (x >= p1.X - 6 && x <= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6) || (x >= p1.X + 6 && x <= p2.X - 6 && y >= p2.Y + 6 && y <= p1.Y - 6) || (x <= p1.X - 6 && x >= p2.X + 6 && y <= p2.Y - 6 && y >= p1.Y + 6)) { float dis = DouglasPeuker.Distance(x, y, p1.X, p1.Y, p2.X, p2.Y); if (dis <= 5) { return(line); } } } } return(null); }
private void button2_Click(object sender, EventArgs e) { foreach (var line in MyGlo.llist) { DouglasPeuker.after.Add(line.CoorList[0]); DouglasPeuker.DP(0, line.CoorList.Count(), (float)Convert.ToDouble(this.textBox1.Text), line.CoorList); line.CoorList.Clear(); //速度太慢,是否有更快的DEEP COPE方法 foreach (var pt in DouglasPeuker.after) { line.CoorList.Add(pt); } DouglasPeuker.after.Clear(); } this.Owner.Refresh(); }
public static void Rdx(object o, object pictureBox1, Point p2) {//点与线关系判断 object obj = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); if ((obj is Lineshape) && (obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '1') { List <float> temp = new List <float>(); for (int i = 0; i < (obj as Lineshape).CoorList.Count() - 1; i++) { if (((o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i + 1].Map_Y) || ((o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i].Map_Y) || ((o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i].Map_Y) || ((o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i].Map_Y)) {//是否在最小外接矩形内 temp.Add(DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i].Map_X, (obj as Lineshape).CoorList[i].Map_Y, (obj as Lineshape).CoorList[i + 1].Map_X, (obj as Lineshape).CoorList[i + 1].Map_Y)); } else {//求最短距离 temp.Add(Math.Min(DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i].Map_X, (obj as Lineshape).CoorList[i].Map_Y), DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i + 1].Map_X, (obj as Lineshape).CoorList[i + 1].Map_Y))); } } if (temp.ToArray().Min() == 0) { MessageBox.Show("在直线上", "关系显示:"); } else { MessageBox.Show("相离,二者间的最小距离为:" + temp.ToArray().Min(), "关系显示:"); } } else {//不是所要的目标 MessageBox.Show("请先选择一个实体点或注记点,然后选择一条直线段", "提示"); } }
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("只能判断实体点和注记点的关系", "关系显示:"); } } }