| |
---|
| | * @param csvFile |
---|
| | * @throws Exception |
---|
| | */ |
---|
| | public NagoyaBusstop(Connection con, File csvFile) throws Exception { |
---|
| | inputFile(con, csvFile); |
---|
| | |
---|
| | /** |
---|
| | * 既存のOSMバス停を読み込む |
---|
| | * --> 'existing.xml' |
---|
| | */ |
---|
| | File existingFile = new File("existing.xml"); |
---|
| | |
---|
| | /** |
---|
| | * インポートしたデータの緯度経度範囲を読み取る |
---|
| | */ |
---|
| | double maxLon = -180.0D; |
---|
| | double minLon = 180.0D; |
---|
| | double maxLat = -90.0D; |
---|
| | double minLat = 90.0D; |
---|
| | PreparedStatement ps8; |
---|
| | ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop"); |
---|
| | ResultSet rset8 = ps8.executeQuery(); |
---|
| | while (rset8.next()) { |
---|
| | Double lat = rset8.getDouble("lat"); |
---|
| | Double lon = rset8.getDouble("lon"); |
---|
| | |
---|
| | if (lat > maxLat) { |
---|
| | maxLat = lat; |
---|
| | } |
---|
| | if (lon > maxLon) { |
---|
| | maxLon = lon; |
---|
| | } |
---|
| | if (lat < minLat) { |
---|
| | minLat = lat; |
---|
| | } |
---|
| | if (lon < minLon) { |
---|
| | minLon = lon; |
---|
| | } |
---|
| | } |
---|
| | rset8.close(); |
---|
| | inputFile(con, csvFile); |
---|
| | |
---|
| | /** |
---|
| | * 既存のOSMバス停を読み込む |
---|
| | * --> 'existing.xml' |
---|
| | */ |
---|
| | File existingFile = new File("existing.xml"); |
---|
| | |
---|
| | /** |
---|
| | * インポートしたデータの緯度経度範囲を読み取る |
---|
| | */ |
---|
| | double maxLon = -180.0D; |
---|
| | double minLon = 180.0D; |
---|
| | double maxLat = -90.0D; |
---|
| | double minLat = 90.0D; |
---|
| | PreparedStatement ps8; |
---|
| | ps8 = con.prepareStatement("SELECT lat,lon FROM "+ DbBusstop.TABLE_NAME); |
---|
| | try (ResultSet rset8 = ps8.executeQuery()) { |
---|
| | while (rset8.next()) { |
---|
| | Double lat = rset8.getDouble("lat"); |
---|
| | Double lon = rset8.getDouble("lon"); |
---|
| | |
---|
| | if (lat > maxLat) { |
---|
| | maxLat = lat; |
---|
| | } |
---|
| | if (lon > maxLon) { |
---|
| | maxLon = lon; |
---|
| | } |
---|
| | if (lat < minLat) { |
---|
| | minLat = lat; |
---|
| | } |
---|
| | if (lon < minLon) { |
---|
| | minLon = lon; |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する |
---|
| | */ |
---|
| |
---|
| | HttpPOST.getCapabilities("public_transport", "platform", minLon, maxLon, minLat, maxLat); |
---|
| | readExistingFile(con, existingFile); |
---|
| | |
---|
| | PreparedStatement ps1; |
---|
| | ps1 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM bus_stop"); |
---|
| | ps1 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM " + DbBusstop.TABLE_NAME); |
---|
| | PreparedStatement ps2 = con.prepareStatement("SELECT count(*) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)"); |
---|
| | PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?"); |
---|
| | PreparedStatement ps3 = con.prepareStatement("UPDATE "+ DbBusstop.TABLE_NAME +" SET fixed=? WHERE idref=?"); |
---|
| | PreparedStatement ps4 = con.prepareStatement("SELECT count(*) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)"); |
---|
| | ResultSet rset1 = ps1.executeQuery(); |
---|
| | while (rset1.next()) { |
---|
| | String idref = rset1.getString(1); |
---|
| |
---|
| | * @param iFile |
---|
| | * @throws Exception |
---|
| | */ |
---|
| | public static void inputFile (Connection con, File iFile) throws Exception { |
---|
| | PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,kana,fixed,area,lat,lon) VALUES (?,?,?,?,?,?,?)"); |
---|
| | PreparedStatement ps2 = con.prepareStatement("INSERT INTO "+ DbBusstop.TABLE_NAME +" (idref,name,kana,fixed,area,lat,lon) VALUES (?,?,?,?,?,?,?)"); |
---|
| | |
---|
| | CsvFile csv = new CsvFile(iFile); |
---|
| | csv.load(); |
---|
| | int cnt = 0; |
---|
| |
---|
| | } |
---|
| | |
---|
| | public static void clearDb(Connection con) throws SQLException { |
---|
| | Statement stmt = con.createStatement(); |
---|
| | long count = stmt.executeUpdate("delete from bus_stop"); |
---|
| | System.out.println("'Database.bus_stop'から "+ count +" 件のデータを削除しました。"); |
---|
| | long count = stmt.executeUpdate("delete from "+ DbBusstop.TABLE_NAME); |
---|
| | System.out.println("'Database.busstop'から "+ count +" 件のデータを削除しました。"); |
---|
| | |
---|
| | count = stmt.executeUpdate("delete from existing_data"); |
---|
| | System.out.println("'Database.existing_data'から "+ count +" 件のデータを削除しました。"); |
---|
| | } |
---|
| | |
---|
| | public static void initDb(Connection con) throws SQLException { |
---|
| | // 'table.BUS_STOP'を新規に作る |
---|
| | // 'table.BUSSTOP'を新規に作る |
---|
| | DbBusstop.create(con); |
---|
| | } |
---|
| | |
---|
| | |
---|
| |
---|
| | |