diff --git a/src/osm/jp/coverage/busstop/Busstop.java b/src/osm/jp/coverage/busstop/Busstop.java index 120a88e..ddde03b 100644 --- a/src/osm/jp/coverage/busstop/Busstop.java +++ b/src/osm/jp/coverage/busstop/Busstop.java @@ -84,6 +84,7 @@ /** * 都道府県ごとのGMLディレクトリの処理 */ + /* int fcounter = 0; File dir = new File("."); File[] files = dir.listFiles(); @@ -95,6 +96,7 @@ } } System.out.println("["+ fcounter +"]つのファイルをインポートしました。"); + */ } finally { DatabaseTool.closeDb(con); @@ -131,7 +133,7 @@ * @throws TransformerException */ public Busstop(Connection con, File gmldir) throws SQLException, FileNotFoundException, ClassNotFoundException, IOException, ParserConfigurationException, SAXException, TransformerException { - int areacode = Integer.parseInt(gmldir.getName().substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)); + //int areacode = Integer.parseInt(gmldir.getName().substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)); BufferedWriter ow = null; ToPostgis postgis = null; @@ -147,6 +149,7 @@ File[] files = gmldir.listFiles(); try { for (File iFile : files) { + /* // 対象のファイルが「数値地図情報のGMLデータファイル」の時のみ処理を行う。 if (!checkFile(iFile, areacode)) { continue; @@ -154,9 +157,9 @@ //Busstop.clearDb(con); if (!Busstop.update) { - inputFile(con, iFile, areacode); + //inputFile(con, iFile, areacode); } - + */ if (true) { PreparedStatement ps1; @@ -440,38 +443,6 @@ System.out.println("("+ areacode +") バス停数["+ iCounter +"]"); } - /** - * 数値地図情報のGMLデータファイルを読み取ってローカルベータベースへ記録する - * @param con - * @param iFile - * @param areacode - * @throws FileNotFoundException - * @throws ClassNotFoundException - * @throws SQLException - * @throws IOException - * @throws ParserConfigurationException - * @throws SAXException - */ - public static void inputFile (Connection con, File iFile, int areacode) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException { - int iCounter = 0; - String timeStampStr = null; - - String iStr = iFile.getName(); - - DocumentBuilderFactory factory; - DocumentBuilder builder; - Node root; - - factory = DocumentBuilderFactory.newInstance(); - builder = factory.newDocumentBuilder(); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - factory.setValidating(true); - root = builder.parse(iFile); - - iCounter += showNodes(con, root, iStr.substring(0, iStr.length() - 4), timeStampStr, areacode); - System.out.println("("+ areacode +") バス停数["+ iCounter +"]"); - } public static void clearDb(Connection con) throws SQLException { try (Statement stmt = con.createStatement()) { @@ -847,45 +818,5 @@ } } } - - /** - * 数値地図情報のGMLデータファイルかどうかを見極める - * @param f - * @return - */ - static boolean checkFile(File f, int areacode) { - String name = f.getName(); - if (!name.startsWith(GML_DIR_PREFIX)) { - return false; - } - if (!name.toUpperCase().endsWith(".XML")) { - return false; - } - if (Integer.parseInt(name.substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)) == areacode) { - return true; - } - return false; - } - /** - * 数値地図情報のデータディレクトリかどうかを見極める - * @param f - * @return - */ - public static boolean checkGMLdir(File f) { - if (!f.isDirectory()) { - return false; - } - String name = f.getName(); - if (!name.startsWith(GML_DIR_PREFIX)) { - return false; - } - if (!name.toUpperCase().endsWith(GML_DIR_PRIFIX)) { - return false; - } - return true; - } - - public static final String GML_DIR_PREFIX = "P11-10_"; - public static final String GML_DIR_PRIFIX = "_GML"; } \ No newline at end of file diff --git a/src/osm/jp/coverage/busstop/DbBusstop.java b/src/osm/jp/coverage/busstop/DbBusstop.java index 9425190..60c6d89 100644 --- a/src/osm/jp/coverage/busstop/DbBusstop.java +++ b/src/osm/jp/coverage/busstop/DbBusstop.java @@ -7,10 +7,15 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLSyntaxErrorException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; import jp.co.areaweb.tools.database.*; +import org.w3c.dom.Node; import org.xml.sax.SAXException; +import static osm.jp.coverage.busstop.Busstop.checkFile; public class DbBusstop { public static final String TABLE_NAME = "bus_stop"; @@ -56,14 +61,26 @@ ps.executeUpdate(); } - File gmlDir = new File("GML_FUEL"); - for (File gmlFile : gmlDir.listFiles()) { - if (checkGMLfile(gmlFile)) { - int index = "P07-15_".length(); - int areacode = Integer.parseInt(gmlFile.getName().substring(index, index+2)); - inputFile(con, gmlFile, areacode); + /** + * 都道府県ごとのGMLディレクトリの処理 + */ + int fcounter = 0; + File dir = new File("GML_BUSSTOP"); + for (File gmldir : dir.listFiles()) { + if (checkGMLdir(gmldir)) { + // GMLディレクトリを処理する + int areacode = Integer.parseInt(gmldir.getName().substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)); + File[] files = gmldir.listFiles(); + for (File iFile : files) { + // 対象のファイルが「数値地図情報のGMLデータファイル」の時のみ処理を行う。 + if (checkFile(iFile, areacode)) { + importBusstop(conHsql, iFile, areacode); + fcounter++; + } + } } } + System.out.println("["+ fcounter +"]つのファイルをインポートしました。"); DbBusstop.export(conHsql); } @@ -73,6 +90,39 @@ } } } + + /** + * 数値地図情報のGMLデータファイルを読み取ってローカルベータベースへ記録する + * @param conHsql + * @param iFile + * @param areacode + * @throws FileNotFoundException + * @throws ClassNotFoundException + * @throws SQLException + * @throws IOException + * @throws ParserConfigurationException + * @throws SAXException + */ + public static void importBusstop (Connection conHsql, File iFile, int areacode) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException { + int iCounter = 0; + String timeStampStr = null; + + String iStr = iFile.getName(); + + DocumentBuilderFactory factory; + DocumentBuilder builder; + Node root; + + factory = DocumentBuilderFactory.newInstance(); + builder = factory.newDocumentBuilder(); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + factory.setValidating(true); + root = builder.parse(iFile); + + iCounter += showNodes(conHsql, root, iStr.substring(0, iStr.length() - 4), timeStampStr, areacode); + System.out.println("("+ areacode +") バス停数["+ iCounter +"]"); + } /** * 'table.BUS_STOP'を新規に作る @@ -201,4 +251,45 @@ e.printStackTrace(); } } + + /** + * 数値地図情報のGMLデータファイルかどうかを見極める + * @param f + * @return + */ + static boolean checkFile(File f, int areacode) { + String name = f.getName(); + if (!name.startsWith(GML_DIR_PREFIX)) { + return false; + } + if (!name.toUpperCase().endsWith(".XML")) { + return false; + } + if (Integer.parseInt(name.substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)) == areacode) { + return true; + } + return false; + } + + /** + * 数値地図情報のデータディレクトリかどうかを見極める + * @param f + * @return + */ + public static boolean checkGMLdir(File f) { + if (!f.isDirectory()) { + return false; + } + String name = f.getName(); + if (!name.startsWith(GML_DIR_PREFIX)) { + return false; + } + if (!name.toUpperCase().endsWith(GML_DIR_PRIFIX)) { + return false; + } + return true; + } + + public static final String GML_DIR_PREFIX = "P11-10_"; + public static final String GML_DIR_PRIFIX = "_GML"; } \ No newline at end of file