| | |
| | | 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 { |
| | |
| | | JOptionPane.showMessageDialog(this, "未找到地块信息,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | String baseStation = dikuai.getBaseStationCoordinates(); |
| | | if (baseStation == null || baseStation.trim().isEmpty() || "-1".equals(baseStation)) { |
| | | JOptionPane.showMessageDialog(this, "基站坐标未设置,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | |
| | | // 获取基准站坐标作为原点 |
| | | String originStr = dikuai.getBaseStationCoordinates(); |
| | | if (originStr == null || originStr.trim().isEmpty() || "-1".equals(originStr.trim())) { |
| | | JOptionPane.showMessageDialog(this, "基准站坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | // 准备 Coordinate 列表 |
| | | String originalCoords = dikuai.getBoundaryOriginalCoordinates(); |
| | | if (originalCoords == null || originalCoords.trim().isEmpty() || "-1".equals(originalCoords)) { |
| | | // 获取原始边界坐标 |
| | | String boundaryStr = dikuai.getBoundaryOriginalCoordinates(); |
| | | if (boundaryStr == null || boundaryStr.trim().isEmpty() || "-1".equals(boundaryStr.trim())) { |
| | | JOptionPane.showMessageDialog(this, "原始边界坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 解析原始坐标到 Coordinate.coordinates |
| | | List<Coordinate> coords = new ArrayList<>(); |
| | | String[] points = originalCoords.split(";"); |
| | | for (String point : points) { |
| | | String[] parts = point.split(","); |
| | | if (parts.length >= 2) { |
| | | double lonDecimal = Double.parseDouble(parts[0].trim()); |
| | | double latDecimal = Double.parseDouble(parts[1].trim()); |
| | | double alt = parts.length > 2 ? Double.parseDouble(parts[2].trim()) : 0.0; |
| | | |
| | | // 将十进制度转换为度分格式字符串 |
| | | String latDM = decimalToDegreeMinute(latDecimal); |
| | | String lonDM = decimalToDegreeMinute(lonDecimal); |
| | | String latDir = latDecimal >= 0 ? "N" : "S"; |
| | | String lonDir = lonDecimal >= 0 ? "E" : "W"; |
| | | |
| | | coords.add(new Coordinate(latDM, latDir, lonDM, lonDir, alt)); |
| | | } |
| | | // 调用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; |
| | | } |
| | | Coordinate.coordinates = coords; |
| | | |
| | | // 调用优化算法 |
| | | String optimized = bianjieguihua2.processCoordinateListAuto(baseStation); |
| | | |
| | | optTextArea.setText(optimized); |
| | | JOptionPane.showMessageDialog(this, "边界优化完成", "提示", JOptionPane.INFORMATION_MESSAGE); |
| | | } catch (Exception ex) { |
| | |
| | | // 获取当前优化后的边界 |
| | | String currentOptimized = optTextArea.getText(); |
| | | |
| | | // 保存地块编号,用于返回回调 |
| | | final String targetLandNumber = dikuai.getLandNumber(); |
| | | |
| | | // 调用首页显示预览 |
| | | SwingUtilities.invokeLater(() -> { |
| | | Shouye.showBoundaryPreview(dikuai, currentOptimized, () -> { |
| | | // 返回回调:重新打开此页面 |
| | | new Dikuanbianjipage(getOwner(), getTitle(), currentOptimized, dikuai).setVisible(true); |
| | | // 返回回调:重新打开此页面,从地块对象重新读取最新的边界坐标 |
| | | // 从 dikuaiMap 重新获取地块对象(确保获取到最新的值) |
| | | Dikuai updatedDikuai = Dikuai.getDikuai(targetLandNumber); |
| | | if (updatedDikuai != null) { |
| | | String latestBoundary = updatedDikuai.getBoundaryCoordinates(); |
| | | new Dikuanbianjipage(getOwner(), getTitle(), latestBoundary, updatedDikuai).setVisible(true); |
| | | } else { |
| | | // 如果获取失败,使用当前值 |
| | | new Dikuanbianjipage(getOwner(), getTitle(), currentOptimized, dikuai).setVisible(true); |
| | | } |
| | | }); |
| | | }); |
| | | }); |
| | |
| | | Dikuai.saveToProperties(); |
| | | this.result = trimmed; |
| | | JOptionPane.showMessageDialog(this, "地块边界坐标已更新", "成功", JOptionPane.INFORMATION_MESSAGE); |
| | | dispose(); |
| | | // 不退出页面,只更新显示 |
| | | // dispose(); // 移除退出逻辑 |
| | | }); |
| | | |
| | | closeBtn.addActionListener(e -> dispose()); |
| | |
| | | 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(); |
| | | } |
| | | } |