| | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | |
| | | @SuppressWarnings("ALL") |
| | | public class SimuService { |
| | | public static final String TIF_EXTSION = ".tif"; |
| | | public static final String YYYY_MM_DD_HHMMSS = "yyyyMMddHHmmss"; |
| | | @Resource |
| | | SimuMapper simuMapper; |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | public List<SimuResult> queryByPosition(double lon, double lat, String serviceName) { |
| | | //transform coordiante from 4326 to 4548 |
| | | double[] xy = CoordinateTransformer.transform(4326, 4548, lon, lat); |
| | | // System.out.println(String.format("转换前的坐标:x:%s,y:%s", lon, lat)); |
| | | // System.out.println(String.format("转换后的坐标:x:%s,y:%s", xy[0], xy[1])); |
| | | //read from zarr |
| | | // return queryByZarr(xy, time, serviceName); |
| | | |
| | | //read from tif file |
| | | return queryByTif(xy, serviceName); |
| | | |
| | | } |
| | | |
| | | private SimuResult queryByZarr(double[] xy, long time, String serviceName) { |
| | | double x = xy[0]; |
| | | double y = xy[1]; |
| | |
| | | SimuResult result = new SimuResult(); |
| | | result.setDepth(depth); |
| | | result.setVelocity(velocity); |
| | | result.setTime(time); |
| | | return result; |
| | | } |
| | | |
| | | private List<SimuResult> queryByTif(double[] xy, String serviceName) { |
| | | double x = xy[0]; |
| | | double y = xy[1]; |
| | | List<SimuResult> res = new ArrayList<>(); |
| | | File inPath = new File(config.getInPath()); |
| | | Path depthPath = Paths.get(inPath.getAbsolutePath(), serviceName, "depth"); |
| | | File depthDir = depthPath.toFile(); |
| | | File[] files = depthDir.listFiles(); |
| | | for (File tifFile : files) { |
| | | ColumnRow cr = getColumnRow(tifFile, x, y); |
| | | if (cr == null) continue; |
| | | float depth = readPixelValue(cr.dataset, cr.col, cr.row, 1); |
| | | float velocity = calcVelocity(cr.dataset, cr.col, cr.row); |
| | | SimuResult result = new SimuResult(); |
| | | result.setDepth(depth); |
| | | result.setVelocity(velocity); |
| | | String time = tifFile.getName().replace(".tif", ""); |
| | | result.setTime(TimeFormatUtil.toMillis(time, YYYY_MM_DD_HHMMSS)); |
| | | res.add(result); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | private static ColumnRow getColumnRow(File tifFile, double x, double y) { |
| | |
| | | } |
| | | |
| | | private String formatTime(long time) { |
| | | // Instant instant = Instant.ofEpochMilli(time); |
| | | // LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); |
| | | // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | // return localDateTime.format(formatter); |
| | | return TimeFormatUtil.formatTime(time, "yyyyMMddHHmmss"); |
| | | return TimeFormatUtil.formatTime(time, YYYY_MM_DD_HHMMSS); |
| | | } |
| | | |
| | | } |