From 9ad0063e44721f5a03269f41b94cc2024d90aeb2 Mon Sep 17 00:00:00 2001 From: hayashi Date: Mon, 8 Oct 2012 11:06:30 +0900 Subject: [PATCH] new commit --- ConvAdmPt.bat | 2 + build.xml | 79 +++++ src/osm/jp/kiban25000/ConvAdmPt25000.java | 488 ++++++++++++++++++++++++++++++ 3 files changed, 569 insertions(+) create mode 100644 ConvAdmPt.bat create mode 100644 build.xml create mode 100644 src/osm/jp/kiban25000/ConvAdmPt25000.java diff --git a/ConvAdmPt.bat b/ConvAdmPt.bat new file mode 100644 index 0000000..ff02310 --- /dev/null +++ b/ConvAdmPt.bat @@ -0,0 +1,2 @@ +java -jar ConvAdmPt.jar +pause \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..b249eeb --- /dev/null +++ b/build.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/osm/jp/kiban25000/ConvAdmPt25000.java b/src/osm/jp/kiban25000/ConvAdmPt25000.java new file mode 100644 index 0000000..fe8288c --- /dev/null +++ b/src/osm/jp/kiban25000/ConvAdmPt25000.java @@ -0,0 +1,488 @@ +package osm.jp.kiban25000; + +import javax.xml.parsers.*; +import org.w3c.dom.*; +import org.xml.sax.*; +import java.io.*; +import java.util.Iterator; +import java.util.TreeMap; + +/** + * ====基盤地図情報のダウンロード==== + * + * まず最初に、基盤地図情報をダウンロードします。 + * + * 国土地理院の基盤地図情報ダウンロードページから、ログイン画面へ進みログインして、「基盤地図情報 縮尺レベル25000 JPGIS形式」を選択し、対象の地域のファイルをダウンロードします。(「JPGIS(GML)形式」ではありません) + * http://fgd.gsi.go.jp/download/ + * + * 対象地域と項目の選択方法は、ダウンロードページの指示に従ってください。 + * + * 「基盤地図情報項目」では「行政区画の境界線及び代表点」を選択してください。 + * 「FG-JPS-39-05-Z001.zip」というような「FG-JPS-xx-05-Z001.zip」という形式のZIPファイルがダウンロードされます。 + * + * ダウンロードした圧縮ファイルを解凍しておきます。 + * 解凍すると「FG-JPS-44209-CommBdry-20091109-0001.xml」というような「FG-JPS-xxxx-CommBdry-xxxxxxxx-xxxx.xml」という形式のXMLファイルが出来上がります。 + * @author yuu + * + */ +public class ConvAdmPt25000 { + File inputFile; + String admCodeStr = ""; + int iCounter = 0; + boolean link = true; + TreeMap admMap = null; + + /** + * メイン + * + * + * + * + * + fgoid:10-00150-11-1002-1530 + + + 2008-03-31 + + + + + 2999-12-31 + + + + + + 2011-01-31 + + + + 25000 + 表示 + + + + + 37.055674 139.338021 + + + + その他 + 福島県南会津郡檜枝岐村 + 07364 + + + + + + + + */ + public static void main(String[] argv) + { + boolean link = true; + for (String arg : argv) { + if (arg.equals("-nolink")) { + link = false; + } + } + + File dir = new File("."); + File[] files = dir.listFiles(); + int counter = 0; + for (File iFile : files) { + if (checkFile(iFile)) { + counter++; + ConvAdmPt25000 t = new ConvAdmPt25000(iFile, link); + t.runner(); + } + } + System.out.println("["+ counter +"]つのファイルを処理しました。"); + } + + public ConvAdmPt25000 (File iFile, boolean link) { + this.inputFile = iFile; + this.link = link; + } + + public void runner() { + DocumentBuilderFactory factory; + DocumentBuilder builder; + Node root; + + this.iCounter = 0; + String iStr = this.inputFile.getName(); + String[] nameAry = iStr.split("-"); + String fileName = ""; + for (int i=0; i < nameAry.length; i++) { + if (i != 0) { + fileName = fileName + "-"; + } + fileName = fileName + nameAry[i]; + if (i == 2) { + this.admCodeStr = nameAry[2]; + } + } + + File outputFile = new File(iStr.substring(0, iStr.length() - 4) +".gpx"); + BufferedWriter wGpx = null; + + File htmlFile = new File(iStr.substring(0, iStr.length() - 4) +".html"); + BufferedWriter wHtml = null; + + File wikiFile = new File(iStr.substring(0, iStr.length() - 4) +".txt"); + BufferedWriter wWiki = null; + + File csvFile = new File(iStr.substring(0, iStr.length() - 4) +".csv"); + BufferedWriter wCsv = null; + + try { + wGpx = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); + wHtml = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8")); + wWiki = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wikiFile), "UTF-8")); + wCsv = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8")); + + wGpx.write(""); + wGpx.newLine(); + wGpx.write(""); + wGpx.newLine(); + + wWiki.write("=== "+ admCodeStr +": "+ getCodeName(Integer.parseInt(admCodeStr)) +" ==="); + wWiki.newLine(); + wWiki.write("{| class=\"wikitable sortable\""); + wWiki.newLine(); + wWiki.write("|- "); + wWiki.newLine(); + wWiki.write("! style=\"width:70px\" | admCode"); + wWiki.newLine(); + wWiki.write("! | name"); + wWiki.newLine(); + wWiki.write("! style=\"width:70px\" | type"); + wWiki.newLine(); + wWiki.write("! | 備考/最終更新日"); + wWiki.newLine(); + + wCsv.write("\"都道府県コード\",\"都道府県名\",\"admCode\",\"Name\",\"type\",\"LAT\",\"LON\",\"備考/最終更新日\""); + wCsv.newLine(); + + wHtml.write(""); + wHtml.newLine(); + wHtml.write(""); + wHtml.newLine(); + wHtml.write(""); + wHtml.newLine(); + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.newLine(); + + factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + factory.setValidating(true); + root = builder.parse(inputFile.getName()); + + //--------------------------------------- + admMap = new TreeMap(); + showNodes(root, ""); + //--------------------------------------- + + Iterator it = admMap.keySet().iterator(); + while (it.hasNext()) { + String code = (String) it.next(); + AdmPt adm = admMap.get(code); + + wWiki.write("|- "); + wWiki.newLine(); + wWiki.write("| " + adm.code); + wWiki.newLine(); + wWiki.write("| " + adm.name); + wWiki.newLine(); + wWiki.write("| " + adm.type); + wWiki.newLine(); + wWiki.write("| "); + wWiki.newLine(); + + wCsv.write("\""+ admCodeStr +"\",\""+ getCodeName(Integer.parseInt(admCodeStr)) +"\","); + wCsv.write("\""+ adm.code +"\",\""+ adm.name +"\",\""+ adm.type +"\","); + wCsv.write("\""+ adm.latStr +"\",\""+ adm.lonStr +"\",\""+ adm.dateStr +"\""); + wCsv.newLine(); + + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.write(""); + wHtml.newLine(); + + wGpx.write(""); + wGpx.newLine(); + wGpx.write(" "); + wGpx.newLine(); + wGpx.write(" "); + wGpx.newLine(); + wGpx.write(""); + wGpx.newLine(); + } + + wGpx.write(""); + wGpx.newLine(); + + wHtml.write("
admCodename
"+ adm.code +""+ adm.name +""+ adm.type +"
"); + wHtml.newLine(); + + wWiki.write("|}"); + wWiki.newLine(); + + } catch (ParserConfigurationException e0) { + System.out.println(e0.getMessage()); + } catch (SAXException e1){ + System.out.println(e1.getMessage()); + } catch (IOException e2) { + System.out.println(e2.getMessage()); + } + finally { + if (wGpx != null) { + try { + wGpx.close(); + wHtml.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + if (wWiki != null) { + try { + wWiki.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + if (wCsv != null) { + try { + wCsv.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + public void showNodes(Node node, String space) throws IOException { + NodeList nodes = node.getChildNodes(); + for (int i=0; i