• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

巨大森林を分割する


Commit MetaInfo

Revisãoa7bfcd8cca29db5520944993851b6c685d113a55 (tree)
Hora2013-08-03 11:34:10
Autorhayashi.yuu <hayashi.yuu@gmai...>
Commiterhayashi.yuu

Mensagem de Log

WAYのaction='delete' に対応

Mudança Sumário

Diff

--- a/src/osm/jp/DbBigrelation.java
+++ b/src/osm/jp/DbBigrelation.java
@@ -61,6 +61,8 @@ public class DbBigrelation
6161 * @throws SQLException
6262 */
6363 public static void create(Connection con) throws SQLException {
64+ drop(con);
65+
6466 if (!isTable(con, "NODE")) {
6567 create_NODE(con);
6668 }
@@ -99,6 +101,7 @@ public class DbBigrelation
99101 *
100102 * idref BIGINT NOT NULL
101103 * osmtype INTEGER
104+ * action INT
102105 * timestamp VARCHAR(20)
103106 * uid BIGINT
104107 * user VARCHAR(64)
@@ -112,7 +115,7 @@ public class DbBigrelation
112115 * @throws SQLException
113116 */
114117 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));";
116119 Logger.logger.info(createSt);
117120 PreparedStatement ps = con.prepareStatement(createSt);
118121 try {
@@ -198,12 +201,12 @@ public class DbBigrelation
198201 * role VARCHAR(128)
199202 * relationid BIGINT
200203 * cnt DOUBLE
201- *
204+ * action INT
202205 * @param con
203206 * @throws SQLException
204207 */
205208 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);";
207210 Logger.logger.info(createSt);
208211 PreparedStatement ps = con.prepareStatement(createSt);
209212 try {
@@ -226,11 +229,18 @@ public class DbBigrelation
226229 * @throws SQLException
227230 */
228231 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+ }
234244 }
235245
236246 /**
@@ -246,60 +256,6 @@ public class DbBigrelation
246256 ps.close();
247257 }
248258
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- }
303259
304260 public static void insert_NODE(Connection con, OsmNode node) throws SQLException
305261 {
@@ -310,7 +266,7 @@ public class DbBigrelation
310266 node.idref = -1;
311267 }
312268 }
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 (?,?,?,?,?,?,?,?,?,?,?)");
314270 ps.setLong(1, node.idref);
315271 ps.setString(2, node.timestampStr);
316272 ps.setLong(3, node.uid);
@@ -321,13 +277,21 @@ public class DbBigrelation
321277 ps.setDouble(8, node.lat);
322278 ps.setDouble(9, node.lon);
323279 ps.setInt(10, DbBigrelation.OSM_NODE);
280+ ps.setInt(11, node.action);
324281 ps.executeUpdate();
325282 ps.close();
326283 }
327284
328285 public static void insert_WAY(Connection con, Way way) throws SQLException
329286 {
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 (?,?,?,?,?,?,?,?,?)");
331295 ps.setLong(1, way.idref);
332296 ps.setString(2, way.timestampStr);
333297 ps.setLong(3, way.uid);
@@ -336,6 +300,22 @@ public class DbBigrelation
336300 ps.setString(6, way.versionStr);
337301 ps.setLong(7, way.changeset);
338302 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);
339319 ps.executeUpdate();
340320 ps.close();
341321 }
@@ -420,6 +400,29 @@ public class DbBigrelation
420400 ps6.executeUpdate();
421401 ps6.close();
422402 }
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+ }
423426
424427 /**
425428 * 'table.NODE'の内容をCSV形式にして標準出力に出力する
@@ -801,6 +804,7 @@ public class DbBigrelation
801804 way.visibleStr = rset.getString("NODE.visible");
802805 way.versionStr = rset.getString("NODE.version");
803806 way.changeset = rset.getLong("NODE.changeset");
807+ way.action = rset.getInt("NODE.action");
804808
805809 ArrayList<NDref> nds = new ArrayList<NDref>();
806810 DbBigrelation.getNDs(con, nds, way.idref);
--- a/src/osm/jp/OsmNode.java
+++ b/src/osm/jp/OsmNode.java
@@ -3,6 +3,10 @@ package osm.jp;
33 import java.util.ArrayList;
44
55 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+
610 public long idref = 0L;
711 public String timestampStr = "";
812 public long uid = 0L;
@@ -12,6 +16,7 @@ public class OsmNode {
1216 public double lat = 0.0D;
1317 public double lon = 0.0D;
1418 public long changeset = 0L;
19+ public int action = OsmNode.ACTION_NON;
1520 private double cnt = 0.0D; // Table.NDREF (index counter)
1621
1722 public ArrayList<Tag> tags = new ArrayList<Tag>();
@@ -27,6 +32,7 @@ public class OsmNode {
2732 this.lon = 0.0D;
2833 this.changeset = 0L;
2934 this.cnt = 0.0D;
35+ this.action = OsmNode.ACTION_NON;
3036 }
3137
3238 public OsmNode(OsmNode osmnode) {
@@ -41,10 +47,9 @@ public class OsmNode {
4147 this.lon = osmnode.lon;
4248 this.changeset = osmnode.changeset;
4349 this.cnt = osmnode.cnt;
50+ this.action = osmnode.action;
4451 }
4552
46-
47-
4853 public void setCounter(double cnt) {
4954 this.cnt = cnt;
5055 }
@@ -75,8 +80,12 @@ public class OsmNode {
7580 if (idref < 0) {
7681 return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"' lat='"+ lat +"' lon='"+ lon +"'");
7782 }
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 +"'");
8088 }
89+ return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"' lat='"+ lat +"' lon='"+ lon +"'");
8190 }
8291 }
--- a/src/osm/jp/RelationCutter.java
+++ b/src/osm/jp/RelationCutter.java
@@ -167,6 +167,8 @@ public class RelationCutter {
167167 }
168168
169169 // 元のWAYをDBから削除する
170+ DbBigrelation.delete_WAY(con, way);
171+ way.waynodes = new ArrayList<OsmNode>();
170172 }
171173 else {
172174 if (isLatBoundary(osmnode.lat)) {
@@ -486,7 +488,6 @@ public class RelationCutter {
486488 String changesetStr = "";
487489 String latStr = "0.0";
488490 String lonStr = "0.0";
489- int osmtype = DbBigrelation.OSM_NODE;
490491
491492 NamedNodeMap nodeMap = node.getAttributes();
492493 if ( null != nodeMap ) {
@@ -520,15 +521,40 @@ public class RelationCutter {
520521 }
521522
522523 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);
524535 }
525536 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);
527546 }
528547 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);
530557 }
531- DbBigrelation.insert_NODE(con, idStr, timestampStr, uidStr, userStr, visibleStr, versionStr, changesetStr, latStr, lonStr, osmtype);
532558 }
533559 }
534560
--- a/src/osm/jp/Way.java
+++ b/src/osm/jp/Way.java
@@ -25,6 +25,7 @@ public class Way {
2525 public String visibleStr = "";
2626 public String versionStr = "";
2727 public long changeset = 0L;
28+ public int action = OsmNode.ACTION_NON;
2829
2930 ArrayList<Tag> tags = new ArrayList<Tag>();
3031 ArrayList<OsmNode> waynodes = new ArrayList<OsmNode>();
@@ -37,6 +38,7 @@ public class Way {
3738 this.visibleStr = "";
3839 this.versionStr = "";
3940 this.changeset = 0L;
41+ this.action = OsmNode.ACTION_NON;
4042 }
4143
4244 public Way(Way source) {
@@ -47,6 +49,7 @@ public class Way {
4749 this.visibleStr = source.visibleStr;
4850 this.versionStr = source.versionStr;
4951 this.changeset = source.changeset;
52+ this.action = source.action;
5053
5154 this.tags = new ArrayList<Tag>();
5255 Iterator<Tag> itag = tags.iterator();
@@ -67,12 +70,15 @@ public class Way {
6770 if (idref < 0) {
6871 return ("id='"+ idref +"' action='modify' visible='"+ visibleStr +"'");
6972 }
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 +"'");
7275 }
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 +"'");
7480 }
75-
81+
7682 public int loadTag(Connection con) throws SQLException {
7783 tags = new ArrayList<Tag>();
7884 DbBigrelation.getTags(con, tags, this.idref);