From 4ecf545f43b6a2fff7d3e426a86411e620253221 Mon Sep 17 00:00:00 2001
From: yyy <1083599556@qq.com>
Date: 星期四, 23 四月 2026 22:29:05 +0800
Subject: [PATCH] 1.发送微信订阅通知 完成40% 2.通过围栏查询 场站 3.围栏详情查询 点位、场站信息 (总数量、启动中、待启动、已停用、已失效) 4.班次 需要增加一个是否跨天 5.修改接口, /map/base/v1/mini-program/cities/list 增加参数 type 1=围栏 2场站 添加场站是否收藏的字段 6.点位情况上报 详情增加上报人的角色
---
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/PolygonOverlapService.java | 142 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 142 insertions(+), 0 deletions(-)
diff --git a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/PolygonOverlapService.java b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/PolygonOverlapService.java
index 5d056d6..c7e5d10 100644
--- a/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/PolygonOverlapService.java
+++ b/xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/PolygonOverlapService.java
@@ -61,4 +61,146 @@
LinearRing linearRing = geometryFactory.createLinearRing(coordinates);
return geometryFactory.createPolygon(linearRing);
}
+
+
+ /**
+ * 判断一个坐标点位是否在一个坐标区域内
+ * @param longitude 经度
+ * @param latitude 纬度
+ * @param fencePoints 围栏点位字符串,格式为 "lng1_lat1,lng2_lat2,..."
+ * @return 是否在区域内 true在 false不在
+ */
+ public boolean isPointInPolygon(double longitude, double latitude, String fencePoints) {
+ if (fencePoints == null || fencePoints.trim().isEmpty()) {
+ return false;
+ }
+
+ // 解析围栏点位
+ String[] points = fencePoints.split(",");
+ if (points.length < 3) {
+ return false;
+ }
+
+ int n = points.length;
+ boolean inside = false;
+
+ double x = longitude, y = latitude;
+ double[] xs = new double[n];
+ double[] ys = new double[n];
+
+ for (int i = 0; i < n; i++) {
+ String[] coords = points[i].split("_");
+ if (coords.length != 2) {
+ continue;
+ }
+ try {
+ xs[i] = Double.parseDouble(coords[0]);
+ ys[i] = Double.parseDouble(coords[1]);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ // 使用射线法判断点是否在多边形内
+ for (int i = 0, j = n - 1; i < n; j = i++) {
+ if (((ys[i] > y) != (ys[j] > y)) &&
+ (x < (xs[j] - xs[i]) * (y - ys[i]) / (ys[j] - ys[i]) + xs[i])) {
+ inside = !inside;
+ }
+ }
+
+ return inside;
+ }
+
+
+ /**
+ * 判断一个坐标区域(多边形A)是否完全在另一个坐标区域(多边形B)内
+ * 原理:如果多边形A的所有顶点都在多边形B内,则认为A在B内
+ * @param innerFencePoints 内部围栏点位字符串(待判断是否在外的围栏),格式为 "lng1_lat1,lng2_lat2,..."
+ * @param outerFencePoints 外部围栏点位字符串(参考围栏),格式为 "lng1_lat1,lng2_lat2,..."
+ * @return 是否在内 true在内 false不在
+ */
+
+ public boolean isPolygonInPolygon(String innerFencePoints, String outerFencePoints) {
+ if (innerFencePoints == null || innerFencePoints.trim().isEmpty()
+ || outerFencePoints == null || outerFencePoints.trim().isEmpty()) {
+ return false;
+ }
+
+ // 解析内部围栏点位
+ String[] innerPoints = innerFencePoints.split(",");
+ if (innerPoints.length < 3) {
+ return false;
+ }
+
+ // 检查内部围栏的每一个顶点是否都在外部围栏内
+ for (String pointStr : innerPoints) {
+ String[] coords = pointStr.split("_");
+ if (coords.length != 2) {
+ continue;
+ }
+ try {
+ double lon = Double.parseDouble(coords[0]);
+ double lat = Double.parseDouble(coords[1]);
+
+ // 如果有一个顶点不在外部围栏内,则整个区域不在内部
+ if (!isPointInPolygon(lon, lat, outerFencePoints)) {
+ return false;
+ }
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
+ /**
+ * 根据围栏点位字符串计算中心点坐标
+ * @param fencePoints 围栏点位字符串,格式为 "lng1_lat1,lng2_lat2,..."
+ * @return double[0] 经度, double[1] 纬度
+ */
+ public double[] calculateCenterPoint(String fencePoints) {
+ if (fencePoints == null || fencePoints.trim().isEmpty()) {
+ return new double[]{0.0, 0.0};
+ }
+
+ String[] points = fencePoints.split(",");
+ if (points.length == 0) {
+ return new double[]{0.0, 0.0};
+ }
+
+ double sumLon = 0.0;
+ double sumLat = 0.0;
+ int count = 0;
+
+ for (String point : points) {
+ String[] coords = point.split("_");
+ if (coords.length == 2) {
+ try {
+ double lon = Double.parseDouble(coords[0]);
+ double lat = Double.parseDouble(coords[1]);
+ sumLon += lon;
+ sumLat += lat;
+ count++;
+ } catch (NumberFormatException e) {
+ // 忽略解析错误的点
+ }
+ }
+ }
+
+ if (count == 0) {
+ return new double[]{0.0, 0.0};
+ }
+
+ double centerLon = sumLon / count;
+ double centerLat = sumLat / count;
+
+ return new double[]{centerLon, centerLat};
+ }
+
+
+
+
}
\ No newline at end of file
--
Gitblit v1.7.1