wuww
2025-05-06 378a66a369b27ba35dc1d4d1cbddd90b626d7046
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package com.se.nsl;
 
import com.se.nsl.domain.po.Region;
import com.se.nsl.helper.GdalHelper;
import com.se.nsl.mapper.RegionMapper;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.Driver;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.gdal.gdalconst.gdalconstConstants;
import org.gdal.ogr.*;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
 
import com.alibaba.fastjson.JSONObject;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class AppTest {
    @Resource
    RegionMapper regionMapper;
 
    @Test
    public void test() {
        System.out.println("> test ----------------------");
        //procDepthFiles();
        //readZarr();
        //collectPngToList();
 
        SimpleDateFormat YYYYMMDDHHMM = new SimpleDateFormat("yyyy MM dd HH mm ");
        System.out.println(YYYYMMDDHHMM.format(new Date()));
 
        SimpleDateFormat YYYYMDHM = new SimpleDateFormat("yyyy M d H m ");
        System.out.println(YYYYMDHM.format(new Date()));
    }
 
    private void procDepthFiles() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(2025 - 1900, 4 - 1, 21, 0, 0, 0));
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
 
        String oldPath = "D:\\other\\simu\\uwsolver\\chicago";
        String newPath = "D:\\other\\simu\\uwsolver\\chicago\\depth";
        for (File file : new File(oldPath).listFiles()) {
            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, 1);
            String newName = df.format(calendar.getTime());
            String newFile = newPath + File.separator + newName + ".tif";
 
            System.out.println(newFile);
            tif.renameTo(new File(newFile));
            file.delete();
        }
    }
 
    //@Test
    public void collectPngToList() {
        System.out.println("------------------------------------------- start");
        int size = 1024;
        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;
 
            File pngFile = new File(file.getPath() + File.separator + size + "_" + size + ".png");
            if (!pngFile.exists() || pngFile.isDirectory()) continue;
 
            list.add("file '" + pngFile.getPath().replace("\\", "/") + "'");
            System.out.println(list.get(list.size() - 1));
        }
 
        Path path = Paths.get(outputPath + File.separator + "list.txt");
        try {
            Files.write(path, list, StandardCharsets.UTF_8);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("------------------------------------------- end");
    }
 
    //@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";
 
        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) {
                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();
        }
    }
}