| | |
| | | package com.stylefeng.guns.modular.crossCity.server.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.crossCity.dao.LocationMapper; |
| | | import com.stylefeng.guns.modular.crossCity.dao.SiteMapper; |
| | | import com.stylefeng.guns.modular.crossCity.model.Site; |
| | | import com.stylefeng.guns.modular.crossCity.server.ISiteService; |
| | | import com.stylefeng.guns.modular.crossCity.warpper.SiteWarpper; |
| | | import com.stylefeng.guns.modular.system.util.GDMapElectricFenceUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @Resource |
| | | private LocationMapper locationMapper; |
| | | |
| | | @Autowired |
| | | private GDMapElectricFenceUtil gdMapElectricFenceUtil; |
| | | private static final double COORDINATE_EPSILON = 1E-10; |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | if(Integer.valueOf(map.get("type").toString()) == 2){//电子围栏 |
| | | String gid = map.get("gid").toString(); |
| | | List<String> list1 = gdMapElectricFenceUtil.monitorElectricFenc("", lonLat); |
| | | if(list1.contains(gid)){ |
| | | Object coordinate = map.get("coordinate"); |
| | | if(coordinate != null && isPointInElectronicFence(lonLat, coordinate.toString())){ |
| | | return true; |
| | | } |
| | | continue; |
| | |
| | | return false; |
| | | } |
| | | |
| | | static boolean isPointInElectronicFence(String lonLat, String coordinate) { |
| | | double[] point = parseCoordinate(lonLat); |
| | | if (point == null || coordinate == null || coordinate.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | String[] fences = coordinate.split("_"); |
| | | for (String fence : fences) { |
| | | String[] coordinatePoints = fence.split(";"); |
| | | if (coordinatePoints.length < 3) { |
| | | continue; |
| | | } |
| | | List<double[]> polygon = new ArrayList<>(); |
| | | boolean validPolygon = true; |
| | | for (String coordinatePoint : coordinatePoints) { |
| | | double[] vertex = parseCoordinate(coordinatePoint); |
| | | if (vertex == null) { |
| | | validPolygon = false; |
| | | break; |
| | | } |
| | | polygon.add(vertex); |
| | | } |
| | | if (validPolygon && isPointInPolygon(point, polygon)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static double[] parseCoordinate(String coordinate) { |
| | | if (coordinate == null || coordinate.trim().isEmpty()) { |
| | | return null; |
| | | } |
| | | String[] values = coordinate.trim().split(","); |
| | | if (values.length != 2) { |
| | | return null; |
| | | } |
| | | try { |
| | | double longitude = Double.parseDouble(values[0].trim()); |
| | | double latitude = Double.parseDouble(values[1].trim()); |
| | | if (Double.isNaN(longitude) || Double.isInfinite(longitude) |
| | | || Double.isNaN(latitude) || Double.isInfinite(latitude)) { |
| | | return null; |
| | | } |
| | | return new double[]{longitude, latitude}; |
| | | } catch (NumberFormatException e) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private static boolean isPointInPolygon(double[] point, List<double[]> polygon) { |
| | | boolean inside = false; |
| | | for (int i = 0, j = polygon.size() - 1; i < polygon.size(); j = i++) { |
| | | double[] start = polygon.get(j); |
| | | double[] end = polygon.get(i); |
| | | if (isPointOnSegment(point, start, end)) { |
| | | return true; |
| | | } |
| | | boolean intersects = (start[1] > point[1]) != (end[1] > point[1]) |
| | | && point[0] < (end[0] - start[0]) * (point[1] - start[1]) |
| | | / (end[1] - start[1]) + start[0]; |
| | | if (intersects) { |
| | | inside = !inside; |
| | | } |
| | | } |
| | | return inside; |
| | | } |
| | | |
| | | private static boolean isPointOnSegment(double[] point, double[] start, double[] end) { |
| | | double crossProduct = (point[0] - start[0]) * (end[1] - start[1]) |
| | | - (point[1] - start[1]) * (end[0] - start[0]); |
| | | if (Math.abs(crossProduct) > COORDINATE_EPSILON) { |
| | | return false; |
| | | } |
| | | return point[0] >= Math.min(start[0], end[0]) - COORDINATE_EPSILON |
| | | && point[0] <= Math.max(start[0], end[0]) + COORDINATE_EPSILON |
| | | && point[1] >= Math.min(start[1], end[1]) - COORDINATE_EPSILON |
| | | && point[1] <= Math.max(start[1], end[1]) + COORDINATE_EPSILON; |
| | | } |
| | | |
| | | /** |
| | | * 根据站点id获取地点区域 |
| | | * @param siteId |