| | |
| | | |
| | | import baseStation.BaseStation; |
| | | import gecaoji.Device; |
| | | import publicway.buttonset; |
| | | import set.Setsys; |
| | | import ui.UIConfig; |
| | | import zhuye.Coordinate; |
| | | import zhuye.MapRenderer; |
| | | import zhuye.Shouye; |
| | | import zhangaiwu.AddDikuai; |
| | | import zhangaiwu.Obstacledge; |
| | | import zhangaiwu.yulanzhangaiwu; |
| | | import zhuye.buttonset; |
| | | import bianjie.bianjieguihua2; |
| | | import bianjie.ThreePointCircle; |
| | | |
| | | import bianjie.Bianjieyouhuatoxy; |
| | | /** |
| | | * 障碍物新增/编辑对话框。设计语言参考 {@link AddDikuai},支持通过实地绘制采集障碍物坐标。 |
| | | */ |
| | | import publicway.Gpstoxuzuobiao; |
| | | |
| | | public class addzhangaiwu extends JDialog { |
| | | private static final long serialVersionUID = 1L; |
| | | private static final double METERS_PER_DEGREE_LAT = 111320.0d; |
| | |
| | | } |
| | | |
| | | private static double parseDMToDecimal(String dmm, String direction) { |
| | | if (dmm == null || dmm.trim().isEmpty()) { |
| | | return Double.NaN; |
| | | } |
| | | try { |
| | | String trimmed = dmm.trim(); |
| | | int dotIndex = trimmed.indexOf('.'); |
| | | if (dotIndex < 2) { |
| | | return Double.NaN; |
| | | } |
| | | int degrees = Integer.parseInt(trimmed.substring(0, dotIndex - 2)); |
| | | double minutes = Double.parseDouble(trimmed.substring(dotIndex - 2)); |
| | | double decimal = degrees + minutes / 60.0; |
| | | if ("S".equalsIgnoreCase(direction) || "W".equalsIgnoreCase(direction)) { |
| | | decimal = -decimal; |
| | | } |
| | | return decimal; |
| | | } catch (NumberFormatException ex) { |
| | | return Double.NaN; |
| | | } |
| | | return Gpstoxuzuobiao.parseDMToDecimal(dmm, direction); |
| | | } |
| | | |
| | | private static double[] convertLatLonToLocal(double lat, double lon, double baseLat, double baseLon) { |
| | | double deltaLat = lat - baseLat; |
| | | double deltaLon = lon - baseLon; |
| | | double meanLatRad = Math.toRadians((baseLat + lat) / 2.0); |
| | | double eastMeters = deltaLon * METERS_PER_DEGREE_LAT * Math.cos(meanLatRad); |
| | | double northMeters = deltaLat * METERS_PER_DEGREE_LAT; |
| | | return new double[]{eastMeters, northMeters}; |
| | | return Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon); |
| | | } |
| | | |
| | | private static CircleFitResult fitCircleFromPoints(List<double[]> points) { |
| | |
| | | } |
| | | if (!configMap.isEmpty()) { |
| | | List<ExistingObstacle> remaining = new ArrayList<>(configMap.values()); |
| | | remaining.sort(Comparator.comparing(ExistingObstacle::getName, String.CASE_INSENSITIVE_ORDER)); |
| | | remaining.sort((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(a.getName(), b.getName())); |
| | | result.addAll(remaining); |
| | | } |
| | | if (result.isEmpty()) { |
| | |
| | | List<Coordinate> savedCoordinates = new ArrayList<>(Coordinate.coordinates); |
| | | |
| | | try { |
| | | // 设置到全局坐标列表 |
| | | Coordinate.coordinates.clear(); |
| | | Coordinate.coordinates.addAll(coordinateList); |
| | | // 构建边界字符串,格式为 "(lat1,lon1,alt1;lat2,lon2,alt2;...)" |
| | | String boundaryStr = buildBoundaryStringForOptimization(coordinateList); |
| | | |
| | | // 调用bianjieguihua2算法生成优化后的多边形边界坐标 |
| | | String optimizedCoordsStr = bianjieguihua2.processCoordinateListAuto(baseStation); |
| | | // 调用 Bianjieyouhuatoxy.optimizeBoundary 方法生成优化后的多边形边界坐标 |
| | | String optimizedCoordsStr = Bianjieyouhuatoxy.optimizeBoundary(baseStation, boundaryStr); |
| | | |
| | | if (optimizedCoordsStr == null || optimizedCoordsStr.trim().isEmpty()) { |
| | | if (optimizedCoordsStr == null || optimizedCoordsStr.trim().isEmpty() || optimizedCoordsStr.startsWith("ERROR")) { |
| | | JOptionPane.showMessageDialog(this, "生成边界坐标失败", "错误", JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 构建用于优化的边界字符串,格式为 "(lat1,lon1,alt1;lat2,lon2,alt2;...)" |
| | | * 其中lat和lon是度分格式(DMM格式),例如 "3949.89151752" |
| | | */ |
| | | private String buildBoundaryStringForOptimization(List<Coordinate> coordinates) { |
| | | if (coordinates == null || coordinates.isEmpty()) { |
| | | return "()"; |
| | | } |
| | | StringBuilder sb = new StringBuilder("("); |
| | | java.text.DecimalFormat elevationFormat = new java.text.DecimalFormat("0.00"); |
| | | for (int i = 0; i < coordinates.size(); i++) { |
| | | Coordinate coord = coordinates.get(i); |
| | | // Coordinate类中的getLatitude()和getLongitude()已经返回度分格式(DMM格式) |
| | | String latDMM = coord.getLatitude(); |
| | | String lonDMM = coord.getLongitude(); |
| | | double elevation = coord.getElevation(); |
| | | |
| | | if (i > 0) { |
| | | sb.append(";"); |
| | | } |
| | | sb.append(latDMM).append(",") |
| | | .append(lonDMM).append(",") |
| | | .append(elevationFormat.format(elevation)); |
| | | } |
| | | sb.append(")"); |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 预览障碍物边界 |
| | | */ |
| | | private void previewObstacleBoundary() { |