dcb
2025-07-14 0e6106783b59c2c4e173ad4b709c1415686e7505
src/test/java/com/se/nsl/AppTest.java
@@ -3,7 +3,6 @@
import com.se.nsl.domain.po.Region;
import com.se.nsl.helper.GdalHelper;
import com.se.nsl.mapper.RegionMapper;
import javafx.scene.input.DataFormat;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.Driver;
import org.gdal.gdal.gdal;
@@ -39,71 +38,45 @@
    RegionMapper regionMapper;
    @Test
    public void insertRegion() {
        GdalHelper.init("D:\\soft\\release-1928-x64-dev\\release-1928-x64\\bin");
        String path = "D:\\Documents\\WeChat Files\\wxid_llap8o5q8rm521\\FileStorage\\File\\2025-04\\孙胡沟geometry.json";
    public void test() {
        System.out.println("> test ----------------------");
        //procDepthFiles();
        //readZarr();
        //collectPngToList();
        org.gdal.ogr.Driver driver = ogr.GetDriverByName("GeoJSON");
        if (null == driver) return;
        SimpleDateFormat YYYYMMDDHHMM = new SimpleDateFormat("yyyy MM dd HH mm ");
        System.out.println(YYYYMMDDHHMM.format(new Date()));
        DataSource ds = driver.Open(path);
        if (null == ds) return;
        List<Region> list = new ArrayList<>();
        for (int i = 0, c = ds.GetLayerCount(); i < c; i++) {
            Layer layer = ds.GetLayer(i);
            for (long j = 0, d = layer.GetFeatureCount(); j < d; j++) {
                Feature f = layer.GetFeature(j);
                Geometry g = f.GetGeometryRef();
                if (null != g) { //  && (g.GetGeometryType() == ogr.wkbPolygon || g.GetGeometryType() == ogr.wkbMultiPolygon)
                    list.add(new Region(f.GetFieldAsString(""), (short) 3, g.ExportToWkt()));
                }
            }
        }
        if (list.size() > 0) {
            regionMapper.inserts(list);
        }
        ds.delete();
        driver.delete();
        System.out.println("hello world");
        SimpleDateFormat YYYYMDHM = new SimpleDateFormat("yyyy M d H m ");
        System.out.println(YYYYMDHM.format(new Date()));
    }
    //@Test
    public void procDepthFiles() {
        String path = "D:\\other\\simu\\uwsolver\\20250412\\depth";
        /*for (File file : new File(path).listFiles()) {
            if (!file.exists() || !file.isDirectory()) continue;
            File tif = new File(path + "\\" + file.getName() + "\\depth.tif");
            if (!tif.exists() || tif.isDirectory()) continue;
            File newFile = new File(path + "\\2025041200" + file.getName() + ".tif");
            System.out.println(newFile.getPath());
            tif.renameTo(newFile);
            file.delete();
        }*/
    private void procDepthFiles() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(2025 - 1900, 3, 12, 0, 0, 0));
        calendar.setTime(new Date(2025 - 1900, 4 - 1, 21, 0, 0, 0));
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String oldPath = "D:\\other\\simu\\uwsolver\\20250412\\depth-old";
        String newPath = "D:\\other\\simu\\uwsolver\\20250412\\depth";
        String oldPath = "D:\\other\\simu\\uwsolver\\chicago";
        String newPath = "D:\\other\\simu\\uwsolver\\chicago\\depth";
        for (File file : new File(oldPath).listFiles()) {
            String fileName = file.getName().replace("2025041200", "").replace(".tif", "");
            int second = Integer.parseInt(fileName);
            if (!file.exists() || !file.isDirectory()) continue;
            File tif = new File(oldPath + "\\" + file.getName() + "\\depth.tif");
            if (!tif.exists() || tif.isDirectory()) continue;
            //String fileName = file.getName().replace("2025041200", "").replace(".tif", "");
            /*int second = Integer.parseInt(fileName);
            calendar.set(Calendar.SECOND, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.HOUR, 0);
            calendar.add(Calendar.SECOND, second);
            calendar.add(Calendar.SECOND, second);*/
            calendar.add(Calendar.SECOND, 1);
            String newName = df.format(calendar.getTime());
            String newFile = newPath + File.separator + newName + ".tif";
            System.out.println(newFile);
            file.renameTo(new File(newFile));
            tif.renameTo(new File(newFile));
            file.delete();
        }
    }
