巨大森林を分割する
Révision | ef1cf628906f00ee0943f393458a628e82c1e8b0 (tree) |
---|---|
l'heure | 2013-10-29 08:45:32 |
Auteur | hayashi.yuu <hayashi.yuu@gmai...> |
Commiter | hayashi.yuu |
WAYの接続を改良
@@ -0,0 +1,3 @@ | ||
1 | +#!/bin/sh | |
2 | +cd database | |
3 | +java -cp .:../../hsqldb.jar org.hsqldb.util.DatabaseManagerSwing | |
\ No newline at end of file |
@@ -404,6 +404,37 @@ public class DbBigrelation | ||
404 | 404 | ps6.executeUpdate(); |
405 | 405 | ps6.close(); |
406 | 406 | } |
407 | + | |
408 | + /** | |
409 | + * WAYを接続する | |
410 | + * @param addway | |
411 | + * @throws SQLException | |
412 | + */ | |
413 | + public static void connect_WAY(Connection con, long firstwayid, long secondwayid) throws SQLException { | |
414 | + PreparedStatement ps1 = con.prepareStatement("select max(CNT) from NDREF where (idref = ?)"); | |
415 | + ps1.setLong(1, firstwayid); | |
416 | + ResultSet rset1 = ps1.executeQuery(); | |
417 | + if (rset1.next()) { | |
418 | + double firstcnt = rset1.getDouble(1); | |
419 | + | |
420 | + PreparedStatement ps2 = con.prepareStatement("select * from NDREF where (idref = ?)"); | |
421 | + ps2.setLong(1, secondwayid); | |
422 | + ResultSet rset2 = ps2.executeQuery(); | |
423 | + while (rset2.next()) { | |
424 | + double secondcnt = rset2.getDouble("CNT"); | |
425 | + | |
426 | + PreparedStatement ps3 = con.prepareStatement("UPDATE NDREF SET idref=?, cnt=? WHERE (idref=?) and (CNT=?)"); | |
427 | + ps3.setLong(1, firstwayid); | |
428 | + ps3.setDouble(2, firstcnt + secondcnt + 1.0d); | |
429 | + ps3.setLong(3, secondwayid); | |
430 | + ps3.setDouble(4, secondcnt); | |
431 | + ps3.executeUpdate(); | |
432 | + ps3.close(); | |
433 | + } | |
434 | + rset2.close(); | |
435 | + } | |
436 | + rset1.close(); | |
437 | + } | |
407 | 438 | |
408 | 439 | /** |
409 | 440 | * idref BIGINT member.idref |
@@ -442,17 +473,25 @@ public class DbBigrelation | ||
442 | 473 | */ |
443 | 474 | public static void delete_NODE(Connection con, OsmNode node) throws SQLException |
444 | 475 | { |
445 | - PreparedStatement ps = con.prepareStatement("update NODE set action=? where idref=? and osmtype=?"); | |
446 | - ps.setInt(1, OsmNode.ACTION_DELETE); | |
447 | - ps.setLong(2, node.idref); | |
448 | - ps.setInt(3, DbBigrelation.OSM_NODE); | |
449 | - ps.executeUpdate(); | |
450 | - ps.close(); | |
476 | + if (node.idref < 0) { | |
477 | + PreparedStatement ps1 = con.prepareStatement("delete from NODE where idref=?"); | |
478 | + ps1.setLong(1, node.idref); | |
479 | + ps1.executeUpdate(); | |
480 | + ps1.close(); | |
481 | + } | |
482 | + else { | |
483 | + PreparedStatement ps1 = con.prepareStatement("update NODE set action=? where idref=? and osmtype=?"); | |
484 | + ps1.setInt(1, OsmNode.ACTION_DELETE); | |
485 | + ps1.setLong(2, node.idref); | |
486 | + ps1.setInt(3, DbBigrelation.OSM_NODE); | |
487 | + ps1.executeUpdate(); | |
488 | + ps1.close(); | |
489 | + } | |
451 | 490 | |
452 | - ps = con.prepareStatement("delete from NDREF where idref=?"); | |
453 | - ps.setLong(1, node.idref); | |
454 | - ps.executeUpdate(); | |
455 | - ps.close(); | |
491 | + PreparedStatement ps2 = con.prepareStatement("delete from NDREF where idref=?"); | |
492 | + ps2.setLong(1, node.idref); | |
493 | + ps2.executeUpdate(); | |
494 | + ps2.close(); | |
456 | 495 | } |
457 | 496 | |
458 | 497 | /** |
@@ -465,17 +504,25 @@ public class DbBigrelation | ||
465 | 504 | */ |
466 | 505 | public static void delete_WAY(Connection con, Way way) throws SQLException |
467 | 506 | { |
468 | - PreparedStatement ps = con.prepareStatement("update NODE set action=? where idref=? and osmtype=?"); | |
469 | - ps.setInt(1, OsmNode.ACTION_DELETE); | |
470 | - ps.setLong(2, way.idref); | |
471 | - ps.setInt(3, DbBigrelation.OSM_WAY); | |
472 | - ps.executeUpdate(); | |
473 | - ps.close(); | |
507 | + if (way.idref < 0) { | |
508 | + PreparedStatement ps1 = con.prepareStatement("delete from NODE where idref=?"); | |
509 | + ps1.setLong(1, way.idref); | |
510 | + ps1.executeUpdate(); | |
511 | + ps1.close(); | |
512 | + } | |
513 | + else { | |
514 | + PreparedStatement ps1 = con.prepareStatement("update NODE set action=? where idref=? and osmtype=?"); | |
515 | + ps1.setInt(1, OsmNode.ACTION_DELETE); | |
516 | + ps1.setLong(2, way.idref); | |
517 | + ps1.setInt(3, DbBigrelation.OSM_WAY); | |
518 | + ps1.executeUpdate(); | |
519 | + ps1.close(); | |
520 | + } | |
474 | 521 | |
475 | - ps = con.prepareStatement("delete from NDREF where idref=?"); | |
476 | - ps.setLong(1, way.idref); | |
477 | - ps.executeUpdate(); | |
478 | - ps.close(); | |
522 | + PreparedStatement ps2 = con.prepareStatement("delete from NDREF where idref=?"); | |
523 | + ps2.setLong(1, way.idref); | |
524 | + ps2.executeUpdate(); | |
525 | + ps2.close(); | |
479 | 526 | } |
480 | 527 | |
481 | 528 | /** |
@@ -778,6 +825,7 @@ public class DbBigrelation | ||
778 | 825 | result.visibleStr = rset.getString("visible"); |
779 | 826 | result.versionStr = rset.getString("version"); |
780 | 827 | result.changeset = rset.getLong("changeset"); |
828 | + result.action = rset.getInt("action"); | |
781 | 829 | } |
782 | 830 | rset.close(); |
783 | 831 | return is; |
@@ -366,6 +366,7 @@ public class RelationCutter { | ||
366 | 366 | // MEMBER->WAY |
367 | 367 | Way way = new Way(); |
368 | 368 | if (!DbBigrelation.getWay(con, way, member.ref)) { |
369 | + Logger.logger.warning("WAY以外のメンバーがあります。(member:id="+ member.ref +")"); | |
369 | 370 | continue; |
370 | 371 | } |
371 | 372 |
@@ -382,6 +383,8 @@ public class RelationCutter { | ||
382 | 383 | OsmNode startNode = way.waynodes.get(0); |
383 | 384 | OsmNode endNode = way.waynodes.get(way.waynodes.size() -1); |
384 | 385 | if ((startNode.lat.compareTo(endNode.lat) == 0) && (startNode.lon.compareTo(endNode.lon) == 0)) { |
386 | + // 既に始点と終点が一致しており、AREAとして閉じています。 | |
387 | + Logger.logger.info("AREAとして閉じています。(wayid="+ way.idref +")"); | |
385 | 388 | continue; |
386 | 389 | } |
387 | 390 | else { |
@@ -93,6 +93,7 @@ public class Way { | ||
93 | 93 | |
94 | 94 | /** |
95 | 95 | * WAYを接続する |
96 | + * 別途、リレーションのメンバーから削除する必要があります。 | |
96 | 97 | * @param addway |
97 | 98 | * @throws SQLException |
98 | 99 | */ |
@@ -103,5 +104,13 @@ public class Way { | ||
103 | 104 | if (lastnode.idref != addway.waynodes.get(0).idref) { |
104 | 105 | DbBigrelation.delete_NODE(con, lastnode); |
105 | 106 | } |
107 | + | |
108 | + for (int i =0; i < addway.waynodes.size(); i++) { | |
109 | + this.waynodes.add(addway.waynodes.get(i)); | |
110 | + } | |
111 | + addway.action = OsmNode.ACTION_DELETE; | |
112 | + | |
113 | + // pending! データベース上のデータも更新する必要がある | |
114 | + DbBigrelation.connect_WAY(con, this.idref, addway.idref); | |
106 | 115 | } |
107 | 116 | } |