| | |
| | | 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); |
| | | return; |
| | | } |
| | | |
| | | // 准备 Coordinate 列表 |
| | | String originalCoords = dikuai.getBoundaryOriginalCoordinates(); |
| | | if (originalCoords == null || originalCoords.trim().isEmpty() || "-1".equals(originalCoords)) { |
| | | JOptionPane.showMessageDialog(this, "原始边界坐标为空,无法优化", "错误", JOptionPane.ERROR_MESSAGE); |
| | | // 从原始边界XY坐标文本域获取输入 |
| | | String inputXY = rawXYArea.getText(); |
| | | if (inputXY == null || inputXY.trim().isEmpty() || "-1".equals(inputXY.trim())) { |
| | | JOptionPane.showMessageDialog(this, "原始边界XY坐标为空,无法优化", "错误", 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)); |
| | | } |
| | | } |
| | | Coordinate.coordinates = coords; |
| | | |
| | | // 调用优化算法 |
| | | String optimized = bianjieguihua2.processCoordinateListAuto(baseStation); |
| | | // 调用优化算法(直接使用XY坐标字符串) |
| | | String optimized = bianjieguihua2.optimizeBoundaryXYString(inputXY.trim()); |
| | | 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, () -> { |
| | | // 返回回调:重新打开此页面 |
| | | // 返回回调:重新打开此页面,从地块对象重新读取最新的边界坐标 |
| | | // 从 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()); |