@@ -111,7 +84,7 @@
    public void collectPngToList() {
        System.out.println("------------------------------------------- start");
        int size = 1024;
        String outputPath = "D:\\other\\simu\\out\\20250412\\waters";
        String outputPath = "D:\\other\\simu\\out\\chicago96\\waters"; // ""D:\\other\\simu\\out\\20250412\\waters";
        List<String> list = new ArrayList<>();
        for (File file : new File(outputPath).listFiles()) {
            if (!file.exists() || file.isFile()) continue;
@@ -133,39 +106,72 @@
    }
    //@Test
    public void readZarr() throws Exception {
    public void insertRegion() {
        GdalHelper.init("D:\\soft\\release-1928-x64-dev\\release-1928-x64\\bin");
        String path = "D:\\Documents\\WeChat Files\\wxid_llap8o5q8rm521\\FileStorage\\File\\2025-04\\孙胡沟geometry.json";
        String zarrPath = "D:\\other\\simu\\CudaUWSolver.zarr";
        org.gdal.ogr.Driver driver = ogr.GetDriverByName("GeoJSON");
        if (null == driver) return;
        DataSource ds = driver.Open(path);
        if (null == ds) return;
        List<Region> list = new ArrayList<>();
        for (int i = 0, c = ds.GetLayerCount(); i < c; i++) {
            Layer layer = ds.GetLayer(i);
            for (long j = 0, d = layer.GetFeatureCount(); j < d; j++) {
                Feature f = layer.GetFeature(j);
                Geometry g = f.GetGeometryRef();
                if (null != g) { //  && (g.GetGeometryType() == ogr.wkbPolygon || g.GetGeometryType() == ogr.wkbMultiPolygon)
                    list.add(new Region(f.GetFieldAsString(""),  3, g.ExportToWkt()));
                }
            }
        }
        if (list.size() > 0) {
            regionMapper.inserts(list);
        }
        ds.delete();
        driver.delete();
        System.out.println("hello world");
    }
    //@Test
    public void readZarr() {
        //GdalHelper.init("D:\\soft\\release-1928-x64-dev\\release-1928-x64\\bin");
        //GdalHelper.init("C:\\Program Files\\GDAL");
        /*try {
            System.setProperty("java.library.path", "C:\\Program Files\\GDAL");
            java.lang.reflect.Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
            fieldSysPath.setAccessible(true);
            fieldSysPath.set(null, null);
            //System.load("C:\\Program Files\\GDAL\\gdaljni.dll");
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        gdal.AllRegister();
        System.out.println("GDAL Initialized. Version: " + gdal.VersionInfo("RELEASE_NAME"));
        String zarrPath = "D:\\other\\simu\\out\\out.zarr"; // "D:\\other\\simu\\out\\CudaUWSolver.zarr";
        Dataset ds = null;
        try {
            Driver driver = gdal.GetDriverByName("Zarr");
            ds = gdal.Open(zarrPath, gdalconst.GA_ReadOnly);
            if (null == ds || ds.getRasterCount() < 1) return;
            System.out.println(ds.getRasterCount());
            if (null == ds || ds.getRasterCount() < 1) {
                System.err.println("Could not open input dataset: " + zarrPath);
                return;
            }
            System.out.println("Successfully opened...");
            System.out.println("Driver: " + ds.GetDriver().getShortName() + "/" + ds.GetDriver().getLongName());
            System.out.println("Size: " + ds.getRasterXSize() + " - " + ds.getRasterYSize() + " - " + ds.getRasterCount());
        } finally {
            if (null != ds) ds.delete();
        }
    }
    //@Test
    public void readZarr2() throws Exception {
        String zarrInputPath = "D:\\other\\simu\\out\\out.zarr";
        gdal.AllRegister();
        System.out.println("GDAL Initialized. Version: " + gdal.VersionInfo("RELEASE_NAME"));
        Dataset inputDataset = gdal.Open(zarrInputPath, gdalconst.GA_ReadOnly);
        if (inputDataset == null) {
            System.err.println("Could not open input dataset: " + zarrInputPath);
            return;
        }
        System.out.println("Successfully opened");
        System.out.println(
                "Driver: " + inputDataset.GetDriver().getShortName() + "/" + inputDataset.GetDriver().getLongName());
        System.out.println("Size: " + inputDataset.getRasterXSize() + "x" + inputDataset.getRasterYSize() + "x"
                + inputDataset.getRasterCount());
    }
}