| | |
| | | package dikuai; |
| | | |
| | | import javax.swing.*; |
| | | import java.awt.*; |
| | | import java.awt.event.*; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import bianjie.bianjieguihua2; |
| | | import bianjie.Bianjieyouhuatoxy; |
| | | import publicway.Fuzhibutton; |
| | | import zhuye.Coordinate; |
| | | import zhuye.Shouye; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 地块边界管理页面 |
| | | * 边界管理页面 |
| | | * 显示:原始边界坐标(经纬度、高程)、原始边界XY(相对于基准站)、以及可编辑的优化后边界坐标 |
| | | */ |
| | | public class Dikuanbianjipage extends JDialog { |
| | |
| | | return; |
| | | } |
| | | |
| | | // 从原始边界XY坐标文本域获取输入 |
| | | String inputXY = rawXYArea.getText(); |
| | | if (inputXY == null || inputXY.trim().isEmpty() || "-1".equals(inputXY.trim())) { |
| | | JOptionPane.showMessageDialog(this, "原始边界XY坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | // 获取基准站坐标作为原点 |
| | | String originStr = dikuai.getBaseStationCoordinates(); |
| | | if (originStr == null || originStr.trim().isEmpty() || "-1".equals(originStr.trim())) { |
| | | JOptionPane.showMessageDialog(this, "基准站坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | // 获取原始边界坐标 |
| | | String boundaryStr = dikuai.getBoundaryOriginalCoordinates(); |
| | | if (boundaryStr == null || boundaryStr.trim().isEmpty() || "-1".equals(boundaryStr.trim())) { |
| | | JOptionPane.showMessageDialog(this, "原始边界坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 调用优化算法(直接使用XY坐标字符串) |
| | | String optimized = bianjieguihua2.optimizeBoundaryXYString(inputXY.trim()); |
| | | // 调用Bianjieyouhuatoxy的optimizeBoundary方法 |
| | | // boundaryStr格式:纬度(度分),纬度方向,经度(度分),经度方向,高程;... |
| | | // 需要转换为optimizeBoundary期望的格式:lat(度分),lon(度分);... |
| | | String convertedBoundaryStr = convertBoundaryFormat(boundaryStr.trim()); |
| | | String optimized = Bianjieyouhuatoxy.optimizeBoundary(originStr.trim(), convertedBoundaryStr); |
| | | |
| | | // 检查是否有错误 |
| | | if (optimized != null && optimized.startsWith("ERROR:")) { |
| | | JOptionPane.showMessageDialog(this, "优化失败: " + optimized.substring(6), "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | optTextArea.setText(optimized); |
| | | JOptionPane.showMessageDialog(this, "边界优化完成", "提示", JOptionPane.INFORMATION_MESSAGE); |
| | | } catch (Exception ex) { |
| | |
| | | double degreeMinutes = degrees * 100.0 + minutes; |
| | | return String.format(java.util.Locale.US, "%.8f", degreeMinutes); |
| | | } |
| | | |
| | | /** |
| | | * 将boundaryOriginalCoordinates格式转换为optimizeBoundary期望的格式 |
| | | * 输入格式:纬度(度分),纬度方向,经度(度分),经度方向,高程;... |
| | | * 输出格式:纬度(度分),经度(度分);... |
| | | * |
| | | * @param boundaryOriginalCoordinates 原始边界坐标字符串 |
| | | * @return 转换后的格式字符串 |
| | | */ |
| | | private String convertBoundaryFormat(String boundaryOriginalCoordinates) { |
| | | if (boundaryOriginalCoordinates == null || boundaryOriginalCoordinates.trim().isEmpty() || "-1".equals(boundaryOriginalCoordinates.trim())) { |
| | | return ""; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | String[] points = boundaryOriginalCoordinates.split(";"); |
| | | |
| | | for (String point : points) { |
| | | if (point == null || point.trim().isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | String[] parts = point.trim().split("[,,]"); |
| | | // 格式:纬度(度分),纬度方向,经度(度分),经度方向,高程 |
| | | // 至少需要4个字段(纬度、方向、经度、方向),高程是可选的 |
| | | if (parts.length >= 4) { |
| | | String lat = parts[0].trim(); |
| | | String lon = parts[2].trim(); |
| | | |
| | | if (sb.length() > 0) { |
| | | sb.append(";"); |
| | | } |
| | | sb.append(lat).append(",").append(lon); |
| | | } |
| | | } |
| | | |
| | | return sb.toString(); |
| | | } |
| | | } |