src/main/java/com/se/nsl/config/PropertiesConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/nsl/service/ResolveService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/nsl/service/SimuService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/nsl/utils/AreaType.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application-dev.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/se/nsl/config/PropertiesConfig.java
@@ -98,6 +98,8 @@ private Integer epsg; private String keyDitch; public String getVer() { return ver; } @@ -453,4 +455,12 @@ public void setLanduseFile(String landuseFile) { this.landuseFile = landuseFile; } public String getKeyDitch() { return keyDitch; } public void setKeyDitch(String keyDitch) { this.keyDitch = keyDitch; } } src/main/java/com/se/nsl/service/ResolveService.java
@@ -14,6 +14,7 @@ import com.se.nsl.helper.GdalHelper; import com.se.nsl.helper.StringHelper; import com.se.nsl.helper.WebHelper; import com.se.nsl.utils.AreaType; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.gdal.gdal.Band; @@ -154,6 +155,29 @@ createDir(inPath + File.separator + "velocity"); createDir(config.getOutPath() + File.separator + data.getOutPath()); Short areaType = simu.getAreaType(); AreaType at = AreaType.of(areaType); String terrainTif = config.getSourceDem(); String landuseTif = config.getSourceLanduse(); if (at == AreaType.KEY_DITCH) { File keyDitchDir = new File(config.getKeyDitch()); String areaName = simu.getAreaName(); Optional<File> first = Arrays.stream(keyDitchDir.listFiles()).filter(f -> f.getName().equals(areaName)).findFirst(); if (first.isPresent()) { File targetTifDir = first.get(); File[] files = targetTifDir.listFiles(); for (File file : files) { String name = file.getName(); if (name.toLowerCase().contains("dem")) { terrainTif = file.getAbsolutePath(); } if (name.toLowerCase().contains("landuse")) { landuseTif = file.getAbsolutePath(); } } } } Geometry geom = Geometry.CreateFromWkt(simu.getGeom()); if (geom.GetGeometryType() == ogr.wkbMultiPolygon) geom = geom.GetGeometryRef(0); SpatialReference dstSR = GdalHelper.createSpatialReference(config.getEpsg()); @@ -163,12 +187,14 @@ String wkt = geom.ExportToWkt(); String terrainFile = inPath + File.separator + config.getTerrainFile(); Dataset dsDem = gdal.Open(config.getSourceDem(), gdalconstConstants.GA_ReadOnly); Dataset dsDem = gdal.Open(terrainTif, gdalconstConstants.GA_ReadOnly); ComHelper.Resample(dsDem, null, terrainFile, null, wkt, null, null); dsDem.delete(); String landuseFile = inPath + File.separator + config.getLanduseFile(); Dataset dsLanduse = gdal.Open(config.getSourceLanduse(), gdalconstConstants.GA_ReadOnly); Dataset dsLanduse = gdal.Open(landuseTif, gdalconstConstants.GA_ReadOnly); ComHelper.Resample(dsLanduse, null, landuseFile, null, wkt, null, null); dsLanduse.delete(); } src/main/java/com/se/nsl/service/SimuService.java
@@ -134,7 +134,7 @@ // 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 null; // return queryByZarr(xy, time, serviceName); //read from tif file return queryByTif(xy, time, serviceName); @@ -146,28 +146,29 @@ double y = xy[1]; String prefix = formatTime(time); File inPath = new File(config.getInPath()); File tifDir = new File(inPath, serviceName + File.separator + "depth"); int index = 0; File[] files = tifDir.listFiles(); for (File file : files) { String name = file.getName(); if (!name.endsWith(TIF_EXTSION)) continue; if (name.equals(prefix + TIF_EXTSION)) { break; } index++; } //TODOéè¦è®¡ç®è¡åå· int col = 0; int row = 0; // File tifDir = new File(inPath, serviceName + File.separator + "depth"); // int index = 0; // File[] files = tifDir.listFiles(); // for (File file : files) { // String name = file.getName(); // if (!name.endsWith(TIF_EXTSION)) continue; // if (name.equals(prefix + TIF_EXTSION)) { // break; // } // index++; // } File dem = new File(inPath, serviceName + File.separator + "DEM.tif"); ColumnRow cr = getColumnRow(dem.getAbsoluteFile(), x, y); if (cr == null) return null; File zarr = new File(inPath, serviceName + File.separator + "result.zarr"); try { ZarrGroup group = ZarrGroup.open(zarr.toPath()); ZarrArray depthArray = group.openArray("depth"); Object object = depthArray.read(); System.out.println(object); int[] shape = new int[] {60, 637, 351}; // int[] offset = new int[]{210, 384}; float[] depth = (float[]) depthArray.read(shape); System.out.println("depth:" + depth.length); } catch (IOException | InvalidRangeException e) { throw new RuntimeException(e); } @@ -187,6 +188,18 @@ return null; } ColumnRow cr = getColumnRow(tifFile, x, y); if (cr == null) return null; System.out.println("col:" + cr.col + " ,row:" + cr.row); 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); return result; } private static ColumnRow getColumnRow(File tifFile, double x, double y) { Dataset dataset = gdal.Open(tifFile.getAbsolutePath(), gdalconstConstants.GA_ReadOnly); // è·åå°ç忢忰ï¼6å ç´ æ°ç»ï¼ // [0]: å·¦ä¸è§Xåæ , [1]: åå 宽度, [2]: Xæ¹åæè½¬, @@ -201,12 +214,19 @@ log.warn("è¡åå·ä¸å¨tifèå´å "); return null; } float depth = readPixelValue(dataset, col, row, 1); float velocity = calcVelocity(dataset, col, row); SimuResult result = new SimuResult(); result.setDepth(depth); result.setVelocity(velocity); return result; return new ColumnRow(dataset, col, row); } private static class ColumnRow { public final Dataset dataset; public final int col; public final int row; public ColumnRow(Dataset dataset, int col, int row) { this.dataset = dataset; this.col = col; this.row = row; } } private float calcVelocity(Dataset dataset, int col, int row) { src/main/java/com/se/nsl/utils/AreaType.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,28 @@ package com.se.nsl.utils; /** * åºåç±»å */ public enum AreaType { CUSTOM(0), ADMINISTRATIVE_AREA(1), KEY_AREA(2), KEY_DITCH(3); private int val; AreaType(int val) { this.val = val; } public static AreaType of(int val) { AreaType[] values = values(); for (AreaType type : values) { if (type.val == val) { return type; } } return AreaType.ADMINISTRATIVE_AREA; } } src/main/resources/application-dev.yml
@@ -169,3 +169,6 @@ sourceLanduse: D:\other\simu\CudaUWSolver-2.0\Beijing-Data-10m\Beijing-4548-Landuse-10m-Nonodata.tif copyTif: false tifPath: D:\other\simu\uwsolver\5ca43c87cd8e48c5a9c5399a5da46dbc\tongzhou_raster_4548_1m_clip_river_fill.tif #tifä¸çé«ç¨æä»¶åè¦å«ædemï¼åå°å©ç¨è¦å«ælanduseï¼ç«ç¹è¦å«æstationï¼ä¸éå¶å¤§å°åï¼æåå°½éç¨è±æåæ¯è¡¨è¾¾ keyDitch: D:\other\simu\CudaUWSolver-2.0\KeyDitch