* バス停データ変換のメイン処理\r
*/\r
int fcounter = 0;\r
- if (args.length > index) {\r
- File iFile = new File(args[index]);\r
- fcounter++;\r
- inputFile(con, iFile);\r
- }\r
- else {\r
- File dir = new File(".");\r
- File[] files = dir.listFiles();\r
- for (File iFile : files) {\r
- if (checkFile(iFile)) {\r
- fcounter++;\r
- ConvBusstop.clearDb(con);\r
- inputFile(con, iFile);\r
- }\r
- }\r
- }\r
- System.out.println("["+ fcounter +"]つのファイルをインポートしました。");\r
- \r
- /**\r
- * 既存のOSMバス停を読み込む\r
- * --> 'existing.xml'\r
- */\r
- if (!ConvBusstop.nocheck && (fcounter > 0)) {\r
- /*\r
- * 既存のOSMデータファイルがなければ、新たにダウンロードする。\r
- * OSMデータファイルがあるときは、ダウンロードしないでそれを使う。\r
- */\r
- File existingFile = new File("existing.xml");\r
- if (!existingFile.isFile()) {\r
- /**\r
- * インポートしたデータの緯度経度範囲を読み取る\r
- */\r
- double maxLat = -90.0D;\r
- double minLat = 90.0D;\r
- double maxLon = -180.0D;\r
- double minLon = 180.0D;\r
- PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop");\r
- ResultSet rset8 = ps8.executeQuery();\r
- while (rset8.next()) {\r
- Double lat = rset8.getDouble("lat");\r
- Double lon = rset8.getDouble("lon");\r
-\r
- if (lat > maxLat) {\r
- maxLat = lat;\r
- }\r
- if (lon > maxLon) {\r
- maxLon = lon;\r
- }\r
- if (lat < minLat) {\r
- minLat = lat;\r
- }\r
- if (lon < minLon) {\r
- minLon = lon;\r
- }\r
- }\r
- rset8.close();\r
+ File dir = new File(".");\r
+ File[] files = dir.listFiles();\r
+ for (File iFile : files) {\r
+ if (checkFile(iFile)) {\r
+ fcounter++;\r
+ ConvBusstop.clearDb(con);\r
+ inputFile(con, iFile);\r
+\r
+ String iStr = iFile.getName();\r
+ iStr = iStr.substring(0, iStr.length() - 4);\r
\r
/**\r
- * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する\r
+ * 既存のOSMバス停を読み込む\r
+ * --> 'existing.xml'\r
*/\r
- HttpPOST.getCapabilities(minLat, maxLat, minLon, maxLon);\r
- }\r
- readExistingFile(con, existingFile);\r
- \r
- PreparedStatement ps1 = con.prepareStatement("SELECT idref,name,lat,lon FROM bus_stop");\r
- PreparedStatement ps2 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)");\r
- PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?");\r
- PreparedStatement ps4 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?) and (name = ?)");\r
- ResultSet rset1 = ps1.executeQuery();\r
- while (rset1.next()) {\r
- String idref = rset1.getString("idref");\r
- String name = rset1.getString("name");\r
- Double lat = rset1.getDouble("lat");\r
- Double lon = rset1.getDouble("lon");\r
- \r
- // 指定の緯度経度を中心とする半径150x2m四方の矩形領域\r
- System.out.print(idref + "("+ name + ") ....");\r
- RectArea rect = new RectArea(lat, lon, NEER); // 300m 四方\r
- ps2.setDouble(1, rect.minlat);\r
- ps2.setDouble(2, rect.maxlat);\r
- ps2.setDouble(3, rect.minlon);\r
- ps2.setDouble(4, rect.maxlon);\r
- ResultSet rset2 = ps2.executeQuery();\r
- if (rset2.next()) {\r
- int count = rset2.getInt(1);\r
- if (count > 0) {\r
- System.out.println("."+ count);\r
- ps3.setInt(1, count);\r
- ps3.setString(2, idref);\r
- ps3.executeUpdate();\r
+ if (!ConvBusstop.nocheck && (fcounter > 0)) {\r
+ /*\r
+ * 既存のOSMデータファイルがなければ、新たにダウンロードする。\r
+ * OSMデータファイルがあるときは、ダウンロードしないでそれを使う。\r
+ */\r
+ File existingFile = new File(iStr, "existing.xml");\r
+ if (!existingFile.isFile()) {\r
+ /**\r
+ * インポートしたデータの緯度経度範囲を読み取る\r
+ */\r
+ double maxLat = -90.0D;\r
+ double minLat = 90.0D;\r
+ double maxLon = -180.0D;\r
+ double minLon = 180.0D;\r
+ PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop");\r
+ ResultSet rset8 = ps8.executeQuery();\r
+ while (rset8.next()) {\r
+ Double lat = rset8.getDouble("lat");\r
+ Double lon = rset8.getDouble("lon");\r
+\r
+ if (lat > maxLat) {\r
+ maxLat = lat;\r
+ }\r
+ if (lon > maxLon) {\r
+ maxLon = lon;\r
+ }\r
+ if (lat < minLat) {\r
+ minLat = lat;\r
+ }\r
+ if (lon < minLon) {\r
+ minLon = lon;\r
+ }\r
+ }\r
+ rset8.close();\r
+ \r
+ /**\r
+ * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する\r
+ */\r
+ HttpPOST.getCapabilities(new File(iStr), minLat, maxLat, minLon, maxLon);\r
}\r
- else {\r
- // 指定の緯度経度を中心とする半径150x4m四方の矩形領域\r
- System.out.print("***");\r
- rect = new RectArea(lat, lon, NEER*2); // 600m 四方\r
- ps4.setDouble(1, rect.minlat);\r
- ps4.setDouble(2, rect.maxlat);\r
- ps4.setDouble(3, rect.minlon);\r
- ps4.setDouble(4, rect.maxlon);\r
- ps4.setString(5, name);\r
- ResultSet rset4 = ps4.executeQuery();\r
- if (rset4.next()) {\r
- count = rset4.getInt(1);\r
- System.out.println(".."+ count);\r
- ps3.setInt(1, count);\r
- ps3.setString(2, idref);\r
- ps3.executeUpdate();\r
+ readExistingFile(con, existingFile);\r
+ \r
+ PreparedStatement ps1 = con.prepareStatement("SELECT idref,name,lat,lon FROM bus_stop");\r
+ PreparedStatement ps2 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)");\r
+ PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?");\r
+ PreparedStatement ps4 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?) and (name = ?)");\r
+ ResultSet rset1 = ps1.executeQuery();\r
+ while (rset1.next()) {\r
+ String idref = rset1.getString("idref");\r
+ String name = rset1.getString("name");\r
+ Double lat = rset1.getDouble("lat");\r
+ Double lon = rset1.getDouble("lon");\r
+ \r
+ // 指定の緯度経度を中心とする半径150x2m四方の矩形領域\r
+ System.out.print(idref + "("+ name + ") ....");\r
+ RectArea rect = new RectArea(lat, lon, NEER); // 300m 四方\r
+ ps2.setDouble(1, rect.minlat);\r
+ ps2.setDouble(2, rect.maxlat);\r
+ ps2.setDouble(3, rect.minlon);\r
+ ps2.setDouble(4, rect.maxlon);\r
+ ResultSet rset2 = ps2.executeQuery();\r
+ if (rset2.next()) {\r
+ int count = rset2.getInt(1);\r
+ if (count > 0) {\r
+ System.out.println("."+ count);\r
+ ps3.setInt(1, count);\r
+ ps3.setString(2, idref);\r
+ ps3.executeUpdate();\r
+ }\r
+ else {\r
+ // 指定の緯度経度を中心とする半径150x4m四方の矩形領域\r
+ System.out.print("***");\r
+ rect = new RectArea(lat, lon, NEER*2); // 600m 四方\r
+ ps4.setDouble(1, rect.minlat);\r
+ ps4.setDouble(2, rect.maxlat);\r
+ ps4.setDouble(3, rect.minlon);\r
+ ps4.setDouble(4, rect.maxlon);\r
+ ps4.setString(5, name);\r
+ ResultSet rset4 = ps4.executeQuery();\r
+ if (rset4.next()) {\r
+ count = rset4.getInt(1);\r
+ System.out.println(".."+ count);\r
+ ps3.setInt(1, count);\r
+ ps3.setString(2, idref);\r
+ ps3.executeUpdate();\r
+ }\r
+ rset4.close();\r
+ }\r
}\r
- rset4.close();\r
+ rset2.close();\r
}\r
+ rset1.close();\r
+ ps3.close();\r
+ ps2.close();\r
+ ps1.close();\r
}\r
- rset2.close();\r
- }\r
- rset1.close();\r
- ps3.close();\r
- ps2.close();\r
- ps1.close();\r
- }\r
- \r
- // ローカルデータベース内の情報を出力する\r
- if (args.length > index) {\r
- File iFile = new File(args[index]);\r
- String iStr = iFile.getName();\r
- outputDb(con, iStr.substring(0, iStr.length() - 4));\r
- }\r
- else {\r
- File dir = new File(".");\r
- File[] files = dir.listFiles();\r
- for (File iFile : files) {\r
- if (checkFile(iFile)) {\r
- String iStr = iFile.getName();\r
- outputDb(con, iStr.substring(0, iStr.length() - 4));\r
- }\r
+ \r
+\r
+ // ローカルデータベース内の情報を出力する\r
+ outputDb(con, iStr);\r
+ \r
+ // ローカルデータベース内の情報を「busstop.xml」に出力する\r
+ int counter = outputDb(con, new File(iStr));\r
+ System.out.println("["+ counter +"] 変換完了しました。");\r
}\r
}\r
- \r
- // ローカルデータベース内の情報を「busstop.xml」に出力する\r
- int counter = outputDb(con);\r
-\r
- System.out.println("["+ counter +"] 変換完了しました。");\r
+ System.out.println("["+ fcounter +"]つのファイルをインポートしました。");\r
}\r
finally {\r
DatabaseTool.closeDb(con);\r
hw.close();\r
}\r
\r
- public static int outputDb(Connection con) throws IOException, SQLException {\r
- File osmFile = new File("busstop.osm");\r
+ public static int outputDb(Connection con, File dir) throws IOException, SQLException {\r
+ File osmFile = new File(dir, "busstop.osm");\r
int counter = 0;\r
\r
SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");\r