⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countrytransfer.java

📁 基于Java的地图数据管理软件。使用MySQL数据库管理系统。
💻 JAVA
字号:
/*
 * 创建日期 2006-9-3
 * 作    者  朱 闰
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */

package net.aetherial.gis.baobu.countrytransfer;

import java.io.File;
import java.util.ArrayList;
import java.util.Vector;

import net.aetherial.gis.our.FrameOur;
import net.aetherial.gis.output.FileOperate;
import net.aetherial.gis.output.toLd.OpenDirectory;
import net.aetherial.gis.publicuse.WptTrackDistance;
import net.aetherial.gis.publicuse.track.ConcatenatedTrack;
import net.aetherial.gis.surface.ItemValue;

import org.w3c.dom.Node;

public class CountryTransfer {

	// 获取所有国省道GPS文件
	public File[] getAllGSFiles(String filePath) {
		OpenDirectory od = new OpenDirectory();
		od.setGradeStr("国道|省道");
		File[] allFiles = od.getOpenFile(filePath);// 读取所有国省道GPS文件
		return allFiles;
	}

	// 获取所有非国省道GPS文件
	public File[] getAllNotGSFile(String filePath) {
		OpenDirectory od = new OpenDirectory();
		od.setGradeStr("县道|乡道|村道|专用");
		File[] allFiles = od.getOpenFile(filePath);// 读取所有非国省道GPS文件
		return allFiles;
	}

	// 获取临时存放的已经删除国省道中航迹和非行政村航点的GPS文件
	public File[] getAllFile(String filePath) {
		OpenDirectory od = new OpenDirectory();
		od.setGradeStr("省道|");
		File[] allFiles = od.getOpenFile(filePath);
		return allFiles;
	}

	// 删除除行政村航点以外的所有航迹和航点,并保存至临时文件夹中
	public void RemoveTrackAndPoint(String filePath) {
		// File newFile=new File(filePath);
		String outPath = "D:\\测试用数据\\输出文件\\整理完毕\\省";
		File file = new File(outPath);
		FileOperate fileOperate = new FileOperate();
		if (file.exists()) {
			fileOperate.delFolder(outPath); // 如果有此文件夹就先删除此文件夹及所有文件
		}
		fileOperate.newFolder(outPath);

		ItemValue.setShowDialogMessage(false);
		FrameOur fo = new FrameOur();
		File[] allGSFile = getAllGSFiles(filePath);// 获取所有国省道GPS文件
		String lxNumber = "";
		String trackName = "";
		String pointName = "";
		String keyName = "";
		String pointValue = "";
		int n = 0;
		for (int p = 0; p < allGSFile.length; p++) {
			File myFile = allGSFile[p];
			String fileName = myFile.getName();
			fo.openFile(new File(myFile.getPath()));
			Node[] zr = ItemValue.getTracks();
			Node[] zr1 = ItemValue.getTracks();
			Node[] pointNodes = ItemValue.getWaypoint();
			n = 0;
			for (int j = 0; pointNodes != null && j < pointNodes.length; j++) {
				pointName = ItemValue.getWaypointName(pointNodes[j]);
				keyName = ItemValue.getWaypointKP(pointNodes[j]);
				if (!keyName.equals("行政村")) {
					ItemValue.removeWaypoint(pointNodes[j]);

				} else
					n++;
			}
			for (int i = 0; i < zr.length; i++) {
				ItemValue.deleteTracks(zr[i]);
			}
			if (n > 0)
				fo.saveFile(new File(outPath + "\\" + fileName));
			fo.reset();
		}
	}

	// 删除行政村航点,并保存至原始位置
	public void RemovePointAndSave(String filePath) {
		ItemValue.setShowDialogMessage(false);
		FrameOur fo = new FrameOur();
		File[] allGSFile = getAllGSFiles(filePath);// 获取所有国省道GPS文件
		String lxNumber = "";
		String trackName = "";
		String pointName = "";
		String keyName = "";
		String pointValue = "";
		int n = 0;
		for (int p = 0; p < allGSFile.length; p++) {
			File myFile = allGSFile[p];
			String fileName = myFile.getName();
			fo.openFile(new File(myFile.getPath()));
			Node[] zr = ItemValue.getTracks();
			Node[] zr1 = ItemValue.getTracks();
			Node[] pointNodes = ItemValue.getWaypoint();
			n = 0;
			for (int j = 0; pointNodes != null && j < pointNodes.length; j++) {
				pointName = ItemValue.getWaypointName(pointNodes[j]);
				keyName = ItemValue.getWaypointKP(pointNodes[j]);
				if (keyName.equals("行政村")) { // 当航点为行政村时,就删除此航点
					ItemValue.removeWaypoint(pointNodes[j]);
					System.err.println("     " + pointName + " 航点已经被删除!");
					n++;
				}
			}
			if (n > 0)
				fo.saveFile(new File(myFile.getParent() + "\\" + fileName));
			fo.reset();
		}
	}

