| | |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | public List<SysUser>getNearAppUsers(SchedulingParam param); |
| | | |
| | | /** |
| | | * 获取封控圈内所有在线app用户(多边形) |
| | | * 刘苏义 |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | public List<SysUser>getNearAppUsersWithPolygon(SchedulingParam param); |
| | | } |
| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | import java.awt.geom.Point2D; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | } |
| | | return filteredList; |
| | | } |
| | | /** |
| | | * 获取封控圈内所有在线app用户(多边形) |
| | | * 刘苏义 |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | @Override |
| | | public List<SysUser> getNearAppUsersWithPolygon(SchedulingParam param) { |
| | | List<SysUser> filteredList = new ArrayList<>(); |
| | | try { |
| | | Long deptId = SecurityUtils.getLoginUser().getUser().getDeptId(); |
| | | List<Point2D> partitionLocation = param.getPartitionLocation(); |
| | | |
| | | SysUser user = new SysUser(); |
| | | user.setDeptId(deptId); |
| | | List<SysUser> appUserList = iSysUserService.selectAllAppUserList(user); |
| | | //过滤在线 |
| | | List<SysUser> onLineList = appUserList.stream() |
| | | .filter(sysUser -> (sysUser.getAppOnlineState().equals("1"))) |
| | | .collect(Collectors.toList()); |
| | | //过滤范围 |
| | | for (SysUser sysUser : onLineList) { |
| | | ArdAppPosition ardAppPosition = ardAppPositionMapper.selectLastArdAppPositionByUserId(sysUser.getUserId()); |
| | | if (ardAppPosition != null) { |
| | | Double lon = ardAppPosition.getLongitude(); |
| | | Double lat = ardAppPosition.getLatitude(); |
| | | if (lon == null || lat == null) { |
| | | continue; |
| | | } |
| | | Point2D point2D=new Point2D.Double(lon,lat); |
| | | boolean inPolygon = GisTool.isInPolygon(point2D, partitionLocation); |
| | | if (inPolygon) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("longitude", lon); |
| | | params.put("latitude", lat); |
| | | sysUser.setParams(params); |
| | | filteredList.add(sysUser); // 将满足条件的用户添加到筛选列表中 |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error("获取封控圈内所有在线app用户异常" + ex.getMessage()); |
| | | } |
| | | return filteredList; |
| | | } |
| | | } |
| | |
| | | public TreeMap getNearCamerasBycoordinate(CameraCmd cmd); |
| | | |
| | | /** |
| | | * 获取监控圈内所有在线光电 |
| | | * 获取监控圈内所有在线光电(半径) |
| | | * 刘苏义 |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | List<ArdCameras> getNearCameras(SchedulingParam param); |
| | | /** |
| | | * 获取监控圈内所有在线光电(多边形) |
| | | * 刘苏义 |
| | | * 2023/8/17 13:56:36 |
| | | */ |
| | | public List<ArdCameras> getNearCamerasWithPolygon(SchedulingParam param); |
| | | } |
| | |
| | | package com.ruoyi.device.camera.service.impl; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.time.LocalTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | double[] camPosition = new double[]{camera.getLongitude(), camera.getLatitude()}; |
| | | double distance = GisTool.getDistance(new double[]{longitude, latitude}, camPosition); |
| | | if (distance <= radius) { |
| | | camera.setChanNo(ArdTool.getChannelBydayNightTime(dayNightTime)); |
| | | /*获取通道列表*/ |
| | | ArdChannel ardChannel=new ArdChannel(); |
| | | ardChannel.setDeviceId(camera.getId()); |
| | | List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel); |
| | | camera.setChannelList(ardChannels); |
| | | ardCameras.add(camera); |
| | | } |
| | | } |
| | | //过滤在线相机 |
| | | List<ArdCameras> onlineList = ardCameras.stream() |
| | | .filter(ardCamera -> (!ardCamera.getLoginId().equals(-1))) |
| | | .collect(Collectors.toList()); |
| | | return onlineList; |
| | | } catch (Exception ex) { |
| | | log.error("获取附近相机异常:" + ex.getMessage()); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 获取监控圈内所有在线光电 |
| | | * 刘苏义 |
| | | * 2023/8/17 13:57:21 |
| | | */ |
| | | @Override |
| | | public List<ArdCameras> getNearCamerasWithPolygon(SchedulingParam param) { |
| | | try { |
| | | Long deptId=SecurityUtils.getLoginUser().getUser().getDeptId(); |
| | | List<Point2D> partitionLocation = param.getPartitionLocation(); |
| | | if(partitionLocation==null) |
| | | { |
| | | log.debug("多边形坐标集合为空"); |
| | | return null; |
| | | } |
| | | String dayNightTime = redisCache.getCacheObject("sys_config:dayNightTime"); |
| | | //获取所有光电(按部门) |
| | | ArdCameras cameras= new ArdCameras(); |
| | | cameras.setDeptId(deptId); |
| | | List<ArdCameras> ardCamerasList = ardCamerasMapper.selectArdCamerasList(cameras); |
| | | List<ArdCameras> ardCameras = new ArrayList<>(); |
| | | for (ArdCameras camera : ardCamerasList) { |
| | | if (camera.getLongitude() == null && camera.getLatitude() == null) { |
| | | continue; |
| | | } |
| | | /*判断坐标是否在多边形范围内*/ |
| | | Point2D camPosition=new Point2D.Double(camera.getLongitude(), camera.getLatitude()); |
| | | boolean inPolygon = GisTool.isInPolygon(camPosition, partitionLocation); |
| | | if (inPolygon) { |
| | | /*获取通道列表*/ |
| | | ArdChannel ardChannel=new ArdChannel(); |
| | | ardChannel.setDeviceId(camera.getId()); |
| | | List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel); |
| | | camera.setChannelList(ardChannels); |
| | | ardCameras.add(camera); |
| | | } |
| | | } |
| | |
| | | IArdAppPositionService iArdAppPositionService; |
| | | |
| | | @GetMapping("/getNearVehiPersonCam") |
| | | @ApiOperation("获取附近的车人相机") |
| | | @ApiOperation("获取附近的车人相机(半径)") |
| | | AjaxResult getNearVehiPersonCam(SchedulingParam param) { |
| | | Map<String, Object> nearMap = new HashMap<>(); |
| | | |
| | |
| | | |
| | | return AjaxResult.success(nearMap); |
| | | } |
| | | @GetMapping("/getPolygonVehiPersonCam") |
| | | @ApiOperation("获取附近的车人相机(多边形)") |
| | | AjaxResult getPolygonVehiPersonCam(SchedulingParam param) { |
| | | Map<String, Object> nearMap = new HashMap<>(); |
| | | List<Map<String, Object>> Cars = iArdSyCarService.getNearCarWithPolygon(param); |
| | | nearMap.put("car", Cars); |
| | | List<ArdCameras> Cameras = iArdCamerasService.getNearCamerasWithPolygon(param); |
| | | nearMap.put("camera", Cameras); |
| | | List<SysUser> AppUsers = iArdAppPositionService.getNearAppUsersWithPolygon(param); |
| | | nearMap.put("users", AppUsers); |
| | | return AjaxResult.success(nearMap); |
| | | } |
| | | } |
| | |
| | | |
| | | import lombok.Data; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: |
| | | * @ClassName: RequestParam |
| | |
| | | Integer monitoringRadius; |
| | | Double longitude; |
| | | Double latitude; |
| | | //多边形坐标集合 |
| | | List<Point2D> partitionLocation; |
| | | } |
| | |
| | | * 获取附近范围内的车辆信息 |
| | | * */ |
| | | List<Map<String, Object>> getNearCar(SchedulingParam param); |
| | | /** |
| | | * 获取附近范围内的车辆信息(多边形) |
| | | * */ |
| | | List<Map<String, Object>> getNearCarWithPolygon(SchedulingParam param); |
| | | } |
| | |
| | | package com.ruoyi.sy.service.impl; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.text.ParseException; |
| | |
| | | /** |
| | | * 获取附近范围内的车辆信息 |
| | | */ |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getNearCar(SchedulingParam param) { |
| | | Double longitude = param.getLongitude(); |
| | |
| | | } |
| | | return filteredList; |
| | | } |
| | | /** |
| | | * 获取范围内的车辆信息(多边形) |
| | | */ |
| | | @Override |
| | | public List<Map<String, Object>> getNearCarWithPolygon(SchedulingParam param) { |
| | | List<Map<String, Object>> filteredList = new ArrayList<>(); |
| | | try { |
| | | List<Point2D> partitionLocation = param.getPartitionLocation(); |
| | | if (partitionLocation == null) { |
| | | log.debug("多边形坐标集合为空"); |
| | | return null; |
| | | } |
| | | String userId = SecurityUtils.getUserId(); |
| | | ArdSyUser syUser = new ArdSyUser(); |
| | | syUser.setSysUserId(userId); |
| | | List<ArdSyUser> ardSyUserList = ardSyUserMapper.selectArdSyUserList(syUser); |
| | | if (ardSyUserList.size() == 0) { |
| | | log.debug("用户未挂接三一车辆"); |
| | | return null; |
| | | } |
| | | ArdSyUser ardSyUser = ardSyUserList.get(0); |
| | | String syUrl = redisCache.getCacheObject("sys_config:syCarPT"); |
| | | String passwordMd5 = DigestUtils.md5Hex(ardSyUser.getPassword()); |
| | | Map<String, Object> LogInResult = sYClient.logIn(syUrl, passwordMd5, ardSyUser.getUserId()); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | |
| | | Map<String, Object> teamList = sYClient.getTeamList(syUrl, ardSyUser.getUserId(), sessionId); |
| | | List<Map<String, Object>> listMap = (List<Map<String, Object>>) teamList.get("list"); |
| | | List<Map<String, Object>> allList = new ArrayList<>(); |
| | | for (Map<String, Object> team : listMap) { |
| | | String teamId = (String) team.get("teamId"); |
| | | Map<String, Object> carListMap = sYClient.getCarList1(syUrl, teamId, ardSyUser.getUserId(), sessionId); |
| | | if (((String) carListMap.get("rspCode")).equals("1")) { |
| | | List<Map<String, Object>> list = (List<Map<String, Object>>) carListMap.get("list"); |
| | | allList.addAll(list); |
| | | } |
| | | } |
| | | //过滤在线车辆 |
| | | List<Map<String, Object>> onlineList = allList.stream() |
| | | .filter(map -> !"离线".equals(map.get("stateCn"))) |
| | | .collect(Collectors.toList()); |
| | | |
| | | //过滤半径 |
| | | for (Map<String, Object> carMap : onlineList) { |
| | | String carId = (String) carMap.get("carId"); |
| | | Map<String, Object> carGPSTrack = sYClient.getCarNearPositionByCarId(syUrl, carId, ardSyUser.getUserId(), sessionId); |
| | | List<Map<String, Object>> carGPSMap = (List<Map<String, Object>>) carGPSTrack.get("list"); |
| | | Double lng = Double.valueOf((String) carGPSMap.get(0).get("lng")); |
| | | Double lat = Double.valueOf((String) carGPSMap.get(0).get("lat")); |
| | | Point2D point2D = new Point2D.Double(lng, lat); |
| | | boolean inPolygon = GisTool.isInPolygon(point2D, partitionLocation); |
| | | if (inPolygon) { |
| | | carMap.put("longitude", lng); |
| | | carMap.put("latitude", lat); |
| | | filteredList.add(carMap); // 将满足条件的车辆添加到筛选列表中 |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.error("获取范围内的车辆信息(多边形)异常:" + ex.getMessage()); |
| | | } |
| | | return filteredList; |
| | | } |
| | | } |
| | |
| | | import org.gavaghan.geodesy.GeodeticCalculator; |
| | | import org.gavaghan.geodesy.GlobalCoordinates; |
| | | |
| | | import java.awt.geom.Point2D; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: |
| | | * @ClassName: GisTool |
| | |
| | | GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo); |
| | | return geodeticCalculator.calculateGeodeticCurve(Ellipsoid.WGS84, source, target).getEllipsoidalDistance(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | // 被检测的经纬度点 |
| | | Point2D point2D= new Point2D.Double(126.649261,45.687377); |
| | | // 商业区域(百度多边形区域经纬度集合) |
| | | List<Point2D> partitionLocation = new ArrayList<>(); |
| | | partitionLocation.add(new Point2D.Double(126.64459,45.688548)); |
| | | partitionLocation.add(new Point2D.Double(126.653376,45.68938)); |
| | | partitionLocation.add(new Point2D.Double(126.645776,45.685048)); |
| | | partitionLocation.add(new Point2D.Double(126.654184,45.685778)); |
| | | System.out.println(isInPolygon(point2D,partitionLocation)); |
| | | } |
| | | |
| | | /** |
| | | * 判断当前位置是否在多边形区域内 |
| | | * @param orderLocation 当前点 |
| | | * @param partitionLocation 区域顶点 |
| | | * @return |
| | | */ |
| | | public static boolean isInPolygon(Point2D orderLocation,List<Point2D> partitionLocation){ |
| | | |
| | | double p_x =orderLocation.getX(); |
| | | double p_y =orderLocation.getY(); |
| | | Point2D.Double point = new Point2D.Double(p_x, p_y); |
| | | |
| | | List<Point2D.Double> pointList= new ArrayList<Point2D.Double>(); |
| | | |
| | | for (Point2D points : partitionLocation){ |
| | | double polygonPoint_x=points.getX(); |
| | | double polygonPoint_y=points.getY(); |
| | | Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x,polygonPoint_y); |
| | | pointList.add(polygonPoint); |
| | | } |
| | | return IsPtInPoly(point,pointList); |
| | | } |
| | | /** |
| | | * 判断点是否在多边形内,如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true |
| | | * @param point 检测点 |
| | | * @param pts 多边形的顶点 |
| | | * @return 点在多边形内返回true,否则返回false |
| | | */ |
| | | public static boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> pts){ |
| | | |
| | | int N = pts.size(); |
| | | boolean boundOrVertex = true; //如果点位于多边形的顶点或边上,也算做点在多边形内,直接返回true |
| | | int intersectCount = 0;//cross points count of x |
| | | double precision = 2e-10; //浮点类型计算时候与0比较时候的容差 |
| | | Point2D.Double p1, p2;//neighbour bound vertices |
| | | Point2D.Double p = point; //当前点 |
| | | |
| | | p1 = pts.get(0);//left vertex |
| | | for(int i = 1; i <= N; ++i){//check all rays |
| | | if(p.equals(p1)){ |
| | | return boundOrVertex;//p is an vertex |
| | | } |
| | | |
| | | p2 = pts.get(i % N); |
| | | if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){ |
| | | p1 = p2; |
| | | continue; |
| | | } |
| | | |
| | | if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){ |
| | | if(p.y <= Math.max(p1.y, p2.y)){ |
| | | if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){ |
| | | return boundOrVertex; |
| | | } |
| | | |
| | | if(p1.y == p2.y){ |
| | | if(p1.y == p.y){ |
| | | return boundOrVertex; |
| | | }else{//before ray |
| | | ++intersectCount; |
| | | } |
| | | }else{ |
| | | double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y; |
| | | if(Math.abs(p.y - xinters) < precision){ |
| | | return boundOrVertex; |
| | | } |
| | | |
| | | if(p.y < xinters){ |
| | | ++intersectCount; |
| | | } |
| | | } |
| | | } |
| | | }else{ |
| | | if(p.x == p2.x && p.y <= p2.y){ |
| | | Point2D.Double p3 = pts.get((i+1) % N); |
| | | if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){ |
| | | ++intersectCount; |
| | | }else{ |
| | | intersectCount += 2; |
| | | } |
| | | } |
| | | } |
| | | p1 = p2; |
| | | } |
| | | |
| | | if(intersectCount % 2 == 0){//偶数在多边形外 |
| | | return false; |
| | | } else { //奇数在多边形内 |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | } |