package com.yssh.utils;
|
|
import java.util.*;
|
|
import com.yssh.entity.MonitorPointPosition;
|
|
public class CalculateUtils {
|
|
/**
|
* @param @param x
|
* @param @param y
|
* @param @return 参数
|
* @return double 返回类型
|
* @throws
|
* @Title: getLon
|
* @Description: 计算经度
|
*/
|
public static double getLon(int x, int y) {
|
double lon = 115.9165227 + 0.000116732 * (x - 0.5) + 0.00000116862 * (y - 0.5);
|
if (lon < 115 || lon > 116) {
|
System.out.println("lon is invalid");
|
}
|
return lon;
|
}
|
|
/**
|
* @param @param x
|
* @param @param y
|
* @param @return 参数
|
* @return double 返回类型
|
* @throws
|
* @Title: getLat
|
* @Description: 计算维度
|
*/
|
public static double getLat(int x, int y) {
|
double lat = 39.77250000 + 0.000001000 * (x - 0.5) - 0.00009000000 * (y - 0.5);
|
if (lat < 39 || lat > 40) {
|
System.out.println("lat is invalid");
|
}
|
return lat;
|
}
|
|
/**
|
* @param @param checkPoints
|
* @param @return 参数
|
* @return List<String> 返回类型
|
* @throws
|
* @Title: assembleId
|
* @Description: 组装id
|
*/
|
public static List<String> assembleId(List<MonitorPointPosition> checkPoints) {
|
List<String> ids2d = new ArrayList<String>();
|
for (MonitorPointPosition point : checkPoints) {
|
ids2d.add(point.getX() + "_" + point.getY() + "_" + point.getZ());
|
}
|
return ids2d;
|
}
|
|
/**
|
* @param @param checkPoint
|
* @param @param range
|
* @param @return 参数
|
* @return List<String> 返回类型
|
* @Title: aloneCrosswiseScope
|
* @Description: 单独点位横向范围扩展
|
* @backup 强制将层级改为 0
|
*/
|
public static List<String> aloneCrosswiseExtend(MonitorPointPosition checkPoint, int range) {
|
List<String> ids = new ArrayList<String>();
|
Integer x = checkPoint.getX();
|
Integer y = checkPoint.getY();
|
for (int i = x - range / 2; i <= x + range / 2; i++) {
|
for (int j = y - range / 2; j <= y + range / 2; j++) {
|
// ids.add(i + "_" + j + "_" + checkPoint.getZ());
|
ids.add(i + "_" + j + "_" + 0);
|
}
|
}
|
return ids;
|
}
|
|
public static List<String> temporary(MonitorPointPosition point, int range) {
|
List<String> ids3d = new ArrayList<String>();
|
Integer x = point.getX();
|
Integer y = point.getY();
|
Integer z = point.getZ();
|
for (int i = x - range / 2; i <= x + range / 2; i++) {
|
for (int j = y - range / 2; j <= y + range / 2; j++) {
|
for (int k = z; k < 100; k++) {
|
ids3d.add(i + "_" + j + "_" + k);
|
}
|
}
|
}
|
return ids3d;
|
}
|
|
/**
|
* @param @return 参数
|
* @return Double 返回类型
|
* @throws
|
* @Title: getWindSpeed
|
* @Description: 计算风速
|
*/
|
public static Double getWindSpeed(double v, double u) {
|
return Math.sqrt(v * v + u * u);
|
}
|
|
/**
|
* @param @param v
|
* @param @param u
|
* @param @return 参数
|
* @return double 返回类型
|
* @throws
|
* @Title: getWindDirection
|
* @Description: 计算风向
|
*/
|
public static double getWindDirection(double v, double u) {
|
double result = Math.atan(u / (v + Math.pow(10, -5))) / Math.PI * 180;
|
if (result < 0) {
|
result += 180;
|
} else if (u < 0 && v > 0) {
|
result += 360;
|
}
|
return result;
|
}
|
|
/**
|
* @param @param list 排序对象
|
* @param @param property 排序参数
|
* @param @param order 排序顺序
|
* @param @return 参数
|
* @return List<Map < String, Object>> 返回类型
|
* @throws
|
* @Title: sort
|
* @Description: 排序
|
*/
|
public static List<Map<String, Object>> sort(List<Map<String, Object>> list, final String property, final boolean order) {
|
if (list == null || property == null) {
|
return null;
|
}
|
Collections.sort(list, new Comparator<Map<String, Object>>() {
|
@Override
|
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
|
try {
|
Object oo1 = o1.get(property);
|
Object oo2 = o2.get(property);
|
if (oo1 == null || "null".equals(oo1.toString()) || "".equals(oo1.toString()) || oo1.toString().endsWith("999")) {
|
oo1 = 0;
|
}
|
if (oo2 == null || "null".equals(oo2.toString()) || "".equals(oo2.toString()) || oo2.toString().endsWith("999")) {
|
oo2 = 0;
|
}
|
if (order) {
|
if (Double.parseDouble(oo1.toString()) < Double.parseDouble(oo2.toString())) {
|
return 1;
|
}
|
} else {
|
if (Double.parseDouble(oo1.toString()) > Double.parseDouble(oo2.toString())) {
|
return 1;
|
}
|
}
|
if (Double.parseDouble(oo1.toString()) == Double.parseDouble(oo2.toString())) {
|
return 0;
|
}
|
} catch (Exception ex) {
|
System.out.println(ex.getMessage());
|
}
|
return -1;
|
}
|
});
|
return list;
|
}
|
}
|