	// 获取所有国省道中行政村的航点(从临时文件夹中获取GPS文件)
	public ArrayList getAllPointNode(String filePath) {
		ArrayList allNodeList = new ArrayList();
		ItemValue.setShowDialogMessage(false);
		FrameOur fo = new FrameOur();
		File[] allGSFile = getAllFile(filePath);// 获取临时存放的已经删除国省道中航迹和非行政村航点的GPS文件
		for (int p = 0; allGSFile != null && p < allGSFile.length; p++) {
			File myFile = allGSFile[p];
			String fileName = myFile.getName();
			fo.openFile(new File(myFile.getPath()));

			WptTrackDistance wd = new WptTrackDistance();
			String lxNumber = "";
			String trackName = "";
			String pointName = "";
			String keyName = "";
			String pointValue = "";
			double distanceValue = 0.00;
			Node[] pointNodes = ItemValue.getWaypoint();
			for (int j = 0; pointNodes != null && j < pointNodes.length; j++) {
				ReadWayPointNode readWP = new ReadWayPointNode();
				readWP.setFileName(myFile.getPath());
				readWP.setPointNode(pointNodes[j]);
				allNodeList.add(readWP);
			}
			fo.reset();
		}
		return allNodeList;
	}

	// 查找国省道中行政村航点与非国省道中航迹的距离对应关系
	public Vector getAllNodeAndTrackDistance(String outPath, String inPath) {
		ItemValue.setShowDialogMessage(false);
		FrameOur fo = new FrameOur();
		ArrayList allPointNode = getAllPointNode(outPath); // 获取所有国省道中行政村的航点(从临时文件夹中获取GPS文件)
		File[] allNotGSFile = getAllNotGSFile(inPath); // 获取所有非国省道GPS文件
		Vector allTrack = new Vector();
		for (int i = 0; i < allPointNode.size(); i++) {
			WptTrackDistance wd = new WptTrackDistance();
			String lxNumber = "";
			String trackName = "";
			String pointName = "";
			String keyName = "";
			String pointValue = "";
			double distanceValue = 0.00;
			Node pointNode = ((ReadWayPointNode) allPointNode.get(i))
					.getPointNode();
			String wpFileName = ((ReadWayPointNode) allPointNode.get(i))
					.getFileName();
			for (int j = 0; j < allNotGSFile.length; j++) {
				File myFile = allNotGSFile[j];
				String fileName = myFile.getName();
				fo.openFile(new File(myFile.getPath()));
				Node[] zr = ItemValue.getTracks();
				for (int k = 0; zr != null && k < zr.length; k++) {
					distanceValue = wd.getWptToTrackDis(pointNode, zr[k]);
					LoadNode ln = new LoadNode();
					ln.setPointValue(pointNode);
					ln.setTrackValue(zr[k]);
					ln.setDistanceValue(distanceValue);
					ln.setFileName(myFile.getPath());
					ln.setWpFileName(wpFileName);
					allTrack.add(ln);
				}
				fo.reset();
			}
		}
		return allTrack;
	}

