王强
侠客
侠客
  • UID49
  • 粉丝0
  • 关注0
  • 发帖数7
阅读:5265回复:1

根据风速风向获取风向杆图标

楼主#
更多 发布于:2021-01-28 10:23
wind.zip

package com.sunsheen.xxzc.dchs.componentlib.common.stationproduct;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;


import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


import com.sunsheen.xxzc.dchs.componentlib.common.cimiss.CimissUtils;


public class AddWindImgUtils {
 /**
  * 从CIMISS查询瞬时风向、瞬时风速
  */
 public static Map<String, Object> getRelateWindByCimiss(String time) {
 String urlTemp = "http://10.203.89.55/cimiss-web/api?userId=BEGY_XXZX_SJFW_API&pwd=qwertyasdfghpassw0rd&interfaceId=getSurfEleByTime&dataCode=SURF_CHN_MUL_HOR&elements=Station_Id_d,Lat,Lon,WIN_D_INST,WIN_S_INST&times="
 + time + "&eleValueRanges=Province:贵州省&dataFormat=json";
 // 从数据源中查询数据
 StringBuffer sb = CimissUtils.getDataByUrl(urlTemp);
 JSONObject dataJsonObj = JSONObject.fromObject(sb.toString());
 Map<String, Object> retMap = new HashMap<String, Object>();
 if (!"0".equals(dataJsonObj.get("returnCode"))) { // 取数据失败
 retMap.put("retcode", "0");
 retMap.put("retmsg", "从CIMISS中获取数据失败!");
 } else {
 retMap.put("retcode", "1");
 // retMap.put("DS", dataJsonObj.get("DS"));
 // System.out.print(dataJsonObj);
 JSONArray ds = (JSONArray) dataJsonObj.get("DS");
 List<Map<String, String>> tempData = ds.toList(ds, Map.class);
 List<Map<String, String>> externslist = new ArrayList<>();
 for (Map<String, String> map : tempData) {
 // "WIN_D_INST":"40","WIN_S_INST":"3.5"
 String string = map.get("Station_Id_d");
 String lon = map.get("Lon");
 String lat = map.get("Lat");
 if (isCountry(string)) {// 站号是否为国家站
 Map<String, String> hashMap = new HashMap<>();
 hashMap.put("lon", lon);
 hashMap.put("lat", lat);
 String speed = map.get("WIN_S_INST");
 String Wind_D = map.get("WIN_D_INST");
 String img = getImgeName(speed, Wind_D);
 hashMap.put("value", img);
 externslist.add(hashMap);
 }
 }
 retMap.put("DS", externslist);
 }
 return retMap;
 }


 private static boolean isCountry(String string) {
 // 国家站就是5个数字
 boolean flag = false;
 Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
 if (string.length() == 5 && pattern.matcher(string).matches()) {
 flag = true;
 }
 return flag;
 }


 /**
  * 风向
  */
 public static String getChineseName(String Wind_D) {
 int value = (int) (Math.round((Double.valueOf(Wind_D))) / 5.0) * 5;
 String wind = null;
 if (value == 0 || value == 360) {
 wind = "北风";
 } else if (value > 0 && value < 45) {
 wind = "北东北风";
 } else if (value == 45) {
 wind = "东北风";
 } else if (value > 45 && value < 90) {
 wind = "东东北风";
 } else if (value == 90) {
 wind = "东风";
 } else if (value > 90 && value < 135) {
 wind = "东东南风";
 } else if (value == 135) {
 wind = "东南风";
 } else if (value > 135 && value < 180) {
 wind = "南东南风";
 } else if (value == 180) {
 wind = "南风";
 } else if (value > 180 && value < 225) {
 wind = "南西南风";
 } else if (value == 225) {
 wind = "西南风";
 } else if (value > 225 && value < 270) {
 wind = "西西南风";
 } else if (value == 270) {
 wind = "西";
 } else if (value > 270 && value < 315) {
 wind = "西西北风";
 } else if (value == 315) {
 wind = "西北风";
 } else if (value > 315 && value < 360) {
 wind = "北西北风";
 }


 return wind;
 }


