| | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.moral.api.entity.HistorySecondUav; |
| | | import com.moral.api.mapper.HistorySecondUavMapper; |
| | | import com.moral.api.pojo.dto.uav.UAVGetBD; |
| | | import com.moral.api.pojo.dto.uav.UAVGteForDTO; |
| | | import com.moral.api.pojo.dto.uav.UAVQueryTimeSlotDTO; |
| | | import com.moral.api.pojo.dto.uav.UAVResultDTO; |
| | |
| | | @PostMapping("test") |
| | | public ResultMessage test(@RequestBody Map<String, Object> params){ |
| | | //判断是否缺少参数 |
| | | if (!params.containsKey("mac") || !params.containsKey("batch") || !params.containsKey("height")|| !params.containsKey("uvasize")) { |
| | | if (!params.containsKey("mac") || !params.containsKey("batch") || !params.containsKey("height1")|| !params.containsKey("uvasize")|| !params.containsKey("height2")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String uvasize = params.get("uvasize").toString(); |
| | |
| | | ArrayList<Double> flyLatList = new ArrayList<>(); |
| | | //经度 |
| | | ArrayList<Double> flyLonList = new ArrayList<>(); |
| | | // HashMap<String, Object> map = new HashMap<>(); |
| | | // String mac ="p5dnd7a0243592"; |
| | | // String time1 ="2023-05-14 10:40:00"; |
| | | // String time2 ="2023-05-14 11:10:00"; |
| | | // map.put("mac",mac); |
| | | // map.put("time1",time1); |
| | | // map.put("time2",time2); |
| | | // map.put("height",0.5); |
| | | // List<UAVResultDTO> uavResultDTOS = historySecondUavMapper.reList(map); |
| | | // QueryWrapper<HistorySecondUav> queryWrapper = new QueryWrapper<>(); |
| | | // queryWrapper.select("value"); |
| | | // queryWrapper.eq("mac",mac); |
| | | // queryWrapper.between("time",time1,time2); |
| | | // List<HistorySecondUav> historySecondUavs = historySecondUavMapper.selectList(queryWrapper); |
| | | |
| | | List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params); |
| | | ArrayList<UAVGetBD> rsBDList = new ArrayList<>(); |
| | | for (HistorySecondUav historySecondUav : historySecondUavs) { |
| | | UAVGetBD uavGetBD = new UAVGetBD(); |
| | | String value = historySecondUav.getValue(); |
| | | JSONObject jsonObject = JSONObject.parseObject(value); |
| | | |
| | | String flylon = jsonObject.get("flylon").toString(); |
| | | String flylat = jsonObject.get("flylat").toString(); |
| | | //WGS84 转 百度坐标 |
| | | double[] doubles = transformWGS84ToBD09(Double.parseDouble(flylon), Double.parseDouble(flylat)); |
| | | uavGetBD.setFlyLon(doubles[0]); |
| | | uavGetBD.setFlyLat(doubles[1]); |
| | | uavGetBD.setTime(DateUtils.dateToDateString(historySecondUav.getTime())); |
| | | uavGetBD.setValue(value); |
| | | rsBDList.add(uavGetBD); |
| | | // flyLatList.add(Double.parseDouble(flylat)); |
| | | // flyLonList.add(Double.parseDouble(flylon)); |
| | | flyLatList.add(doubles[1]); |
| | | flyLonList.add(doubles[0]); |
| | | } |
| | | if (ObjectUtils.isEmpty(historySecondUavs)){ |
| | | return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,"null"); |
| | | } |
| | | |
| | | for (HistorySecondUav historySecondUav : historySecondUavs) { |
| | | String value = historySecondUav.getValue(); |
| | | Map map1 = JSON.parseObject(value, Map.class); |
| | | flyLatList.add(Double.parseDouble(map1.get("flylat").toString())); |
| | | flyLonList.add(Double.parseDouble(map1.get("flylon").toString())); |
| | | |
| | | } |
| | | //获取最大最小的经纬度 |
| | | Double maxLat = Collections.max(flyLatList); |
| | | Double maxLon = Collections.max(flyLonList); |
| | | Double minLat = Collections.min(flyLatList); |
| | | Double minLon = Collections.min(flyLonList); |
| | | |
| | | //大四边形右下 |
| | | String leftTop = minLat +";"+ maxLon; |
| | | // String leftTop = minLat +";"+ maxLon; |
| | | //右上 |
| | | String rightTop = maxLat +";"+ maxLon; |
| | | // String rightTop = maxLat +";"+ maxLon; |
| | | //左下 |
| | | String leftBottom = minLat +";" + minLon; |
| | | // String leftBottom = minLat +";" + minLon; |
| | | //左上 |
| | | String rightBottom = maxLat +";" + minLon; |
| | | // String rightBottom = maxLat +";" + minLon; |
| | | //计算纬度的距离 |
| | | double distance1 = getDistance(maxLon, minLat, maxLon, maxLat); |
| | | //计算经度的距离 |
| | |
| | | ArrayList<UAVGteForDTO> list = new ArrayList<>(); |
| | | //小四边形 |
| | | |
| | | String [] lefts =new String[]{maxLon.toString(),minLat.toString()}; |
| | | // String [] lefts =new String[]{maxLon.toString(),minLat.toString()}; |
| | | //右上2 |
| | | String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, 50); |
| | | String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, size); |
| | | //右下2 |
| | | String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), 50); |
| | | String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), size); |
| | | //左下2 |
| | | String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, 50); |
| | | String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, size); |
| | | |
| | | for (int i = 0; i <distance2 ; i+=size) { |
| | | UAVGteForDTO dto1 = new UAVGteForDTO(); |
| | |
| | | } |
| | | } |
| | | } |
| | | ArrayList<UAVResultDTO> uavResultDTOS1 = new ArrayList<>(); |
| | | for (UAVGteForDTO uavGteForDTO : list) { |
| | | ArrayList<String[]> doubleArrayList = new ArrayList<>(); |
| | | doubleArrayList.add(uavGteForDTO.getLeftTop()); |
| | | doubleArrayList.add(uavGteForDTO.getLeftBottom()); |
| | | doubleArrayList.add(uavGteForDTO.getRightTop()); |
| | | doubleArrayList.add(uavGteForDTO.getRightBottom()); |
| | | // UAVResultDTO result = getResult(doubleArrayList); |
| | | // uavResultDTOS1.add(result); |
| | | } |
| | | if (!ObjectUtils.isEmpty(uavResultDTOS1)){ |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),uavResultDTOS1); |
| | | |
| | | } |
| | | |
| | | // ArrayList<List<String>> lists = new ArrayList<>(); |
| | | HashMap<String,List<String>> rsMap = new HashMap<>(); |
| | | // HashMap<String,List<Map<String,Object>>> rsMap1 = new HashMap<>(); |
| | | List<String> stringList = new ArrayList<>(); |
| | | for (UAVGteForDTO uavGteForDTO : list) { |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | ArrayList<String[]> doubleArrayList = new ArrayList<>(); |
| | |
| | | doubleArrayList.add(uavGteForDTO.getLeftBottom()); |
| | | doubleArrayList.add(uavGteForDTO.getRightTop()); |
| | | doubleArrayList.add(uavGteForDTO.getRightBottom()); |
| | | String[] leftTops = uavGteForDTO.getLeftTop(); |
| | | String[] rightBottoms = uavGteForDTO.getRightBottom(); |
| | | Double x1 = Double.parseDouble(leftTops[0]); |
| | | Double x2 = Double.parseDouble(rightBottoms[0]); |
| | | Double y1 = Double.parseDouble(leftTops[1]); |
| | | Double y2 = Double.parseDouble(rightBottoms[1]); |
| | | //获取区域对象 |
| | | for (HistorySecondUav historySecondUav : historySecondUavs) { |
| | | String value = historySecondUav.getValue(); |
| | | Map map1 = JSON.parseObject(value, Map.class); |
| | | String flylat = map1.get("flylat").toString(); |
| | | String flylon = map1.get("flylon").toString(); |
| | | //判断点是否在区域内 |
| | | boolean flag = isInPolygon(flylon,flylat,doubleArrayList); |
| | | // for (int i = 0; i < historySecondUavs.size(); i++) { |
| | | // HistorySecondUav historySecondUav = historySecondUavs.get(i); |
| | | // String value = historySecondUav.getValue(); |
| | | // Map map1 = JSON.parseObject(value, Map.class); |
| | | // String flylat = map1.get("flylat").toString(); |
| | | // String flylon = map1.get("flylon").toString(); |
| | | // //判断点是否在区域内 |
| | | // boolean flag = isInPolygon(flylon,flylat,x1,x2,y1,y2); |
| | | // if (flag){ |
| | | // String time = DateUtils.dateToDateString(historySecondUav.getTime()); |
| | | // //historySecondUavs.remove(i); |
| | | // if(!stringList.contains(time)){ |
| | | // list1.add(historySecondUav.getValue()); |
| | | // stringList.add(time); |
| | | // } |
| | | // } |
| | | // } |
| | | for (UAVGetBD uavGetBD : rsBDList) { |
| | | boolean flag = isInPolygon(uavGetBD.getFlyLon().toString(),uavGetBD.getFlyLat().toString(),x1,x2,y1,y2); |
| | | if (flag){ |
| | | |
| | | list1.add(historySecondUav.getValue()); |
| | | String time = uavGetBD.getTime(); |
| | | //historySecondUavs.remove(i); |
| | | if(!stringList.contains(time)){ |
| | | list1.add(uavGetBD.getValue()); |
| | | stringList.add(time); |
| | | } |
| | | } |
| | | } |
| | | // lists.add(list1); |
| | | //获取中心点坐标 |
| | | String result = getResult(doubleArrayList); |
| | | rsMap.put(result,list1); |
| | |
| | | O3Double = O3ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | |
| | | // dto.setCoAvg(CODouble); |
| | | // dto.setNO2Avg(NODouble); |
| | | // dto.setO3Avg(O3Double); |
| | | // dto.setTVOCAvg(TVODouble); |
| | | // dto.setPM10Avg(PM10Double); |
| | | // dto.setPM25Avg(PM25Double); |
| | | // dto.setSO2Avg(SODouble); |
| | | // dto.setWDAvg(WDDouble); |
| | | // dto.setSHAvg(SHDouble); |
| | | // dto.setQYAvg(QYDouble); |
| | | dto.setA21005(CODouble); |
| | | dto.setA21004(NODouble); |
| | | dto.setA05024(O3Double); |
| | |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | //处理查询业务 |
| | | List<UAVQueryTimeSlotDTO> dtos = historySecondUavService.queryTimeSlot(form); |
| | | if (ObjectUtils.isEmpty(dtos)){ |
| | | return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,null); |
| | | } |
| | | //封装vo层 |
| | | UAVQueryTimeSlotVOs vo = UAVQueryTimeSlotVOs.convert(dtos); |
| | | |
| | | //返回数据 |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo); |
| | | } |
| | |
| | | |
| | | //获取中心点 |
| | | public static String getResult(ArrayList<String[]> doubleArrayList){ |
| | | // UAVResultDTO uavResultDTO = new UAVResultDTO(); |
| | | |
| | | int total = doubleArrayList.size(); |
| | | double X = 0, Y = 0, Z = 0; |
| | | for (int i = 0; i < total; i++) { |
| | |
| | | double Lon = Math.atan2(Y, X); |
| | | double Hyp = Math.sqrt(X * X + Y * Y); |
| | | double Lat = Math.atan2(Z, Hyp); |
| | | DecimalFormat decimalFormat = new DecimalFormat("#.00000000"); |
| | | double rsLon = Lon * 180 / Math.PI; |
| | | double rsLat = Lat * 180 / Math.PI; |
| | | |
| | | // double[] doubles = transformWGS84ToGCJ02(rsLon, rsLat); |
| | | // String s = transformGCJ02ToBD09(doubles[0], doubles[1]); |
| | | |
| | | |
| | | return decimalFormat.format(rsLon)+"_"+decimalFormat.format(rsLat); |
| | | // return rsLon+"_"+rsLat; |
| | | // return s; |
| | | } |
| | | |
| | | |
| | | //获取中心点 |
| | | public static UAVResultDTO getResults(ArrayList<String[]> doubleArrayList){ |
| | | UAVResultDTO uavResultDTO = new UAVResultDTO(); |
| | | int total = doubleArrayList.size(); |
| | | double X = 0, Y = 0, Z = 0; |
| | | for (int i = 0; i < total; i++) { |
| | | double lat, lon, x, y, z; |
| | | String[] strings = doubleArrayList.get(i); |
| | | lon = Double.parseDouble(strings[0]) * Math.PI / 180; |
| | | lat = Double.parseDouble(strings[1]) * Math.PI / 180; |
| | | x = Math.cos(lat) * Math.cos(lon); |
| | | y = Math.cos(lat) * Math.sin(lon); |
| | | z = Math.sin(lat); |
| | | X += x; |
| | | Y += y; |
| | | Z += z; |
| | | } |
| | | X = X / total; |
| | | Y = Y / total; |
| | | Z = Z / total; |
| | | double Lon = Math.atan2(Y, X); |
| | | double Hyp = Math.sqrt(X * X + Y * Y); |
| | | double Lat = Math.atan2(Z, Hyp); |
| | | |
| | | double rsLon = Lon * 180 / Math.PI; |
| | | double rsLat = Lat * 180 / Math.PI; |
| | | // uavResultDTO.setFlyLon(rsLon); |
| | | // uavResultDTO.setFlyLat(rsLat); |
| | | uavResultDTO.setFlyLon(rsLon); |
| | | uavResultDTO.setFlyLat(rsLat); |
| | | |
| | | return rsLon+"_"+rsLat; |
| | | // return uavResultDTO; |
| | | // return rsLon+"_"+rsLat; |
| | | return uavResultDTO; |
| | | } |
| | | |
| | | /** |
| | |
| | | double p_x =Double.parseDouble(X); |
| | | double p_y =Double.parseDouble(Y); |
| | | Point2D.Double point = new Point2D.Double(p_x, p_y); |
| | | |
| | | List<Point2D.Double> pointList= new ArrayList<Point2D.Double>(); |
| | | |
| | | for (String[] strings : doubleArrayList) { |
| | | double polygonPoint_x=Double.parseDouble(strings[0]); |
| | | double polygonPoint_y=Double.parseDouble(strings[1]); |
| | |
| | | |
| | | } |
| | | |
| | | public boolean isInPolygon(String X,String Y,double x1,double x2,double y1,double y2){ |
| | | boolean result = false; |
| | | double x =Double.parseDouble(X); |
| | | double y =Double.parseDouble(Y); |
| | | if(x >= Math.min(x1, x2) && x <= Math.max(x1, x2) ){ |
| | | if(y >= Math.min(y1, y2) && y <= Math.max(y1, y2)){ |
| | | result = true; |
| | | } |
| | | } |
| | | return result; |
| | | |
| | | } |
| | | |
| | | private static final double x_PI = 3.14159265358979324 * 3000.0 / 180.0; |
| | | private static final double PI = 3.1415926535897932384626; |
| | | private static final double a = 6378245.0; |
| | | private static final double ee = 0.00669342162296594323; |
| | | /** |
| | | * WGS84 坐标 转 GCJ02 |
| | | * |
| | | * @param lng 经度 |
| | | * @param lat 纬度 |
| | | * @return GCJ02 坐标:[经度,纬度] |
| | | */ |
| | | public static double[] transformWGS84ToGCJ02(double lng, double lat) { |
| | | if (outOfChina(lng, lat)) { |
| | | return new double[]{lng, lat}; |
| | | } else { |
| | | double dLat = transformLat(lng - 105.0, lat - 35.0); |
| | | double dLng = transformLng(lng - 105.0, lat - 35.0); |
| | | double redLat = lat / 180.0 * PI; |
| | | double magic = Math.sin(redLat); |
| | | magic = 1 - ee * magic * magic; |
| | | double sqrtMagic = Math.sqrt(magic); |
| | | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI); |
| | | dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(redLat) * PI); |
| | | double mgLat = lat + dLat; |
| | | double mgLng = lng + dLng; |
| | | return new double[]{mgLng, mgLat}; |
| | | } |
| | | } |
| | | |
| | | private static double transformLat(double lng, double lat) { |
| | | double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng)); |
| | | ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0; |
| | | ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | |
| | | private static double transformLng(double lng, double lat) { |
| | | double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng)); |
| | | ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0; |
| | | ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | /** |
| | | * 判断坐标是否不在国内 |
| | | * |
| | | * @param lng 经度 |
| | | * @param lat 纬度 |
| | | * @return 坐标是否在国内 |
| | | */ |
| | | public static boolean outOfChina(double lng, double lat) { |
| | | return (lng < 72.004 || lng > 137.8347) || (lat < 0.8293 || lat > 55.8271); |
| | | } |
| | | |
| | | /** |
| | | * GCJ02 转百度坐标 |
| | | * |
| | | * @param lng GCJ02 经度 |
| | | * @param lat GCJ02 纬度 |
| | | * @return 百度坐标:[经度,纬度] |
| | | */ |
| | | public static double[] transformGCJ02ToBD09(double lng, double lat) { |
| | | double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI); |
| | | double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI); |
| | | double bd_lng = z * Math.cos(theta) + 0.0065; |
| | | double bd_lat = z * Math.sin(theta) + 0.006; |
| | | return new double[]{bd_lng, bd_lat}; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * WGS84 转 百度坐标BD09 |
| | | * |
| | | * @param lng 经度 |
| | | * @param lat 纬度 |
| | | * @return BD09 坐标:[经度,纬度] |
| | | */ |
| | | public static double[] transformWGS84ToBD09(double lng, double lat) { |
| | | double[] lngLat = transformWGS84ToGCJ02(lng, lat); |
| | | |
| | | return transformGCJ02ToBD09(lngLat[0], lngLat[1]); |
| | | } |
| | | |
| | | } |