| | |
| | | ArdNoFlyBox box = zone.getArdNoFlyBox(); |
| | | if (box == null) continue; |
| | | |
| | | // 包围盒快速排除 |
| | | if (current.x < box.getMinx() || current.x > box.getMaxx() || |
| | | current.y < box.getMiny() || current.y > box.getMaxy()) { |
| | | // ⭐ 外扩 50 米 |
| | | ArdNoFlyBox expanded = expandBoxByMeter(box, 50); |
| | | |
| | | // ⭐ 包围盒快速排除必须使用 expanded,而不是 box |
| | | if (current.x < expanded.getMinx() || current.x > expanded.getMaxx() || |
| | | current.y < expanded.getMiny() || current.y > expanded.getMaxy()) { |
| | | continue; |
| | | } |
| | | |
| | | // 计算 polygon 距离 |
| | | List<Vertex> polygon = zone.getVertices(); |
| | | if (polygon == null || polygon.size() < 3) continue; |
| | | |
| | |
| | | return NoFlyDistanceDTO.builder() |
| | | .boxSn(boxSn) |
| | | .zoneName(nearestZone.getName()) |
| | | .distance(minDistance) |
| | | .distance(minDistance) // 米 |
| | | .inNoFlyZone(minDistance == 0) |
| | | .build(); |
| | | } |
| | | |
| | | // 外扩包围盒多少米 |
| | | private ArdNoFlyBox expandBoxByMeter(ArdNoFlyBox box, double meter) { |
| | | |
| | | // 计算经纬度偏移 |
| | | double latShift = meter / 111320.0; // 纬度方向 |
| | | double lngShift = meter / (111320.0 * Math.cos(Math.toRadians( |
| | | (box.getMiny() + box.getMaxy()) / 2 |
| | | ))); // 经度方向与纬度相关 |
| | | |
| | | return new ArdNoFlyBox( |
| | | box.getMinx() - lngShift, |
| | | box.getMiny() - latShift, |
| | | box.getMaxx() + lngShift, |
| | | box.getMaxy() + latShift |
| | | ); |
| | | } |
| | | |
| | | |
| | |
| | | protected String getMessageType() { |
| | | return "noFlyZoneDistance"; |
| | | } |
| | | |
| | | |
| | | |
| | | } |