巨大森林を分割する
Revisão | a7bfcd8cca29db5520944993851b6c685d113a55 (tree) |
---|---|
Hora | 2013-08-03 11:34:10 |
Autor | hayashi.yuu <hayashi.yuu@gmai...> |
Commiter | hayashi.yuu |
WAYのaction='delete' に対応
@@ -61,6 +61,8 @@ public class DbBigrelation | ||
61 | 61 | * @throws SQLException |
62 | 62 | */ |
63 | 63 | public static void create(Connection con) throws SQLException { |
64 | + drop(con); | |
65 | + | |
64 | 66 | if (!isTable(con, "NODE")) { |
65 | 67 | create_NODE(con); |
66 | 68 | } |
@@ -99,6 +101,7 @@ public class DbBigrelation | ||
99 | 101 | * |
100 | 102 | * idref BIGINT NOT NULL |
101 | 103 | * osmtype INTEGER |
104 | + * action INT | |
102 | 105 | * timestamp VARCHAR(20) |
103 | 106 | * uid BIGINT |
104 | 107 | * user VARCHAR(64) |
@@ -112,7 +115,7 @@ public class DbBigrelation | ||
112 | 115 | * @throws SQLException |
113 | 116 | */ |
114 | 117 | public static boolean create_NODE(Connection con) throws SQLException { |
115 | - String createSt = "CREATE TABLE NODE (idref BIGINT NOT NULL, osmtype INTEGER, timestamp VARCHAR(20), uid BIGINT, usr VARCHAR(64), visible VARCHAR(8), version VARCHAR(32), changeset BIGINT, lat DOUBLE, lon DOUBLE, CONSTRAINT node_pk PRIMARY KEY(idref));"; | |
118 | + String createSt = "CREATE TABLE NODE (idref BIGINT NOT NULL, osmtype INTEGER, action INT, timestamp VARCHAR(20), uid BIGINT, usr VARCHAR(64), visible VARCHAR(8), version VARCHAR(32), changeset BIGINT, lat DOUBLE, lon DOUBLE, CONSTRAINT node_pk PRIMARY KEY(idref));"; | |
116 | 119 | Logger.logger.info(createSt); |
117 | 120 | PreparedStatement ps = con.prepareStatement(createSt); |
118 | 121 | try { |
@@ -198,12 +201,12 @@ public class DbBigrelation | ||
198 | 201 | * role VARCHAR(128) |
199 | 202 | * relationid BIGINT |
200 | 203 | * cnt DOUBLE |
201 | - * | |
204 | + * action INT | |
202 | 205 | * @param con |
203 | 206 | * @throws SQLException |
204 | 207 | */ |
205 | 208 | public static void create_MEMBER(Connection con) throws SQLException { |
206 | - String createSt = "create table MEMBER (idref BIGINT NOT NULL, ref BIGINT NOT NULL, type VARCHAR(128), role VARCHAR(128), relationid BIGINT, cnt DOUBLE);"; | |
209 | + String createSt = "create table MEMBER (idref BIGINT NOT NULL, ref BIGINT NOT NULL, type VARCHAR(128), role VARCHAR(128), relationid BIGINT, cnt DOUBLE, action INT);"; | |
207 | 210 | Logger.logger.info(createSt); |
208 | 211 | PreparedStatement ps = con.prepareStatement(createSt); |
209 | 212 | try { |
@@ -226,11 +229,18 @@ public class DbBigrelation | ||
226 | 229 | * @throws SQLException |
227 | 230 | */ |
228 | 231 | public static void drop(Connection con) throws SQLException { |
229 | - drop(con, "NODE"); | |
230 | - drop(con, "TAG"); | |
231 | - drop(con, "NDREF"); | |
232 | - drop(con, "MEMBER"); | |
233 | - drop(con, "WAY"); | |
232 | + if (isTable(con, "NODE")) { | |
233 | + drop(con, "NODE"); | |
234 | + } | |
235 | + if (isTable(con, "TAG")) { | |
236 | + drop(con, "TAG"); | |
237 | + } | |
238 | + if (isTable(con, "NDREF")) { | |
239 | + drop(con, "NDREF"); | |
240 | + } | |
241 | + if (isTable(con, "MEMBER")) { | |
242 | + drop(con, "MEMBER"); | |
243 | + } | |
234 | 244 | } |
235 | 245 | |
236 | 246 | /** |
@@ -246,60 +256,6 @@ public class DbBigrelation | ||
246 | 256 | ps.close(); |
247 | 257 | } |
248 | 258 | |
249 | - /** | |
250 | - * | |
251 | - * @param con | |
252 | - * @param id | |
253 | - * @param timestampStr | |
254 | - * @param uidStr | |
255 | - * @param userStr | |
256 | - * @param visibleStr | |
257 | - * @param versionStr | |
258 | - * @param changesetStr | |
259 | - * @param latStr | |
260 | - * @param lonStr | |
261 | - * @param osmtype | |
262 | - * @throws SQLException | |
263 | - */ | |
264 | - public static void insert_NODE(Connection con, | |
265 | - String idStr, | |
266 | - String timestampStr, | |
267 | - String uidStr, | |
268 | - String userStr, | |
269 | - String visibleStr, | |
270 | - String versionStr, | |
271 | - String changesetStr, | |
272 | - String latStr, | |
273 | - String lonStr, | |
274 | - int osmtype) throws SQLException | |
275 | - { | |
276 | - long idref = Long.parseLong(idStr); | |
277 | - if (idref == 0L) { | |
278 | - idref = DbBigrelation.getOsmnode_MinId(con); | |
279 | - idref = idref - 1L; | |
280 | - if (idref > 0) { | |
281 | - idref = -1; | |
282 | - } | |
283 | - } | |
284 | - PreparedStatement ps6 = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,lat,lon,osmtype) VALUES (?,?,?,?,?,?,?,?,?,?)"); | |
285 | - double lat = Double.parseDouble(latStr); | |
286 | - double lon = Double.parseDouble(lonStr); | |
287 | - long uid = Long.parseLong(uidStr); | |
288 | - long changeset = Long.parseLong(changesetStr); | |
289 | - ps6.setLong(1, idref); | |
290 | - ps6.setString(2, timestampStr); | |
291 | - ps6.setLong(3, uid); | |
292 | - ps6.setString(4, userStr); | |
293 | - ps6.setString(5, visibleStr); | |
294 | - ps6.setString(6, versionStr); | |
295 | - ps6.setLong(7, changeset); | |
296 | - ps6.setDouble(8, lat); | |
297 | - ps6.setDouble(9, lon); | |
298 | - ps6.setInt(10, osmtype); | |
299 | - //System.out.println("INSERT INTO node(type="+ osmtype +" id="+ idStr +" lat="+ lat +", lon="+ lon +")"); | |
300 | - ps6.executeUpdate(); | |
301 | - ps6.close(); | |
302 | - } | |
303 | 259 | |
304 | 260 | public static void insert_NODE(Connection con, OsmNode node) throws SQLException |
305 | 261 | { |
@@ -310,7 +266,7 @@ public class DbBigrelation | ||
310 | 266 | node.idref = -1; |
311 | 267 | } |
312 | 268 | } |
313 | - PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,lat,lon,osmtype) VALUES (?,?,?,?,?,?,?,?,?,?)"); | |
269 | + PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,lat,lon,osmtype,action) VALUES (?,?,?,?,?,?,?,?,?,?,?)"); | |
314 | 270 | ps.setLong(1, node.idref); |
315 | 271 | ps.setString(2, node.timestampStr); |
316 | 272 | ps.setLong(3, node.uid); |
@@ -321,13 +277,21 @@ public class DbBigrelation | ||
321 | 277 | ps.setDouble(8, node.lat); |
322 | 278 | ps.setDouble(9, node.lon); |
323 | 279 | ps.setInt(10, DbBigrelation.OSM_NODE); |
280 | + ps.setInt(11, node.action); | |
324 | 281 | ps.executeUpdate(); |
325 | 282 | ps.close(); |
326 | 283 | } |
327 | 284 | |
328 | 285 | public static void insert_WAY(Connection con, Way way) throws SQLException |
329 | 286 | { |
330 | - PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,osmtype) VALUES (?,?,?,?,?,?,?,?)"); | |
287 | + if (way.idref == 0L) { | |
288 | + way.idref = DbBigrelation.getWAY_MinId(con); | |
289 | + way.idref = way.idref - 1L; | |
290 | + if (way.idref >= 0) { | |
291 | + way.idref = -1; | |
292 | + } | |
293 | + } | |
294 | + PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,osmtype,action) VALUES (?,?,?,?,?,?,?,?,?)"); | |
331 | 295 | ps.setLong(1, way.idref); |
332 | 296 | ps.setString(2, way.timestampStr); |
333 | 297 | ps.setLong(3, way.uid); |
@@ -336,6 +300,22 @@ public class DbBigrelation | ||
336 | 300 | ps.setString(6, way.versionStr); |
337 | 301 | ps.setLong(7, way.changeset); |
338 | 302 | ps.setInt(8, DbBigrelation.OSM_WAY); |
303 | + ps.setInt(9, way.action); | |
304 | + ps.executeUpdate(); | |
305 | + ps.close(); | |
306 | + } | |
307 | + | |
308 | + public static void insert_RELATION(Connection con, Relation node) throws SQLException | |
309 | + { | |
310 | + PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,osmtype) VALUES (?,?,?,?,?,?,?,?)"); | |
311 | + ps.setLong(1, node.id); | |
312 | + ps.setString(2, node.timestampStr); | |
313 | + ps.setLong(3, node.uid); | |
314 | + ps.setString(4, node.userStr); | |
315 | + ps.setString(5, node.visibleStr); | |
316 | + ps.setString(6, node.versionStr); | |
317 | + ps.setLong(7, node.changeset); | |
318 | + ps.setInt(8, DbBigrelation.OSM_RELATION); | |
339 | 319 | ps.executeUpdate(); |
340 | 320 | ps.close(); |
341 | 321 | } |
@@ -420,6 +400,29 @@ public class DbBigrelation | ||
420 | 400 | ps6.executeUpdate(); |
421 | 401 | ps6.close(); |
422 | 402 | } |
403 | + | |
404 | + /** | |
405 | + * WAYをOSMデータから削除する | |
406 | + * 別途、WAYノードを事前に削除する必要があります。 | |
407 | + * 別途、リレーションのメンバーから削除する必要があります。 | |
408 | + * @param con | |
409 | + * @param way | |
410 | + * @throws SQLException | |
411 | + */ | |
412 | + public static void delete_WAY(Connection con, Way way) throws SQLException | |
413 | + { | |
414 | + PreparedStatement ps = con.prepareStatement("update NODE set action=? where idref=? and osmtype=?"); | |
415 | + ps.setInt(1, OsmNode.ACTION_DELETE); | |
416 | + ps.setLong(2, way.idref); | |
417 | + ps.setInt(3, DbBigrelation.OSM_WAY); | |
418 | + ps.executeUpdate(); | |
419 | + ps.close(); | |
420 | + | |
421 | + ps = con.prepareStatement("delete from NDREF where idref=?"); | |
422 | + ps.setLong(1, way.idref); | |
423 | + ps.executeUpdate(); | |
424 | + ps.close(); | |
425 | + } | |
423 | 426 | |
424 | 427 | /** |
425 | 428 | * 'table.NODE'の内容をCSV形式にして標準出力に出力する |
@@ -801,6 +804,7 @@ public class DbBigrelation | ||
801 | 804 | way.visibleStr = rset.getString("NODE.visible"); |
802 | 805 | way.versionStr = rset.getString("NODE.version"); |
803 | 806 | way.changeset = rset.getLong("NODE.changeset"); |
807 | + way.action = rset.getInt("NODE.action"); | |
804 | 808 | |
805 | 809 | ArrayList<NDref> nds = new ArrayList<NDref>(); |
806 | 810 | DbBigrelation.getNDs(con, nds, way.idref); |
@@ -3,6 +3,10 @@ package osm.jp; | ||
3 | 3 | import java.util.ArrayList; |
4 | 4 | |
5 | 5 | public class OsmNode { |
6 | + public static final int ACTION_NON = 0; | |
7 | + public static final int ACTION_MODIFY = 1; | |
8 | + public static final int ACTION_DELETE = 2; | |
9 | + | |
6 | 10 | public long idref = 0L; |
7 | 11 | public String timestampStr = ""; |
8 | 12 | public long uid = 0L; |
@@ -12,6 +16,7 @@ public class OsmNode { | ||
12 | 16 | public double lat = 0.0D; |
13 | 17 | public double lon = 0.0D; |
14 | 18 | public long changeset = 0L; |
19 | + public int action = OsmNode.ACTION_NON; | |
15 | 20 | private double cnt = 0.0D; // Table.NDREF (index counter) |
16 | 21 | |
17 | 22 | public ArrayList<Tag> tags = new ArrayList<Tag>(); |
@@ -27,6 +32,7 @@ public class OsmNode { | ||
27 | 32 | this.lon = 0.0D; |
28 | 33 | this.changeset = 0L; |
29 | 34 | this.cnt = 0.0D; |
35 | + this.action = OsmNode.ACTION_NON; | |
30 | 36 | } |
31 | 37 | |
32 | 38 | public OsmNode(OsmNode osmnode) { |
@@ -41,10 +47,9 @@ public class OsmNode { | ||
41 | 47 | this.lon = osmnode.lon; |
42 | 48 | this.changeset = osmnode.changeset; |
43 | 49 | this.cnt = osmnode.cnt; |
50 | + this.action = osmnode.action; | |
44 | 51 | } |
45 | 52 | |
46 | - | |
47 | - | |
48 | 53 | public void setCounter(double cnt) { |
49 | 54 | this.cnt = cnt; |
50 | 55 | } |
@@ -75,8 +80,12 @@ public class OsmNode { | ||
75 | 80 | if (idref < 0) { |
76 | 81 | return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"' lat='"+ lat +"' lon='"+ lon +"'"); |
77 | 82 | } |
78 | - else { | |
79 | - return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"' lat='"+ lat +"' lon='"+ lon +"'"); | |
83 | + if (action == OsmNode.ACTION_MODIFY) { | |
84 | + return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"' lat='"+ lat +"' lon='"+ lon +"'"); | |
85 | + } | |
86 | + if (action == OsmNode.ACTION_DELETE) { | |
87 | + return ("id='"+ idref +"' action='delete' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"' lat='"+ lat +"' lon='"+ lon +"'"); | |
80 | 88 | } |
89 | + return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"' lat='"+ lat +"' lon='"+ lon +"'"); | |
81 | 90 | } |
82 | 91 | } |
@@ -167,6 +167,8 @@ public class RelationCutter { | ||
167 | 167 | } |
168 | 168 | |
169 | 169 | // 元のWAYをDBから削除する |
170 | + DbBigrelation.delete_WAY(con, way); | |
171 | + way.waynodes = new ArrayList<OsmNode>(); | |
170 | 172 | } |
171 | 173 | else { |
172 | 174 | if (isLatBoundary(osmnode.lat)) { |
@@ -486,7 +488,6 @@ public class RelationCutter { | ||
486 | 488 | String changesetStr = ""; |
487 | 489 | String latStr = "0.0"; |
488 | 490 | String lonStr = "0.0"; |
489 | - int osmtype = DbBigrelation.OSM_NODE; | |
490 | 491 | |
491 | 492 | NamedNodeMap nodeMap = node.getAttributes(); |
492 | 493 | if ( null != nodeMap ) { |
@@ -520,15 +521,40 @@ public class RelationCutter { | ||
520 | 521 | } |
521 | 522 | |
522 | 523 | if (node.getNodeName().equals("node")) { |
523 | - osmtype = DbBigrelation.OSM_NODE; | |
524 | + OsmNode osm = new OsmNode(); | |
525 | + osm.idref = Long.parseLong(idStr); | |
526 | + osm.timestampStr = timestampStr; | |
527 | + osm.uid = Long.parseLong(uidStr); | |
528 | + osm.userStr = userStr; | |
529 | + osm.visibleStr = visibleStr; | |
530 | + osm.versionStr = versionStr; | |
531 | + osm.changeset = Long.parseLong(changesetStr); | |
532 | + osm.lat = Double.parseDouble(latStr); | |
533 | + osm.lon = Double.parseDouble(lonStr); | |
534 | + DbBigrelation.insert_NODE(con, osm); | |
524 | 535 | } |
525 | 536 | else if (node.getNodeName().equals("way")) { |
526 | - osmtype = DbBigrelation.OSM_WAY; | |
537 | + Way osm = new Way(); | |
538 | + osm.idref = Long.parseLong(idStr); | |
539 | + osm.timestampStr = timestampStr; | |
540 | + osm.uid = Long.parseLong(uidStr); | |
541 | + osm.userStr = userStr; | |
542 | + osm.visibleStr = visibleStr; | |
543 | + osm.versionStr = versionStr; | |
544 | + osm.changeset = Long.parseLong(changesetStr); | |
545 | + DbBigrelation.insert_WAY(con, osm); | |
527 | 546 | } |
528 | 547 | else if (node.getNodeName().equals("relation")) { |
529 | - osmtype = DbBigrelation.OSM_RELATION; | |
548 | + Relation osm = new Relation(); | |
549 | + osm.id = Long.parseLong(idStr); | |
550 | + osm.timestampStr = timestampStr; | |
551 | + osm.uid = Long.parseLong(uidStr); | |
552 | + osm.userStr = userStr; | |
553 | + osm.visibleStr = visibleStr; | |
554 | + osm.versionStr = versionStr; | |
555 | + osm.changeset = Long.parseLong(changesetStr); | |
556 | + DbBigrelation.insert_RELATION(con, osm); | |
530 | 557 | } |
531 | - DbBigrelation.insert_NODE(con, idStr, timestampStr, uidStr, userStr, visibleStr, versionStr, changesetStr, latStr, lonStr, osmtype); | |
532 | 558 | } |
533 | 559 | } |
534 | 560 |
@@ -25,6 +25,7 @@ public class Way { | ||
25 | 25 | public String visibleStr = ""; |
26 | 26 | public String versionStr = ""; |
27 | 27 | public long changeset = 0L; |
28 | + public int action = OsmNode.ACTION_NON; | |
28 | 29 | |
29 | 30 | ArrayList<Tag> tags = new ArrayList<Tag>(); |
30 | 31 | ArrayList<OsmNode> waynodes = new ArrayList<OsmNode>(); |
@@ -37,6 +38,7 @@ public class Way { | ||
37 | 38 | this.visibleStr = ""; |
38 | 39 | this.versionStr = ""; |
39 | 40 | this.changeset = 0L; |
41 | + this.action = OsmNode.ACTION_NON; | |
40 | 42 | } |
41 | 43 | |
42 | 44 | public Way(Way source) { |
@@ -47,6 +49,7 @@ public class Way { | ||
47 | 49 | this.visibleStr = source.visibleStr; |
48 | 50 | this.versionStr = source.versionStr; |
49 | 51 | this.changeset = source.changeset; |
52 | + this.action = source.action; | |
50 | 53 | |
51 | 54 | this.tags = new ArrayList<Tag>(); |
52 | 55 | Iterator<Tag> itag = tags.iterator(); |
@@ -67,12 +70,15 @@ public class Way { | ||
67 | 70 | if (idref < 0) { |
68 | 71 | return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"'"); |
69 | 72 | } |
70 | - else { | |
71 | - return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'"); | |
73 | + if (action == OsmNode.ACTION_MODIFY) { | |
74 | + return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"'"); | |
72 | 75 | } |
73 | - | |
76 | + if (action == OsmNode.ACTION_DELETE) { | |
77 | + return ("id='"+ idref +"' action='delete' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'"); | |
78 | + } | |
79 | + return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'"); | |
74 | 80 | } |
75 | - | |
81 | + | |
76 | 82 | public int loadTag(Connection con) throws SQLException { |
77 | 83 | tags = new ArrayList<Tag>(); |
78 | 84 | DbBigrelation.getTags(con, tags, this.idref); |