📄 seachspecial.java
字号:
package net.aetherial.gis.our.search;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import net.aetherial.gis.surface.ItemValue;
import net.aetherial.gis.our.allauto.frame.PathSelect;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import java.io.File;
import org.w3c.dom.Node;
import net.aetherial.gis.publicuse.wpt.WPTsTrack;
import net.aetherial.gis.dataType.TrackType;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.*;
import net.aetherial.gis.table.TrackTableName;
import net.aetherial.gis.our.FrameOur;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class SeachSpecial
extends JFrame {
BorderLayout borderLayout1 = new BorderLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
PathSelect pathSelect = new PathSelect(false);
String gradeStr = "";
String fileName = "";
PrintStream out = null;
FrameOur fo = null;
public SeachSpecial(FrameOur fo) {
try {
this.setFo(fo);
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
jButton1.addActionListener(new SeachSpecial_jButton1_actionAdapter(this));
this.getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
jButton1.setText("确定");
jPanel1.setLayout(xYLayout1);
jScrollPane1.getViewport().add(jPanel1);
jCheckBox1.setSelected(true);
jCheckBox1.setText("村道");
jCheckBox3.setSelected(true);
jCheckBox3.setText("无路面 或者 路面小于3.5米");
jCheckBox2.setSelected(true);
jCheckBox2.setText("不属于(沟通建制村的唯一村道)");
jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD, 15));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText("特殊搜索");
jLabel2.setText("范围:");
jLabel3.setText("米");
jTextField1.setText("80");
jPanel1.add(jLabel1, new XYConstraints(115, 19, 126, 20));
jPanel1.add(pathSelect, new XYConstraints(1, 21, 448, 112));
jPanel1.add(jCheckBox3, new XYConstraints(131, 168, -1, -1));
jPanel1.add(jCheckBox1, new XYConstraints(131, 132, -1, -1));
jPanel1.add(jCheckBox2, new XYConstraints(131, 203, -1, -1));
jPanel1.add(jTextField1, new XYConstraints(131, 239, 86, -1));
jPanel1.add(jLabel2, new XYConstraints(92, 243, -1, -1));
jPanel1.add(jLabel3, new XYConstraints(232, 241, -1, -1));
jPanel1.add(jButton1, new XYConstraints(165, 299, -1, -1));
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
this.setTitle("数据查询");
this.setSize(462, 405);
this.setLocation(
(screenDim.width - 462) / 2,
(screenDim.height - 405) / 2
);
this.setIconImage(ItemValue.getImage("HSDIlogo.gif"));
}
private Vector findOutGPSFiles(String inputPath) {
Vector gpsFiles = new Vector();
String gradeDir = "";
File base = new File(inputPath);
File[] all = base.listFiles();
for (int i = 0; all != null && i < all.length; i++) {
if (all[i].isDirectory()) {
// System.out.println(all[i].getAbsolutePath());
gpsFiles.addAll(findOutGPSFiles(all[i].getAbsolutePath()));
}
}
File[] gps = base.listFiles(new java.io.FilenameFilter() {
public boolean accept(File file, String name) {
return
file != null &&
checkGradePath(file.getAbsolutePath(), gradeStr) &&
name.length() > 4 &&
".gps".equalsIgnoreCase(name.substring(name.length() - 4));
}
});
for (int i = 0; gps != null && i < gps.length; i++) {
gpsFiles.add(gps[i]);
}
return gpsFiles;
}
private boolean checkGradePath(String path, String gradeStr) {
boolean result = false;
if (gradeStr.length() == 0) {
result = path.indexOf("整理完毕") > -1;
}
else {
if (gradeStr.indexOf("国道") > -1) {
result |= path.indexOf("整理完毕\\国") > -1;
}
if (gradeStr.indexOf("省道") > -1) {
result |= path.indexOf("整理完毕\\省") > -1;
}
if (gradeStr.indexOf("县道") > -1) {
result |= path.indexOf("整理完毕\\县") > -1;
}
if (gradeStr.indexOf("乡道") > -1) {
result |= path.indexOf("整理完毕\\乡") > -1;
}
if (gradeStr.indexOf("村道") > -1) {
result |= path.indexOf("整理完毕\\村") > -1 || path.indexOf("整理完毕\\乡村") > -1 || path.indexOf("整理完毕\\乡道非年报") > -1;
}
if (gradeStr.indexOf("专用道路") > -1) {
result |= path.indexOf("整理完毕\\专") > -1;
}
}
return result;
}
public static void main(String[] args) {
SeachSpecial seachspecial = new SeachSpecial(null);
}
private boolean isCunDao(Node trk) {
String grade = ItemValue.getTracksGrade(trk).trim();
return TrackType.Grade_CUN.equals(grade) || grade.equals("");
}
private boolean isTulu_less3mi5(Node trk) {
String type = ItemValue.getTracksType(trk).trim();
if (type.equals("")) {
type = TrackType.RS_D_bad;
}
double kuandu = 1000;
try {
kuandu = Double.parseDouble(ItemValue.getTracksWidth(trk));
}
catch (NumberFormatException ex) {
}
if (kuandu < 3.5 || type.equals(TrackType.RS_D_bad)) {
return true;
}
else {
return false;
}
}
private boolean isSuitable(boolean cun, boolean tulu_less3mi5, Node trk) {
if (cun && tulu_less3mi5) {
return isCunDao(trk) && isTulu_less3mi5(trk);
}
else if ( (!cun) && tulu_less3mi5) {
return isTulu_less3mi5(trk);
}
else if (cun && (!tulu_less3mi5)) {
return isCunDao(trk);
}
else {
return true;
}
}
private Node[] scanAFile() {
boolean cun = this.jCheckBox1.isSelected();
boolean tulu_less3mi5 = this.jCheckBox3.isSelected();
boolean feiJZCOnly = this.jCheckBox2.isSelected();
Node[] trks = ItemValue.getTracks();
Vector temp1 = new Vector();
if (trks != null) {
for (int i = 0; i < trks.length; i++) {
if (isSuitable(cun, tulu_less3mi5, trks[i])) {
temp1.add(trks[i]);
}
}
}
Vector temp2 = new Vector();
if (feiJZCOnly) {
for (int i = 0; i < temp1.size(); i++) {
if (this.checkXingZCOnly( (Node) temp1.get(i))) {
System.out.println("沟通建制村的唯一一条路线:" + ItemValue.getTracksNum( (Node) temp1.get(i)));
temp2.add( (Node) temp1.get(i));
}else{
System.out.println("非沟通建制村的唯一一条路线:" + ItemValue.getTracksNum( (Node) temp1.get(i)));
}
}
}
Vector temp3 = new Vector();
for (int i = 0; i < temp1.size(); i++) {
if (temp2.indexOf(temp1.get(i)) == -1) {
temp3.add(temp1.get(i));
}
}
Node[] result = new Node[temp3.size()];
temp3.copyInto(result);
return result;
}
/**
* 是否包含的建制村仅此一条航迹
*/
private boolean checkXingZCOnly(Node track) {
if (track != null) {
Node[] wpts = ItemValue.getTracksWaypoint(track);
Node[] wpt2 = ItemValue.getXingZCInWaypoint(wpts);
Node[] wptTrack = null;
boolean isOnly = false;
for (int i = 0; wpts != null && i < wpts.length; i++) {
String kp = ItemValue.getWaypointKP(wpts[i]);
if (kp != null && kp.length() > 0 &&
("行政村".equals(kp) && wpt2 != null && wpt2.length > 0)) {
try {
WPTsTrack.setFanwei(Double.parseDouble(this.jTextField1.getText().trim()));
}
catch (NumberFormatException ex) {
}
wptTrack = WPTsTrack.getWptNearTrack(wpts[i]);
for (int k = 0;wptTrack != null && k < wptTrack.length; k++) {
System.out.println(" wptTrack["+k+"]:" + ItemValue.getTracksName(wptTrack[k]));
}
if (wptTrack == null) {
System.out.println(" wptTrack == null");
}
if (wptTrack.length == 1) {
isOnly = true;
}
else {
return false;
}
}
}
return isOnly;
}
return false;
}
private void getTrkInfo(Node trk) {
TrackTableName rodeName = new TrackTableName(trk);
String trackShi = ItemValue.getTracksT1(trk);
String trackXian = ItemValue.getTracksT2(trk);
String trackXiang = ItemValue.getTracksT3(trk);
String trackCun = ItemValue.getTracksT4(trk);
String trackName = ItemValue.getTracksName(trk);
String roadName = rodeName.getStartEndName();
String trackNumber = ItemValue.getTracksNumber(trk);
String trackGrade = ItemValue.getTracksGrade(trk);
String trackLevel = ItemValue.getTracksT5(trk);
String trackSurface = ItemValue.getTracksType(trk);
String trackSurfaceWidth = ItemValue.getTracksWidth(trk);
String trackBaseWidth = ItemValue.getTracks_jitongbu_luji_With(trk);
double dis = ItemValue.getTracksDistance(trk) / 1000;
out.println("\"" + trackShi + "\",\"" +
trackXian + "\",\"" +
trackXiang + "\",\"" +
trackCun + "\",\"" +
trackName + "\",\"" +
roadName + "\",\"" +
trackNumber + "\",\"" +
trackGrade + "\",\"" +
trackLevel + "\",\"" +
trackSurface + "\",\"" +
trackSurfaceWidth + "\",\"" +
trackBaseWidth + "\",\"" +
dis + "\""
);
}
private void openFeiNianBaoToCundao(File gpsFile){
Node[] trksBefore = ItemValue.getTracks();
this.fo.openFile(gpsFile);
Node[] trksAfter = ItemValue.getTracks();
boolean find = false;
for (int i = 0;trksAfter!= null && i < trksAfter.length; i++) {
for (int j = 0;trksBefore!= null && j < trksBefore.length; j++) {
if (trksBefore[j] == trksAfter[i]) {
find = true;
break;
}
}
if (find == false) {
ItemValue.setTracksGrade(trksAfter[i],TrackType.Grade_CUN);
}
}
}
public void jButton1_actionPerformed(ActionEvent e) throws Exception {
System.out.println("" + this.getWidth() + "," + this.getHeight());
String inputPath = this.pathSelect.getInputPath();
String outputPath = this.pathSelect.getOutputPath();
fileName = outputPath + "搜索结果_" + System.currentTimeMillis() +
".csv";
try {
out = new PrintStream(new BufferedOutputStream(new
FileOutputStream(fileName)));
}
catch (FileNotFoundException ex) {
}
ProgressBar pbar = new ProgressBar();
// gradeStr = "国道|省道|县道|乡道|村道|专用道路";
gradeStr = "村道";
Vector gpsFiles = this.findOutGPSFiles(inputPath);
ItemValue.setShowDialogMessage(false);
Node[] temp = null;
File gpsFile = null;
for (int i = 0; gpsFiles != null && i < gpsFiles.size(); i++) {
gpsFile = (File) gpsFiles.get(i);
if (gpsFile.getAbsolutePath().indexOf("乡道非年报") != -1) {
openFeiNianBaoToCundao(gpsFile);
}else{
this.fo.openFile(gpsFile);
}
temp = this.scanAFile();
for (int j = 0; temp != null && j < temp.length; j++) {
this.getTrkInfo(temp[j]);
}
this.fo.reset();
}
out.flush();
out.close();
pbar.dispose();
msg("运行结束,结果文件是: \n" + fileName);
}
/**
* 弹出报警信息
*/
public void msg(String string) {
JOptionPane.showMessageDialog(this, string,
string,
JOptionPane.WARNING_MESSAGE);
}
public void setFo(FrameOur fo) {
this.fo = fo;
}
}
class SeachSpecial_jButton1_actionAdapter
implements ActionListener {
private SeachSpecial adaptee;
SeachSpecial_jButton1_actionAdapter(SeachSpecial adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
try {
adaptee.jButton1_actionPerformed(e);
}
catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
adaptee.msg(ex.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -