package com.zhgd.xmgl.util; import lombok.extern.slf4j.Slf4j; /** * @program: wisdomSite * @description: 风向 * @author: Mr.Peng * @create: 2020-10-12 15:57 **/ @Slf4j public class WindDirectionUtils { public static String getWindDirectionName(String winddirection) { String winddirectionName = ""; try { if (winddirection.indexOf("S") != -1 || winddirection.indexOf("E") != -1 || winddirection.indexOf("N") != -1 || winddirection.indexOf("W") != -1) { if ("NNE".equals(winddirection)) { winddirectionName = "东北偏北"; } else if ("NE".equals(winddirection)) { winddirectionName = "东北"; } else if ("ENE".equals(winddirection)) { winddirectionName = "东北偏东"; } else if ("E".equals(winddirection)) { winddirectionName = "正东"; } else if ("ESE".equals(winddirection)) { winddirectionName = "东南偏东"; } else if ("SE".equals(winddirection)) { winddirectionName = "东南"; } else if ("SSE".equals(winddirection)) { winddirectionName = "东南偏南"; } else if ("S".equals(winddirection)) { winddirectionName = "正南"; } else if ("SSW".equals(winddirection)) { winddirectionName = "正南偏南"; } else if ("SW".equals(winddirection)) { winddirectionName = "西南"; } else if ("WSW".equals(winddirection)) { winddirectionName = "西南偏西"; } else if ("W".equals(winddirection)) { winddirectionName = "正西"; } else if ("WNW".equals(winddirection)) { winddirectionName = "西北偏西"; } else if ("NW".equals(winddirection)) { winddirectionName = "西北"; } else if ("NNW".equals(winddirection)) { winddirectionName = "西北偏北"; } else if ("N".equals(winddirection)) { winddirectionName = "正北"; } } else if (isChinese(winddirection)) { winddirectionName = winddirection; } else { double winddirections = Double.parseDouble(winddirection); if (337.5 < winddirections || winddirections <= 22.5) { winddirectionName = "北"; } else if (22.5 < winddirections && winddirections <= 67.5) { winddirectionName = "东北"; } else if (67.5 < winddirections && winddirections <= 112.5) { winddirectionName = "东"; } else if (112.5 < winddirections && winddirections <= 157.5) { winddirectionName = "东南"; } else if (157.5 < winddirections && winddirections <= 202.5) { winddirectionName = "南"; } else if (202.5 < winddirections && winddirections <= 247.5) { winddirectionName = "西南"; } else if (247.5 < winddirections && winddirections <= 292.5) { winddirectionName = "西"; } else if (292.5 < winddirections && winddirections <= 337.5) { winddirectionName = "西北"; } } } catch (Exception e) { log.error("err:", e); } return winddirectionName; } /** * 判断该字符串是否为中文 * * @param string * @return */ public static boolean isChinese(String string) { int n = 0; for (int i = 0; i < string.length(); i++) { n = (int) string.charAt(i); if (!(19968 <= n && n < 40869)) { return false; } } return true; } }