-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadDEM.java
More file actions
63 lines (56 loc) · 2.02 KB
/
Copy pathReadDEM.java
File metadata and controls
63 lines (56 loc) · 2.02 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
package heyingzhe;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
// 读取dem数据
public class ReadDEM {
private String filepath;
private int ncols;
private int nrows;
private double xllcorner;
private double yllcorner;
private double cellsize;
private int NODATA_value;
private int[][] data;
// 构造函数,输入文件路径
public ReadDEM(String filepath) throws IOException {
this.filepath = filepath;
this.data = readData();
}
// 返回dem数组
public int[][] getData() {
return data;
}
// 读取dem数据中的网格数据和dem数据
public int[][] readData() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(filepath));
ncols = Integer.parseInt(reader.readLine().split("\\s+")[1]);
nrows = Integer.parseInt(reader.readLine().split("\\s+")[1]);
xllcorner = Double.parseDouble(reader.readLine().split("\\s+")[1]);
yllcorner = Double.parseDouble(reader.readLine().split("\\s+")[1]);
cellsize = Double.parseDouble(reader.readLine().split("\\s+")[1]);
NODATA_value = Integer.parseInt(reader.readLine().split("\\s+")[1]);
data = new int[nrows][ncols];
for (int i = 0; i < nrows; i++) {
String[] line = reader.readLine().split(" ");
for (int j = 0; j < ncols; j++) {
data[i][j] = Integer.parseInt(line[j]);
}
}
reader.close();
return data;
}
// 打印网格数据
public void getProperty() {
System.out.println(ncols + " " + nrows + " " + xllcorner + " " + yllcorner + " " + cellsize + " " + NODATA_value);
}
// 打印dem数组
public void printData() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
System.out.print(data[i][j] + "\t");
}
System.out.println();
}
}
}