-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccFlowThread.java
More file actions
90 lines (82 loc) · 3.69 KB
/
Copy pathAccFlowThread.java
File metadata and controls
90 lines (82 loc) · 3.69 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package heyingzhe;
import java.io.IOException;
import java.nio.file.Paths;
import java.sql.SQLException;
public class AccFlowThread extends Thread {
private int[][] dem;
private int[][] filledDem;
private int[][] flowDirectionArray;
private double[][] idwInterpolationResult;
private String outPutDirectory;
private String outputAccFlowPath;
private String outputWaterAreaPath;
private String dbUserName;
private String dbPassword;
public AccFlowThread(int[][] dem, int[][] filledDem, int[][] flowDirectionArray, double[][] idwInterpolationResult, String outPutDirectory, String outputAccFlowPath, String outputWaterAreaPath, String dbUserName, String dbPassword) {
this.dem = dem;
this.filledDem = filledDem;
this.flowDirectionArray = flowDirectionArray;
this.idwInterpolationResult = idwInterpolationResult;
this.outPutDirectory = outPutDirectory;
this.outputAccFlowPath = outputAccFlowPath;
this.outputWaterAreaPath = outputWaterAreaPath;
this.dbUserName = dbUserName;
this.dbPassword = dbPassword;
}
public void run() {
//计算累积流数组
System.out.println("正在进行累积流计算……");
CalculateAccumulatedFlow accCalculation = new CalculateAccumulatedFlow(dem); //计算累计流
double[][] flowAccumulation = accCalculation.calculateFlow(flowDirectionArray, idwInterpolationResult, filledDem);
System.out.println("累积流计算完成");
//将累积流数组输出为图片
ImageVisualizer imageVision = new ImageVisualizer();
imageVision.convertFlowAccumulationToImage(flowAccumulation, 10);
try {
imageVision.saveImage(Paths.get(outPutDirectory, outputAccFlowPath).toString(), "png");
} catch (IOException e) {
throw new RuntimeException(e);
}
//根据海拔高度,输出水域图片
imageVision.createWaterAreaImage(filledDem, 250);
try {
imageVision.saveImage(Paths.get(outPutDirectory, outputWaterAreaPath).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", "accFlow"); //创建累积流表格
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
saveProcessing.saveArrayToAscFile(flowAccumulation, outPutDirectory, "accFlow.asc"); //保存为二进制文件
//saveProcessing.saveArrayToMySQL(flowAccumulation, "accFlow"); //上传至MySQL数据库
} catch (IOException e) {
throw new RuntimeException(e);
}
/*
catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}*/
System.out.println("累积流数据已经添加到数据库里面");
}
}