/// <summary> /// 删除选中的数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void deleteBtn_Click(object sender, EventArgs e) { if (!MainForm.IfStep1) { if (bPointList.SelectedItems.Count == 0) { MessageBox.Show("未选中任何项!"); return; } List <AdminPolygon> polygons = MainForm.Polygons; AdminPolygon polygon = null; for (int i = 0; i < polygons.Count; i++) { if (comboBox1.Text.Equals(polygons[i].Code)) { polygon = polygons[i]; } } if (polygon != null) { for (int i = 0; i < bPointList.SelectedItems.Count; i++) { int index = int.Parse(bPointList.SelectedItems[i].Text); polygon.BPoints.RemoveAt(index - 1); } UpdateBoundaryList(); } } else { MessageBox.Show("开始计算后请不要修改数据!若要更改数据,请重新导入数据或新建数据!"); } }
/// <summary> /// 提交数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void admitBtn_Click(object sender, EventArgs e) { if (!MainForm.IfStep1) { List <AdminPolygon> polygons = MainForm.Polygons; bool found = false; bool ifParse = Regex.IsMatch(textX.Text, @"^[+-]?\d*[.]?\d*$"); bool ifParse2 = Regex.IsMatch(textY.Text, @"^[+-]?\d*[.]?\d*$"); if (ifParse && ifParse2 && !textX.Text.Equals("") && !textY.Text.Equals("")) { for (int i = 0; i < polygons.Count; i++) { if (comboBox2.Text.Equals(polygons[i].Code)) { polygons[i].BPoints.Add(new BPoint(double.Parse(textX.Text), double.Parse(textY.Text), 0)); polygons[i].BPoints2.Add(new BPoint(double.Parse(textX.Text), double.Parse(textY.Text), 0)); found = true; } } if (!found) { AdminPolygon polygon = new AdminPolygon(comboBox2.Text); polygon.BPoints.Add(new BPoint(double.Parse(textX.Text), double.Parse(textY.Text), 0)); polygon.BPoints2.Add(new BPoint(double.Parse(textX.Text), double.Parse(textY.Text), 0)); polygons.Add(polygon); UpdateCBB(); } UpdateBoundaryList(); } else { MessageBox.Show("请输入正确格式的坐标数据!"); } } else { MessageBox.Show("开始计算后请不要修改数据!若要更改数据,请重新导入数据或新建数据!"); } }
/// <summary> /// 绘制大地坐标系下的示意图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void geoPic_Paint(object sender, PaintEventArgs e) { double height = geoPic.Height; double width = geoPic.Width; if (MainForm.canPaintGeo) { Graphics graphics = e.Graphics; double maxX = 0; double maxY = 0; double minX = double.MaxValue; double minY = double.MaxValue; AdminPolygon polygon = null; for (int i = 0; i < MainForm.Polygons.Count; i++) { polygon = MainForm.Polygons[i]; if (polygon.BPoints2.Count == 0) { continue; } if (polygon.BPoints2.Max(x => x.L) + 0.0002 > maxX) { maxX = polygon.BPoints2.Max(x => x.L) + 0.0002; } if (polygon.BPoints2.Max(x => x.B) + 0.0002 > maxY) { maxY = polygon.BPoints2.Max(x => x.B) + 0.0002; } if (polygon.BPoints2.Min(x => x.L) - 0.0002 < minX) { minX = polygon.BPoints2.Min(x => x.L) - 0.0002; } if (polygon.BPoints2.Min(x => x.B) - 0.0002 < minY) { minY = polygon.BPoints2.Min(x => x.B) - 0.0002; } } double scaleX = (width - 50) / (maxX - minX); double scaleY = (height - 50) / (maxY - minY); double latdiffer = 0, londiffer = 0; Tool.SetLatAndLonDif(MainForm.MeaScale, ref latdiffer, ref londiffer); latdiffer = latdiffer * Math.PI / 180; londiffer = londiffer * Math.PI / 180; for (double i = Math.Ceiling(minX / latdiffer) * latdiffer; i < maxX; i = i + londiffer) { double x1 = (i - minX) * scaleX + 25; double y1 = height - (maxY - minY) * scaleY - 25; graphics.DrawLine(Pens.Yellow, (float)x1, (float)y1, (float)x1, (float)(height - 25)); geoLines.Add(new Line(x1, y1, x1, height - 25)); } for (double i = Math.Ceiling(minY / londiffer) * londiffer; i < maxY; i = i + latdiffer) { double x1 = (maxX - minX) * scaleX + 25; double y1 = height - (i - minY) * scaleY - 25; graphics.DrawLine(Pens.Yellow, (float)x1, (float)y1, (float)25, (float)y1); geoLines.Add(new Line(x1, y1, 25, y1)); } for (int i = 0; i < MainForm.Polygons.Count; i++) { Pen pen; Brush brush; pen = Pens.Blue; brush = Brushes.Blue; polygon = MainForm.Polygons[i]; if (i == 0 && polygon.MapSheet.WSPoint1 != null) { double x = (polygon.MapSheet.WSPoint1.L - minX) * scaleX + 25; double y = height - (polygon.MapSheet.WSPoint1.B - minY) * scaleY - 25; gaussPoints.Add(new Point(x, y)); double x2 = (polygon.MapSheet.WSPoint1.L + londiffer - minX) * scaleX + 25; double y2 = height - (polygon.MapSheet.WSPoint1.B - minY) * scaleY - 25; gaussPoints.Add(new Point(x2, y2)); double x3 = (polygon.MapSheet.ENPoint1.L - minX) * scaleX + 25; double y3 = height - (polygon.MapSheet.ENPoint1.B - minY) * scaleY - 25; gaussPoints.Add(new Point(x3, y3)); double x4 = (polygon.MapSheet.WSPoint1.L - minX) * scaleX + 25; double y4 = height - (polygon.MapSheet.WSPoint1.B + latdiffer - minY) * scaleY - 25; gaussPoints.Add(new Point(x4, y4)); graphics.DrawLines(Pens.DarkMagenta, new PointF[5] { new PointF((float)x, (float)y), new PointF((float)x2, (float)y2), new PointF((float)x3, (float)y3), new PointF((float)x4, (float)y4), new PointF((float)x, (float)y) }); } if (polygon.BPoints2.Count == 0) { continue; } for (int j = 0; j < polygon.BPoints2.Count; j++) { double x = (polygon.BPoints2[j].L - minX) * scaleX + 25; double y = height - (polygon.BPoints2[j].B - minY) * scaleY - 25; gaussPoints.Add(new Point(x, y)); graphics.DrawEllipse(pen, (float)(x - 0.5), (float)(y - 0.5), 1, 1); if (j != polygon.BPoints2.Count - 1) { double x1 = (polygon.BPoints2[j + 1].L - minX) * scaleX + 25; double y1 = height - (polygon.BPoints2[j + 1].B - minY) * scaleY - 25; graphics.DrawLine(pen, (float)x, (float)y, (float)x1, (float)y1); geoLines.Add(new Line(x, y, x1, y1)); } } double x5 = (polygon.BPoints2.Average(x => x.L) - minX) * scaleX + 25; double y5 = height - (polygon.BPoints2.Average(x => x.B) - minY) * scaleY - 25; graphics.DrawString(polygon.Code, new Font("宋体", 10), brush, (float)(x5 - 10), (float)y5); geoMemos.Add(new Memo(polygon.Code, x5, y5)); } graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)25, (float)height - 25); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)25, (float)height - 25); graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)20, (float)30); graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)30, (float)30); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)width - 35, (float)height - 20); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)width - 35, (float)height - 30); graphics.DrawString((minY).ToString("F4"), new Font("宋体", 10), Brushes.Black, (float)5, (float)height - 40); graphics.DrawString((maxX).ToString("F4"), new Font("宋体", 10), Brushes.Black, (float)width - 45, (float)height - 17); graphics.DrawString((minX).ToString("F4"), new Font("宋体", 10), Brushes.Black, (float)25, (float)height - 17); graphics.DrawString((maxY).ToString("F4"), new Font("宋体", 10), Brushes.Black, (float)5, (float)15); } }
/* * private double getMinX(List<BPoint> points) * { * double minX = double.MaxValue; * for (int i = 0; i < points.Count; i++) * { * if (points[i].Y < minX && points[i].Y != 0) * { * minX = points[i].Y; * } * } * return minX; * } * private double getMinY(List<BPoint> points) * { * double minY = double.MaxValue; * for (int i = 0; i < points.Count; i++) * { * if (points[i].X < minY && points[i].X != 0) * { * minY = points[i].X; * } * } * return minY; * }*/ /* * private void deleteZero(List<BPoint> points) * { * for (int i = 0; i < points.Count; i++) * { * if (points[i].X == 0 || points[i].Y == 0) * { * points.RemoveAt(i); * i--; * } * } * } * */ /// <summary> /// 绘制高斯坐标系下的示意图 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gaussPic_Paint(object sender, PaintEventArgs e) { double height = gaussPic.Height; double width = gaussPic.Width; if (MainForm.canPaintGauss) { Graphics graphics = e.Graphics; double maxX = 0; double maxY = 0; double minX = double.MaxValue; double minY = double.MaxValue; AdminPolygon polygon = null; for (int i = 0; i < MainForm.Polygons.Count; i++) { polygon = MainForm.Polygons[i]; if (polygon.BPoints2.Count == 0) { continue; } if (polygon.BPoints2.Max(x => x.Y) + 800 > maxX) { maxX = polygon.BPoints2.Max(x => x.Y) + 800; } if (polygon.BPoints2.Max(x => x.X) + 800 > maxY) { maxY = polygon.BPoints2.Max(x => x.X) + 800; } if (polygon.BPoints2.Min(x => x.Y) - 800 < minX) { minX = polygon.BPoints2.Min(x => x.Y) - 800; } if (polygon.BPoints2.Min(x => x.X) - 800 < minY) { minY = polygon.BPoints2.Min(x => x.X) - 800; } } double scaleX = (width - 50) / (maxX - minX); double scaleY = (height - 50) / (maxY - minY); for (int i = 0; i < MainForm.Polygons.Count; i++) { Pen pen; Brush brush; pen = Pens.Blue; brush = Brushes.Blue; polygon = MainForm.Polygons[i]; if (polygon.BPoints2.Count == 0) { continue; } for (int j = 0; j < polygon.BPoints2.Count; j++) { double x = (polygon.BPoints2[j].Y - minX) * scaleX + 25; double y = height - (polygon.BPoints2[j].X - minY) * scaleY - 25; gaussPoints.Add(new Point(x, y)); graphics.DrawEllipse(pen, (float)(x - 0.5), (float)(y - 0.5), 1, 1); if (j != polygon.BPoints2.Count - 1) { double x1 = (polygon.BPoints2[j + 1].Y - minX) * scaleX + 25; double y1 = height - (polygon.BPoints2[j + 1].X - minY) * scaleY - 25; graphics.DrawLine(pen, (float)x, (float)y, (float)x1, (float)y1); gaussLines.Add(new Line(x, y, x1, y1)); } } double x2 = (polygon.BPoints2.Average(x => x.Y) - minX) * scaleX + 25; double y2 = height - (polygon.BPoints2.Average(x => x.X) - minY) * scaleY - 25; graphics.DrawString(polygon.Code, new Font("宋体", 10), brush, (float)(x2 - 10), (float)y2); gaussMemos.Add(new Memo(polygon.Code, x2, y2)); } graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)25, (float)height - 25); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)25, (float)height - 25); graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)20, (float)30); graphics.DrawLine(Pens.Black, (float)25, (float)25, (float)30, (float)30); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)width - 35, (float)height - 20); graphics.DrawLine(Pens.Black, (float)width - 25, (float)height - 25, (float)width - 35, (float)height - 30); graphics.DrawString(((int)minY).ToString(), new Font("宋体", 10), Brushes.Black, (float)5, (float)height - 40); graphics.DrawString(((int)maxX).ToString(), new Font("宋体", 10), Brushes.Black, (float)width - 45, (float)height - 17); graphics.DrawString(((int)minX).ToString(), new Font("宋体", 10), Brushes.Black, (float)25, (float)height - 17); graphics.DrawString(((int)maxY).ToString(), new Font("宋体", 10), Brushes.Black, (float)5, (float)15); } }