diff --git a/src/osm/jp/api/HttpPOST.java b/src/osm/jp/api/HttpPOST.java index 28b8e82..25b5725 100644 --- a/src/osm/jp/api/HttpPOST.java +++ b/src/osm/jp/api/HttpPOST.java @@ -513,9 +513,9 @@ } - public static File overpassAPI(String query) { + public static File overpassAPI(String query, File outputFile) { StringBuilder sb = new StringBuilder(); - File outputFile = new File("overpassAPI.xml"); + //File outputFile = new File("overpassAPI.xml"); try { // https://overpass-api.de/api/interpreter @@ -523,7 +523,7 @@ HttpURLConnection connection = null; - try (FileWriter fw = new FileWriter(outputFile);) { + try (FileWriter fw = new FileWriter(outputFile)) { connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); diff --git a/src/osm/jp/api/OsmExist.java b/src/osm/jp/api/OsmExist.java index c835c2b..4ccab5a 100644 --- a/src/osm/jp/api/OsmExist.java +++ b/src/osm/jp/api/OsmExist.java @@ -133,7 +133,7 @@ StringBuilder sb = new StringBuilder(); for (Japan box : Japan.all2) { - String boxq = String.format("(%f,%f,%f,%f)", box.minLat, box.minLon, box.maxLat, box.maxLon); + String boxq = String.format("(%2.1f,%3.1f,%2.1f,%3.1f)", box.minLat, box.minLon, box.maxLat, box.maxLon); sb.append(String.format("(node(changed:\"%s\")%s;)->.a;\n", startDate, boxq)); sb.append(String.format("(node(newer:\"%s\")%s;)->.b;\n", startDate, boxq)); sb.append(String.format("(way(changed:\"%s\")%s;)->.c;\n", startDate, boxq)); @@ -147,7 +147,7 @@ else if (f.node == Feature.AREA) { sb.append("way.c.d"); } - sb.append(String.format("[\"%s\"=\"%s\"]\n", f.key, f.v)); + sb.append(String.format("[\"%s\"=\"%s\"];\n", f.key, f.v)); point += f.point; } sb.append(");\n"); @@ -156,9 +156,11 @@ /*-------------------------------------------- Overpass API を実行して XMLを受信する ---------------------------------------------*/ - File xmlFile = HttpPOST.overpassAPI(sb.toString()); - - + File xmlFile = HttpPOST.overpassAPI(sb.toString(), new File("overpassAPI.xml")); + try { + Thread.sleep(5000); // 5秒 + } catch(InterruptedException e){} + /*-------------------------------------------- 受信したXMLファイルをパースする ---------------------------------------------*/ diff --git a/src/osm/jp/api/Osmdb.java b/src/osm/jp/api/Osmdb.java index 9961cdb..26c65a2 100644 --- a/src/osm/jp/api/Osmdb.java +++ b/src/osm/jp/api/Osmdb.java @@ -368,6 +368,18 @@ TABLE_NAME, idref, lat, lon, score, name); System.out.println(sql); + sql = String.format("DELETE FROM %s WHERE idref=?", TABLE_NAME); + try (PreparedStatement ps5 = hsqldb.prepareStatement(sql)) { + ps5.setString(1, idref); + ps5.executeUpdate(); + } + catch (HsqlException | SQLIntegrityConstraintViolationException e) { + // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST + // [HsqlException]は、無視する + // integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST + // [SQLIntegrityConstraintViolationException]は、無視する + } + sql = String.format("INSERT INTO %s (idref,lat,lon,score,name) VALUES (?,?,?,?,?)", TABLE_NAME); try (PreparedStatement ps5 = hsqldb.prepareStatement(sql)) { ps5.setString(1, idref);