-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKrigThread.java
More file actions
74 lines (66 loc) · 2.84 KB
/
Copy pathKrigThread.java
File metadata and controls
74 lines (66 loc) · 2.84 KB
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
package heyingzhe;
import java.awt.Color;
import java.io.IOException;
import java.nio.file.Paths;
import java.sql.SQLException;
import static heyingzhe.KrigingInterpolation.krigingInterpolation;
public class KrigThread extends Thread {
private double[][] data;
private String outputPath;
private Color color1;
private Color color2;
private String outputKrigImage;
private String dbUserName;
private String dbPassword;
public KrigThread(double[][]data, String outputPath, String outputKrigImage, Color color1, Color color2, String dbUserName, String dbPassword) {
this.data = data;
this.outputPath = outputPath;
this.color1 = color1;
this.color2 = color2;
this.outputKrigImage = outputKrigImage;
this.dbUserName = dbUserName;
this.dbPassword = dbPassword;
}
public void run() {
System.out.println("正在进行克里金插值……");
double[][] krigingInterpolationResult = krigingInterpolation(data, 50, 900, 0.1); //克里金插值
System.out.println("克里金插值完成");
// 插值结果输出图片
ImageVisualizer imageVision = new ImageVisualizer();
imageVision.colorizeWithLevels(krigingInterpolationResult, color1, color2, 20);
try {
imageVision.saveImage(Paths.get(outputPath, outputKrigImage).toString(), "png");
} catch (IOException e) {
throw new RuntimeException(e);
}
//储存数据到数据库
SaveResult saveProcessing = new SaveResult();
// 配置数据库
saveProcessing.setMySQLProperty(dbUserName, dbPassword);
try {
saveProcessing.createDatabase("result");
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
System.out.println("克里金插值:数据库连接成功!");
System.out.println("正在将克里金插值结果上传至数据库……");
try {
saveProcessing.createTable("result", "krigInterpolation"); //创建krig表格
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
saveProcessing.saveArrayToAscFile(krigingInterpolationResult, outputPath, "krig.asc"); //保存为二进制文件
//saveProcessing.saveArrayToMySQL(krigingInterpolationResult, "krigInterpolation");
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("krig数据已经添加到数据库里面");
}
}