📄 totongji.java
字号:
package net.aetherial.gis.test.tongji;
import java.io.File;
import java.util.Vector;
import net.aetherial.gis.output.toLd.OpenDirectory;
import net.aetherial.gis.our.FrameOur;
import net.aetherial.gis.table.WuWei;
import net.aetherial.gis.surface.ItemValue;
import java.io.IOException;
import net.aetherial.gis.surface.CreateFile;
import java.text.DecimalFormat;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ToTongji {
private String inputPath;
private String outputPath;
private String xian;
public WuWei array = null;
private String n = "";
private FrameOur fo = new FrameOur();
java.text.DecimalFormat formater = new DecimalFormat("##.##");
private String errorString = "";
public ToTongji() {
ItemValue.setShowDialogMessage(false);
}
public void scanAllFile() {
OpenDirectory od = new OpenDirectory();
od.setGradeStr("国道|省道|县道");
File[] ganxians = od.getOpenFile(this.inputPath);
ItemValue.setArrayPath(od.getArrayStringPath(this.inputPath));
array = new WuWei();
od.setGradeStr("乡道|村道");
File[] xiangcuns = od.getOpenFile(this.inputPath);
for (int i = 0; i < xiangcuns.length; i++) {
this.scanAFile(ganxians, xiangcuns[i]);
}
this.initErrorString(xiangcuns,array);
this.n += this.errorString;
this.Save( (new File(this.outputPath)).getAbsolutePath() + "\\" + this.xian +
"_行政村统计.txt", this.n);
}
private void initErrorString(File[] xiangcuns, WuWei array) {
String arrayNot = "", gpsNot = "";
String xiangzhen = "";
boolean find = false;
for (int i = 0; i < xiangcuns.length; i++) {
find = false;
xiangzhen = xiangcuns[i].getName();
try {
xiangzhen = xiangzhen.substring(0, 2);
}
catch (Exception ex) {
}
for (int j = 0; j < array.wuchen_xiangzhen.length; j++) {
if (array.wuchen_xiangzhen[j].indexOf(xiangzhen) != -1 ||
xiangzhen.indexOf(array.wuchen_xiangzhen[j]) != -1) {
find = true;
}
}
if (!find) {
arrayNot += this.xian + "\t" + xiangcuns[i].getName() + "\r\n";
}
}
for (int i = 0; i < array.wuchen_xiangzhen.length; i++) {
find = false;
for (int j = 0; j < xiangcuns.length; j++) {
xiangzhen = xiangcuns[j].getName();
try {
xiangzhen = xiangzhen.substring(0, 2);
}
catch (Exception ex) {
}
if (array.wuchen_xiangzhen[i].indexOf(xiangzhen) != -1 ||
xiangzhen.indexOf(array.wuchen_xiangzhen[i]) != -1) {
find = true;
}
}
if (!find) {
gpsNot += this.xian + "\t" + array.wuchen_xiangzhen[i] + "\r\n";
}
}
if (!(gpsNot.trim().equals(""))) {
this.errorString += "array含有,GPS测量没有的乡镇\r\n";
this.errorString += gpsNot;
}
if (!(arrayNot.trim().equals(""))) {
this.errorString += "GPS测量含有,array没有的乡镇\r\n";
this.errorString += arrayNot;
}
}
private int getXingzhengcunNum(String xiangzhen) {
int count = 0;
for (int i = 0; i < this.array.wuchen_xiangzhen.length; i++) {
if (this.array.wuchen_xiangzhen[i].indexOf(xiangzhen) != -1 ||
xiangzhen.indexOf(this.array.wuchen_xiangzhen[i]) != -1) {
count++;
}
}
return count;
}
private String getXingzhengcunName(String xiangzhen) {
String xingzhengcun = "";
for (int i = 0; i < this.array.wuchen_xiangzhen.length; i++) {
if (this.array.wuchen_xiangzhen[i].indexOf(xiangzhen) != -1 ||
xiangzhen.indexOf(this.array.wuchen_xiangzhen[i]) != -1) {
if (i != this.array.wuchen_xiangzhen.length - 1) {
xingzhengcun += this.array.wuwei_cun[i] + ",";
}
else {
xingzhengcun += this.array.wuwei_cun[i];
}
}
}
return xingzhengcun;
}
private String[] getXingzhengcunName(File xiangzhenFile) {
String xingzhengcun = "", xiangzhen = xiangzhenFile.getName();
Vector xzc = new Vector();
try {
xiangzhen = xiangzhen.substring(0, 2);
}
catch (Exception ex) {
}
for (int i = 0; i < this.array.wuchen_xiangzhen.length; i++) {
if (this.array.wuchen_xiangzhen[i].indexOf(xiangzhen) != -1 ||
xiangzhen.indexOf(this.array.wuchen_xiangzhen[i]) != -1) {
// if (i != this.array.wuchen_xiangzhen.length -1) {
// xingzhengcun += this.array.wuwei_cun[i] +",";
// }else{
// xingzhengcun += this.array.wuwei_cun[i];
// }
xzc.add(this.array.wuwei_cun[i]);
}
}
String[] temp = new String[xzc.size()];
xzc.copyInto(temp);
return temp;
}
private void scanAFile(File[] ganxian, File xiangzhen) {
int num = 0;
/**
* 县名称
*/
this.n += this.xian + "\t";
/**
* 乡镇名称
*/
this.n += xiangzhen.getName().toUpperCase().replaceAll(".GPS", "") + "\t";
/**
* 建制村数量
*/
try {
num = getXingzhengcunNum(xiangzhen.getName().substring(0, 2));
this.n += num + "\t";
}
catch (Exception ex) {
this.n += " " + "\t";
}
/**
* 建制村名称
*/
try {
this.n += getXingzhengcunName(xiangzhen.getName().substring(0, 2)) + "\t";
}
catch (Exception ex) {
this.n += " " + "\t";
}
Goutong goutong = new Goutong();
goutong.setFo(this.fo);
goutong.setGanxians(ganxian);
goutong.setXiangzhenFile(xiangzhen);
String[] xzc = this.getXingzhengcunName(xiangzhen);
for (int i = 0; i < xzc.length; i++) {
goutong.addXingzhencun(xzc[i]);
}
//
goutong.countFiles();
Vector shuini = goutong.getShuini_xingzhencun();
for (int i = 0; i < shuini.size(); i++) {
if (i == shuini.size() - 1) {
this.n += shuini.get(i) + ",";
}
else {
this.n += shuini.get(i) + ",";
}
}
Vector youlu = goutong.getYoulu_xingzhencun();
for (int i = 0; i < youlu.size(); i++) {
if (i == youlu.size() - 1) {
this.n += youlu.get(i) + "\t";
}
else {
this.n += youlu.get(i) + ",";
}
}
if (youlu.size() == 0) {
this.n += " " + "\t";
}
this.n += (youlu.size() + shuini.size()) + "\t";
if (num != 0) {
this.n +=
formater.format( (shuini.size() + youlu.size()) * 1.0 / num * 100) +
"%\r\n";
}
else {
}
}
// private void getData(File[] ganxian, File xiangzhen){
// Goutong goutong = new Goutong();
// goutong.setFo(this.fo);
// goutong.setGanxians(ganxian);
// goutong.setXiangzhenFile(xiangzhen);
// String[] xzc = this.getXingzhengcunName(xiangzhen);
// for (int i = 0; i < xzc.length; i++) {
// goutong.addXingzhencun(xzc[i]);
// }
////
// goutong.countFiles();
// goutong.getShuini_xingzhencun();
// goutong.getYoulu_xingzhencun();
//
// }
public void Save(String file, String content) {
// System.out.println(content);
if (content.trim().equals("")) {
return;
}
File f = new File(file);
if (! (f.getParentFile().exists())) {
f.getParentFile().mkdirs();
}
try {
f.createNewFile();
}
catch (IOException ex) {
ex.printStackTrace();
}
CreateFile cf = new CreateFile(f);
cf.setEncode(System.getProperty("file.encoding"));
cf.memoryToFile(content);
// try {
// cf.setEncode("unicode");
// cf.memoryToFile(content);
// }
// catch (Exception ex1) {
// cf.setEncode("GB2312");
// cf.memoryToFile(content);
// }
}
public void setInputPath(String inputPath) {
this.inputPath = inputPath;
}
public void setXian(String xian) {
this.xian = xian;
}
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}
public static void main(String args[]) {
ToTongji tongji = new ToTongji();
tongji.setXian(args[0]);
tongji.setInputPath(args[1]);
tongji.setOutputPath(args[2]);
tongji.scanAllFile();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -