📄 getaverage.java
字号:
package net.aetherial.gis.baobu.GetAverage;
import java.io.File;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import net.aetherial.gis.publicuse.WptTrackDistance;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.our.FrameOur;
import net.aetherial.gis.output.FileOperate;
import net.aetherial.gis.output.toLd.OpenDirectory;
public class GetAverage {
// 获取所有县乡村道GPS文件
public File[] getAllGPSFiles(String filePath) {
OpenDirectory od = new OpenDirectory();
od.setGradeStr("县道|乡道");
File[] allFiles = od.getOpenFile(filePath);// 读取所有县道GPS文件
return allFiles;
}
//根据航迹获取航迹信息
public String [] getTrackLiChengAndValue(Node trackNode){
double sumLiCheng = 0.0;
int trackNodeInt = 0;
String [] temp = new String [6];
NodeList wayPointS = null;
double tempMaxValue = 0.0;
double tempMinValue = 9999.0;
double minValue = 9999.0;
double maxValue = 0.0;
sumLiCheng = Double.parseDouble(ItemValue.getTracksStringDistance(trackNode));
wayPointS = ItemValue.getTracksPoint(trackNode); //获取航迹点
if (wayPointS != null )
trackNodeInt = wayPointS.getLength();
else trackNodeInt = 0;
Node pointNode = null;
Node nextPointNode = null;
for (int j = 0; wayPointS != null && j < wayPointS.getLength() ; j++) {
pointNode = wayPointS.item(j);
if (tempMinValue > Double.parseDouble(ItemValue.getTracksPointZ(pointNode))){
tempMinValue = Double.parseDouble(ItemValue.getTracksPointZ(pointNode));
}
if (tempMaxValue < Double.parseDouble(ItemValue.getTracksPointZ(pointNode))){
tempMaxValue = Double.parseDouble(ItemValue.getTracksPointZ(pointNode));
}
if (j < wayPointS.getLength()-1){
nextPointNode = wayPointS.item(j+1);
if (minValue > ItemValue.getTrackPointDistance(pointNode,nextPointNode)){
minValue = ItemValue.getTrackPointDistance(pointNode,nextPointNode);
}
if (maxValue < ItemValue.getTrackPointDistance(pointNode,nextPointNode)){
maxValue = ItemValue.getTrackPointDistance(pointNode,nextPointNode);
}
}
}
temp[0] = "" + sumLiCheng ; //航迹里程
temp[1] = "" + trackNodeInt ;//航迹点个数
temp[2] = "" + tempMaxValue ; //航迹上最大高度
temp[3] = "" + tempMinValue; //航迹上最小高度
temp[4] = "" + maxValue ; //两点最大长度
temp[5] = "" + minValue ; //两点最小长度
return temp ;
}
//分县统计航点间距平均数、最大高度、最小高度
public void println(String filePath){
ItemValue.setShowDialogMessage(false);
FrameOur fo = new FrameOur();
File [] allFiles = getAllGPSFiles(filePath); //分县获取县乡道GPS数据
Node [] allTracks = null;
double sumCount = 0.0;
int trackNodeInt = 0;
String [] trackInfo = null;
double minValue = 9999.0;
double maxValue = 0.0;
double averageValue = 0.0;
double tempMinValue = 9999.0;
double tempMaxValue = 0.0;
String headStr = "";
String contentStr = "";
String tempPath = filePath.replace('\\', ',');
String[] paths = tempPath.split(",");
String quXianName = paths[ paths.length - 1]; // 区县名
String shiName = paths[ paths.length - 2]; // 市名
for (int i = 0; allFiles != null && i < allFiles.length ; i++){
File myFile = allFiles[i];
fo.openFile(myFile);
allTracks = ItemValue.getTracks();
trackNodeInt = 0;
minValue = 9999.0;
maxValue = 0.0;
averageValue = 0.0;
sumCount = 0.0;
tempMinValue = 9999.0;
tempMaxValue = 0.0;
for (int j = 0 ;allTracks != null && j < allTracks.length ; j++){
trackInfo = getTrackLiChengAndValue(allTracks[j]);
sumCount += Double.parseDouble(trackInfo[0]);
trackNodeInt += Integer.parseInt(trackInfo[1]);
if (maxValue < Double.parseDouble(trackInfo[2]) ){
maxValue = Double.parseDouble(trackInfo[2]);
}
if (minValue > Double.parseDouble(trackInfo[3])){
minValue = Double.parseDouble(trackInfo[3]) ;
}
if (tempMaxValue < Double.parseDouble(trackInfo[4]) ){
tempMaxValue = Double.parseDouble(trackInfo[4]);
}
if (tempMinValue > Double.parseDouble(trackInfo[5])){
tempMinValue = Double.parseDouble(trackInfo[5]) ;
}
}
averageValue = sumCount/trackNodeInt; //航迹点间平均间距
contentStr += shiName + "\t" + quXianName + "\t" + myFile.getName().substring(0,4) + "\t"+ trackNodeInt + "\t" + sumCount
+ "\t" + averageValue + "\t" + tempMaxValue + "\t" + tempMinValue + "\t" + maxValue + "\t" + minValue + "\r\n";
System.out.println("\t"+ trackNodeInt + "\t" + sumCount + "\t" + averageValue + "\t" + maxValue + "\t" + minValue );
fo.reset();
}
headStr = "市名\t县(区)名\t路线\t航点个数\t路线里程\t航点间平均间距\t两点间最长距离\t两点间最短距离\t最大高度\t最小高度\r\n"; //标题行
contentStr = headStr + contentStr ; //所有内容
FileOperate fileOperate = new FileOperate();
fileOperate.newFile("e:\\统计数据\\统计结果.txt",contentStr);//输出文件
}
public static void main(String [] args){
GetAverage ga = new GetAverage();
ga.println( "D:\\安徽省通达数据\\六安市\\霍山县");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -