| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.commons.collections.MapUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | import com.moral.mapper.SensorMapper; |
| | | import com.moral.service.DeviceService; |
| | | import com.moral.service.HistoryHourlyService; |
| | | import javax.annotation.Resource; |
| | | |
| | | @Service |
| | | public class HistoryHourlyServiceImpl implements HistoryHourlyService { |
| | |
| | | sensorKeys.add(sensor.getSensorKey()); |
| | | } |
| | | parameters.put("sensorKeys", sensorKeys); |
| | | /* if(pollutionSourceData.get("e6")!=null&&pollutionSourceData.get("e18")!=null){ |
| | | pollutionSourceData=historyHourlyMapper.getPollutionSourceData(parameters); |
| | | } |
| | | return pollutionSourceData;*/ |
| | | System.out.println("----"+historyHourlyMapper.getPollutionSourceData(parameters)); |
| | | return historyHourlyMapper.getPollutionSourceData(parameters); |
| | | return historyHourlyMapper.getPollutionSourceData(parameters); |
| | | } |
| | | |
| | | @Override |
| | | public Point getDirPoint(Map<String, Object> parameters) throws Exception{ |
| | | Map<String,Object> pollutionSourceData=getPollutionSourceData(parameters); |
| | | public Point getDirPoint(Map<String, Object> parameters) throws Exception { |
| | | Map<String, Object> pollutionSourceData = getPollutionSourceData(parameters); |
| | | String mac = parameters.get("mac").toString(); |
| | | Device device = deviceService.getDeviceByMac(mac, false); |
| | | Point pointEnd=new Point(); |
| | | if(MapUtils.isNotEmpty(pollutionSourceData)){ |
| | | System.out.println("pollutionSourceData"+pollutionSourceData); |
| | | if(pollutionSourceData.get("e18")!=null&&pollutionSourceData.get("e23")!=null&&pollutionSourceData.get("e6")!=null){ |
| | | double windSpeed=Double.valueOf(pollutionSourceData.get("e18").toString()); |
| | | double winDir=Double.valueOf(pollutionSourceData.get("e23").toString()); |
| | | double distance=windSpeed*3600; |
| | | double long1=device.getLongitude(); |
| | | double lat1=device.getLatitude(); |
| | | System.out.println("windSpeed:"+windSpeed+"---winDir:"+winDir+"---distance:"+distance+"--long1:"+long1+"--lat1:"+lat1); |
| | | String[] result=calLocationByDistanceAndLocationAndDirection(winDir,long1,lat1,distance); |
| | | System.out.println("result1:"+Double.valueOf(result[0])+"result2:"+Double.valueOf(result[1])); |
| | | Point pointEnd = new Point(); |
| | | if (MapUtils.isNotEmpty(pollutionSourceData)) { |
| | | if (pollutionSourceData.get("e18") != null && pollutionSourceData.get("e23") != null && pollutionSourceData.get("e6") != null) { |
| | | double windSpeed = Double.valueOf(pollutionSourceData.get("e18").toString()); |
| | | double winDir = Double.valueOf(pollutionSourceData.get("e23").toString()); |
| | | double distance = windSpeed * 3600; |
| | | double long1 = device.getLongitude(); |
| | | double lat1 = device.getLatitude(); |
| | | String[] result = calLocationByDistanceAndLocationAndDirection(winDir, long1, lat1, distance); |
| | | pointEnd.setLng(Double.valueOf(result[0])); |
| | | pointEnd.setLat(Double.valueOf(result[1])); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据一点的坐标与距离,以及方向,计算另外一点的位置 |
| | | * @param angle 角度,从正北顺时针方向开始计算 |
| | | * |
| | | * @param angle 角度,从正北顺时针方向开始计算 |
| | | * @param startLong 起始点经度 |
| | | * @param startLat 起始点纬度 |
| | | * @param distance 距离,单位m |
| | | * @param startLat 起始点纬度 |
| | | * @param distance 距离,单位m |
| | | * @return |
| | | */ |
| | | private String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong,double startLat, double distance){ |
| | | private String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong, double startLat, double distance) { |
| | | /** 地球半径 **/ |
| | | final double R = 6371e3; |
| | | /** 180° **/ |
| | | final DecimalFormat df = new DecimalFormat("0.000000"); |
| | | String[] result = new String[2]; |
| | | //将距离转换成经度的计算公式 |
| | | double δ = distance/R; |
| | | double δ = distance / R; |
| | | // 转换为radian,否则结果会不正确 |
| | | angle = Math.toRadians(angle); |
| | | startLong = Math.toRadians(startLong); |
| | | startLat = Math.toRadians(startLat); |
| | | double lat = Math.asin(Math.sin(startLat)*Math.cos(δ)+Math.cos(startLat)*Math.sin(δ)*Math.cos(angle)); |
| | | double lng = startLong + Math.atan2(Math.sin(angle)*Math.sin(δ)*Math.cos(startLat),Math.cos(δ)-Math.sin(startLat)*Math.sin(lat)); |
| | | double lat = Math.asin(Math.sin(startLat) * Math.cos(δ) + Math.cos(startLat) * Math.sin(δ) * Math.cos(angle)); |
| | | double lng = startLong + Math.atan2(Math.sin(angle) * Math.sin(δ) * Math.cos(startLat), Math.cos(δ) - Math.sin(startLat) * Math.sin(lat)); |
| | | // 转为正常的10进制经纬度 |
| | | lng = Math.toDegrees(lng); |
| | | lat = Math.toDegrees(lat); |