 /**
  * 风速
  *
  * @param speed
  * @return
  */
 public static String getWindSpeed(String speed) {
 double value = (Math.round((Double.valueOf(speed))) / 5.0) * 5;
 String WindSpeed = null;
 if (value > 0.00 && value <= 0.200) {
 WindSpeed = "0";
 } else if (value >= 0.300 && value <= 1.5000) {
 WindSpeed = "1";
 } else if (value >= 1.600 && value <= 3.3000) {
 WindSpeed = "2";
 } else if (value >= 3.40000 && value <= 5.4000) {
 WindSpeed = "3";
 } else if (value >= 5.50000 && value <= 7.90000) {
 WindSpeed = "4";
 } else if (value >= 8.000 && value <= 10.700) {
 WindSpeed = "5";
 } else if (value >= 10.800 && value <= 13.800) {
 WindSpeed = "6";
 } else if (value >= 13.900 && value <= 17.100) {
 WindSpeed = "7";
 } else if (value >= 17.200 && value <= 20.700) {
 WindSpeed = "8";
 } else if (value >= 20.800 && value <= 24.400) {
 WindSpeed = "9";
 } else if (value >= 24.500 && value <= 28.400) {
 WindSpeed = "10";
 } else if (value >= 28.500 && value <= 32.600) {
 WindSpeed = "11";
 } else if (value >= 32.700 && value <= 36.900) {
 WindSpeed = "12";
 } else if (value >= 37.000 && value <= 41.400) {
 WindSpeed = "13";
 } else if (value >= 41.500 && value <= 46.100) {
 WindSpeed = "14";
 } else if (value >= 46.200 && value <= 50.900) {
 WindSpeed = "15";
 } else if (value >= 51.000 && value <= 56.000) {
 WindSpeed = "16";
 } else if (value >= 56.100) {
 WindSpeed = "17";
 } else {
 WindSpeed = "1";
 }
 return WindSpeed;
 }


 /**
  * 根据风速风向获取图片的名字
  *
  * @param value
  * @param valueDer
  * @return
  */
 public static String getImgeName(String value, String valueDer) {
 String imge = null;
 if (value != null && valueDer != null) {
 int fengxiang = (int) (Math.round((Double.valueOf(valueDer))) / 5.0) * 5;
 // 缺测
 if (fengxiang > 360) {
 return null;
 }
 if (fengxiang == 360) {
 fengxiang = 0;
 }
 imge = String.valueOf(fengxiang) + "-";
 String gan = null;
 double fengsu = Double.valueOf(value);
 if (fengsu == 0 && fengxiang == 0) {
 gan = "null";
 return null;
 } else if (fengsu <= 1) {
 gan = "0";
 } else if (fengsu <= 2) {
 gan = "1";
 } else if (fengsu <= 4) {
 gan = "2";
 } else if (fengsu <= 6) {
 gan = "3";
 } else if (fengsu <= 8) {
 gan = "4";
 } else if (fengsu <= 10.7) {
 gan = "5";
 } else if (fengsu <= 13.8) {
 gan = "6";
 } else if (fengsu <= 17.1) {
 gan = "7";
 } else if (fengsu <= 20.7) {
 gan = "8";
 } else if (fengsu <= 24.4) {
 gan = "8";
 } else if (fengsu <= 28.4) {
 gan = "8";
 } else if (fengsu <= 32.6) {
 gan = "8";
 } else if (fengsu > 9999) {
 return null;
 } else {
 gan = "8";
 }
 imge = imge + gan + ".png";
 }
 return imge;
 }
}
何圆
管理员
管理员
  • UID3
  • 粉丝18
  • 关注6
  • 发帖数291
  • 社区居民
  • 忠实会员
  • 原创写手
沙发#
发布于:2021-01-30 01:23
游客

返回顶部