	// 获取与航点最近的航迹文件(GPS文件),并组织对应关系
	public ArrayList getMinDistanceNode(String outPath, String inPath) {
		ArrayList allMinNode = new ArrayList();
		ArrayList allPointNode = getAllPointNode(outPath);// 获取所有国省道中行政村的航点(从临时文件夹中获取GPS文件)
		// File[] allNotGSFile=getAllNotGSFile(inPath);
		Vector allTrack = getAllNodeAndTrackDistance(outPath, inPath); // 查找国省道中行政村航点与非国省道中航迹的距离对应关系
		String pointName = "黄马村委会";
		String fileName = "";
		String wpFileName = "";
		Node pointNode = null;
		String pointName1 = "";
		Node pointNode1 = null;
		String fileName1 = "";
		String wpFileName1 = "";
		double minDoubleValue = 100000.0;
		for (int j = 0; j < allPointNode.size(); j++) {
			pointName = ItemValue
					.getWaypointName(((ReadWayPointNode) allPointNode.get(j))
							.getPointNode());
			minDoubleValue = 100000.0;
			for (int i = 0; i < allTrack.size(); i++) {
				pointName1 = ItemValue.getWaypointName(((LoadNode) allTrack
						.get(i)).getPointValue());
				pointNode1 = ((LoadNode) allTrack.get(i)).getPointValue();
				double distanceValue = (((LoadNode) allTrack.get(i))
						.getDistanceValue());
				fileName1 = (((LoadNode) allTrack.get(i)).getFileName());
				wpFileName1 = (((LoadNode) allTrack.get(i)).getWpFileName());
				if (pointName1.equals(pointName)) {
					if (distanceValue < minDoubleValue) {
						minDoubleValue = distanceValue;
						fileName = fileName1;
						wpFileName = wpFileName1;
						pointNode = pointNode1;

					}
				}
			}

			LoadMinNode lmn = new LoadMinNode();
			lmn.setFileName(fileName);
			lmn.setPointNode(pointNode);
			lmn.setWpFileName(wpFileName);
			allMinNode.add(lmn);
		}
		// 去除在同一路线中转移到非国省道同一路线的航点重复对应关系
		int n = 0;
		ArrayList tempList = allMinNode;
		for (int k = 0; k < tempList.size(); k++) {
			fileName1 = (((LoadMinNode) tempList.get(k)).getFileName());
			wpFileName1 = (((LoadMinNode) tempList.get(k)).getWpFileName());
			n = 0;
			for (int l = 0; l < allMinNode.size(); l++) {
				fileName = (((LoadMinNode) allMinNode.get(l)).getFileName());
				wpFileName = (((LoadMinNode) allMinNode.get(l)).getWpFileName());
				if (fileName.equals(fileName1)
						&& wpFileName.equals(wpFileName1)) {
					n++;
					if (n > 1)
						allMinNode.remove(l);
				}

			}
		}
		return allMinNode;

	}

	// 执行国省道上行政村航点转移到最近的非国省道上?
	public void CountryTransfer(String inPath) {
		String outPath = "D:\\测试用数据\\输出文件";
		RemoveTrackAndPoint(inPath);// 移除在国省道上的所有非行政村航点及所有航迹,并将GPS文件保存在临时文件夹中
		ArrayList allMinNode = getMinDistanceNode(outPath, inPath);// 获取与国省道中行政村航点最近的航迹信息及对应关系
		ArrayList tempList = allMinNode;
		ItemValue.setShowDialogMessage(false);
		FrameOur fo = new FrameOur();
		String fileName1 = "";
		String fileName2 = "";
		String tmFileName1 = "";
		String tmFileName2 = "";
		Node pointNode = null;
		for (int i = 0; i < allMinNode.size(); i++) {
			fileName1 = (((LoadMinNode) allMinNode.get(i)).getFileName());
			fileName2 = (((LoadMinNode) allMinNode.get(i)).getWpFileName());
			File file2 = new File(fileName2);
			fo.openFile(file2);
			Node[] pointNodes = ItemValue.getWaypoint();
			for (int j = 0; j < tempList.size(); j++) {
				tmFileName1 = (((LoadMinNode) tempList.get(j)).getFileName());
				tmFileName2 = (((LoadMinNode) tempList.get(j)).getWpFileName());
				String pointName = ItemValue
						.getWaypointName(((LoadMinNode) tempList.get(i))
								.getPointNode());
				pointNode = (((LoadMinNode) tempList.get(j)).getPointNode());
				if (!tmFileName1.equals(fileName1)
						&& tmFileName2.equals(fileName2)) {
					for (int k = 0; k < pointNodes.length; k++) {
						String pointName1 = ItemValue
								.getWaypointName(pointNodes[k]);
						if (!pointName1.equals(pointName)) {
							ItemValue.removeWaypoint(pointNodes[k]);
							// System.err.println("=================ERR!========="+pointName);
						}
					}
				}
			}
			String pointName1 = ItemValue
					.getWaypointName(((LoadMinNode) allMinNode.get(i))
							.getPointNode());
			// 转移航点到非国省道
			File file1 = new File(fileName1);
			String fileName = file1.getName();
			System.out.println("=========" + file1.getParent());
			fo.openFile(file1);

			fo.saveFile(new File(file1.getParent() + "\\" + fileName));
			fo.reset();
			System.err.println("===========pointName===" + pointName1);
			System.err.println("===========fileName===" + fileName1);
			System.err.println("===========WpfileName===" + fileName2);
		}

		// RemovePointAndSave(inPath);//删除国省道中的行政村航点

	}

	public static void main(String[] args) {
		CountryTransfer ct = new CountryTransfer();
		// ct.RemoveTrackAndPoint("D:\\测试用数据\\怀宁县");
		ct.CountryTransfer("D:\\测试用数据\\祁门县");
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -