• 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ãod657905b22beef4786d7ef00164f20023c50be58 (tree)
Hora2013-07-28 20:55:44
Autorhayashi.yuu <hayashi.yuu@gmai...>
Commiterhayashi.yuu

Mensagem de Log

分割点でWAYを分割

Mudança Sumário

Diff

--- a/osmCutter.sh
+++ b/osmCutter.sh
@@ -1,3 +1,4 @@
11 #!/bin/sh
22 rm -r database
3-java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter natural_wood_kanagawa.osm
3+# java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter natural_wood_kanagawa.osm
4+java -cp .:OsmCutter.jar:../hayashi_0225.jar:../hsqldb.jar osm.jp.RelationCutter koubouyama159740689.osm
\ No newline at end of file
--- a/src/osm/jp/DbBigrelation.java
+++ b/src/osm/jp/DbBigrelation.java
@@ -167,12 +167,14 @@ public class DbBigrelation
167167 * ref BIGINT NOT NULL
168168 * type VARCHAR(128)
169169 * role VARCHAR(128)
170+ * relationid BIGINT
171+ * cnt DOUBLE
170172 *
171173 * @param con
172174 * @throws SQLException
173175 */
174176 public static void create_MEMBER(Connection con) throws SQLException {
175- String createSt = "create table MEMBER (idref BIGINT NOT NULL, ref BIGINT NOT NULL, type VARCHAR(128), role VARCHAR(128));";
177+ String createSt = "create table MEMBER (idref BIGINT NOT NULL, ref BIGINT NOT NULL, type VARCHAR(128), role VARCHAR(128), relationid BIGINT, cnt DOUBLE);";
176178 Logger.logger.info(createSt);
177179 PreparedStatement ps = con.prepareStatement(createSt);
178180 try {
@@ -280,6 +282,21 @@ public class DbBigrelation
280282 ps.close();
281283 }
282284
285+ public static void insert_WAY(Connection con, Way way) throws SQLException
286+ {
287+ PreparedStatement ps = con.prepareStatement("INSERT INTO node (idref,timestamp,uid,usr,visible,version,changeset,osmtype) VALUES (?,?,?,?,?,?,?,?)");
288+ ps.setLong(1, way.idref);
289+ ps.setString(2, way.timestampStr);
290+ ps.setLong(3, way.uid);
291+ ps.setString(4, way.userStr);
292+ ps.setString(5, way.visibleStr);
293+ ps.setString(6, way.versionStr);
294+ ps.setLong(7, way.changeset);
295+ ps.setInt(8, DbBigrelation.OSM_WAY);
296+ ps.executeUpdate();
297+ ps.close();
298+ }
299+
283300 /**
284301 *
285302 * idref BIGINT NOT NULL
@@ -339,27 +356,25 @@ public class DbBigrelation
339356 * role VARCHAR(128)
340357 *
341358 * @param con
342- * @param idStr
343- * @param keyStr
344- * @param valueStr
359+ * @param member
345360 * @throws SQLException
346361 */
347- public static void insert_MEMBER(Connection con,
348- long id,
349- long ref,
350- String type,
351- String role) throws SQLException
362+ public static void insert_MEMBER(Connection con, Member member) throws SQLException
352363 {
353- PreparedStatement ps6 = con.prepareStatement("INSERT INTO MEMBER (idref,ref,type,role) VALUES (?,?,?,?)");
354- ps6.setLong(1, id);
355- ps6.setLong(2, ref);
356- ps6.setString(3, type);
357- ps6.setString(4, role);
358- //System.out.println("MEMBER(id="+ id +" ref="+ ref +" type="+ type +" role="+ role +")");
364+ if (member.cnt == 0.0D) {
365+ member.cnt = DbBigrelation.getMEMBER_maxCNT(con, member.relationid) + 1.0D;
366+ }
367+ PreparedStatement ps6 = con.prepareStatement("INSERT INTO MEMBER (idref,ref,type,role,relationid,cnt) VALUES (?,?,?,?,?,?)");
368+ ps6.setLong(1, member.idref);
369+ ps6.setLong(2, member.ref);
370+ ps6.setString(3, member.typeStr);
371+ ps6.setString(4, member.roleStr);
372+ ps6.setLong(5, member.relationid);
373+ ps6.setDouble(6, member.cnt);
359374 ps6.executeUpdate();
360375 ps6.close();
361376 }
362-
377+
363378 /**
364379 * 'table.NODE'の内容をCSV形式にして標準出力に出力する
365380 * 'table.TAG'の内容をCSV形式にして標準出力に出力する
@@ -813,7 +828,7 @@ public class DbBigrelation
813828 ow.newLine();
814829 while (ii.hasNext()) {
815830 Tag tag = ii.next();
816- ow.write(" <node "+ tag.show() +" />");
831+ ow.write(" <tag "+ tag.show() +" />");
817832 ow.newLine();
818833 }
819834 ow.write(" </node>");
@@ -840,4 +855,55 @@ public class DbBigrelation
840855 rset.close();
841856 return idref;
842857 }
858+
859+ /**
860+ * Table.NODE からNODE.IDが最小のID値を取り出す。
861+ * @param con
862+ * @return
863+ * @throws SQLException
864+ */
865+ public static long getWAY_MinId(Connection con) throws SQLException {
866+ long idref = 0x7fffffffffffffffL;
867+ PreparedStatement ps = con.prepareStatement("select min(idref) from NODE where osmtype="+ OSM_WAY);
868+ ResultSet rset = ps.executeQuery();
869+ if (rset.next()) {
870+ idref = rset.getLong(1);
871+ }
872+ rset.close();
873+ return idref;
874+ }
875+
876+ /**
877+ * Table.MEMBER からMEMBER.IDが最小のID値を取り出す。
878+ * @param con
879+ * @return
880+ * @throws SQLException
881+ */
882+ public static long getMEMBER_MinId(Connection con) throws SQLException {
883+ long idref = 0x7fffffffffffffffL;
884+ PreparedStatement ps = con.prepareStatement("select min(idref) from MEMBER");
885+ ResultSet rset = ps.executeQuery();
886+ if (rset.next()) {
887+ idref = rset.getLong(1);
888+ }
889+ rset.close();
890+ return idref;
891+ }
892+
893+ /**
894+ * Table.MEMBER からMEMBER.IDが最小のID値を取り出す。
895+ * @param con
896+ * @return
897+ * @throws SQLException
898+ */
899+ public static double getMEMBER_maxCNT(Connection con, long relationid) throws SQLException {
900+ double maxCnt = 0.0D;
901+ PreparedStatement ps = con.prepareStatement("select max(cnt) from MEMBER where relationid="+ relationid);
902+ ResultSet rset = ps.executeQuery();
903+ if (rset.next()) {
904+ maxCnt = rset.getLong(1);
905+ }
906+ rset.close();
907+ return maxCnt;
908+ }
843909 }
\ No newline at end of file
--- a/src/osm/jp/Member.java
+++ b/src/osm/jp/Member.java
@@ -10,8 +10,33 @@ public class Member {
1010 public long ref = 0L;
1111 public String typeStr = "";
1212 public String roleStr = "";
13+ public long relationid = 0L;
14+ public double cnt = 0.0D;
1315
16+ public Member() {
17+ this.idref = 0L;
18+ this.ref = 0L;
19+ this.typeStr = "";
20+ this.roleStr = "";
21+ this.relationid = 0L;
22+ this.cnt = 0.0D;
23+ }
24+
25+ public Member(Member source) {
26+ this.idref = source.idref;
27+ this.ref = source.ref;
28+ this.typeStr = source.typeStr;
29+ this.roleStr = source.roleStr;
30+ this.relationid = source.relationid;
31+ this.cnt = source.cnt;
32+ }
33+
34+ /**
35+ * <member type='way' ref='-223310' role='outer' />
36+ * <member type='way' ref='90563930' role='inner' />
37+ * @return
38+ */
1439 public String show() {
15- return ("id='"+ idref +"' ref='"+ ref +"' type='"+ typeStr +"' role='"+ roleStr +"'");
40+ return ("id='"+ idref +"' type='"+ typeStr +"' ref='"+ ref +"' role='"+ roleStr +"'");
1641 }
1742 }
--- a/src/osm/jp/OsmNode.java
+++ b/src/osm/jp/OsmNode.java
@@ -1,5 +1,7 @@
11 package osm.jp;
22
3+import java.util.ArrayList;
4+
35 public class OsmNode {
46 public long idref = 0L;
57 public String timestampStr = "";
@@ -12,6 +14,8 @@ public class OsmNode {
1214 public long changeset = 0L;
1315 private double cnt = 0.0D; // Table.NDREF (index counter)
1416
17+ public ArrayList<Tag> tags = new ArrayList<Tag>();
18+
1519 public OsmNode() {
1620 this.idref = 0L;
1721 this.timestampStr = "";
@@ -39,6 +43,8 @@ public class OsmNode {
3943 this.cnt = osmnode.cnt;
4044 }
4145
46+
47+
4248 public void setCounter(double cnt) {
4349 this.cnt = cnt;
4450 }
@@ -57,7 +63,7 @@ public class OsmNode {
5763 //if (!this.timestampStr.equals(osmnode.timestampStr)) return false;
5864 //if (this.uid != osmnode.uid) return false;
5965 //if (!this.userStr.equals(osmnode.userStr)) return false;
60- //if (!this.visibleStr.equals(osmnode.visibleStr)) return false;
66+ if (!this.visibleStr.equals(osmnode.visibleStr)) return false;
6167 //if (!this.versionStr.equals(osmnode.versionStr)) return false;
6268 if (this.lat != osmnode.lat) return false;
6369 if (this.lon != osmnode.lon) return false;
--- a/src/osm/jp/Relation.java
+++ b/src/osm/jp/Relation.java
@@ -1,5 +1,9 @@
11 package osm.jp;
22
3+import java.sql.Connection;
4+import java.sql.SQLException;
5+import java.util.ArrayList;
6+
37 public class Relation {
48 public long id = 0L;
59 public String timestampStr = "";
@@ -9,7 +13,33 @@ public class Relation {
913 public String versionStr = "";
1014 public long changeset = 0L;
1115
16+ public ArrayList<Tag> tags = new ArrayList<Tag>();
17+ public ArrayList<Member> members = new ArrayList<Member>();
18+
19+ public int loadTag(Connection con) throws SQLException {
20+ tags = new ArrayList<Tag>();
21+ DbBigrelation.getTags(con, tags, this.id);
22+ return tags.size();
23+ }
24+
25+ public int loadMember(Connection con) throws SQLException {
26+ members = new ArrayList<Member>();
27+ DbBigrelation.getMembers(con, members, this.id);
28+ return members.size();
29+ }
30+
31+ /**
32+ * <relation id='-223340' action='modify' visible='true'>
33+ * <relation id='1331167' timestamp='2012-12-17T09:52:06Z' uid='621319' user='hayashi' visible='true' version='11' changeset='14303816'>
34+ * @return
35+ */
1236 public String show() {
13- return ("id='"+ id +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'");
37+ if (this.id == 0L) {
38+ // action='modify'
39+ return ("id='"+ id +"' action='modify' visible='"+ visibleStr +"'");
40+ }
41+ else {
42+ return ("id='"+ id +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'");
43+ }
1444 }
1545 }
--- a/src/osm/jp/RelationCutter.java
+++ b/src/osm/jp/RelationCutter.java
@@ -10,12 +10,8 @@ import org.xml.sax.*;
1010
1111 import java.io.*;
1212 import java.sql.Connection;
13-import java.sql.PreparedStatement;
1413 import java.sql.SQLException;
15-import java.text.SimpleDateFormat;
1614 import java.util.ArrayList;
17-import java.util.Calendar;
18-import java.util.Date;
1915 import java.util.Iterator;
2016
2117
@@ -42,7 +38,7 @@ public class RelationCutter {
4238 /**
4339 * アプリケーション [ConvBusstop]
4440 * > java -jar ConvBusstop.jar <オプション>
45- * オプション: -exp 実行する直前にデータベースを初期化する(省略可能)
41+ * オプション: 実行する直前にデータベースを初期化する(省略可能)
4642 */
4743 if (args.length <= 0) {
4844 Logger.logger.warning("インポートファイルが指定されていません。");
@@ -101,27 +97,111 @@ public class RelationCutter {
10197 before = new OsmNode(osmnode);
10298 continue;
10399 }
100+ OsmNode newnode = null;
104101 do {
105- OsmNode newnode = bundary(con, before, osmnode);
102+ newnode = bundary(con, before, osmnode);
106103 if (newnode == null) {
107104 before = new OsmNode(osmnode);
108105 }
109106 else {
110- // WAYにbundaryノードを挿入する
107+ // WAYにboundaryノードを挿入する
111108 newnode.setCounter((before.getCounter() + osmnode.getCounter()) / 2.0D);
112109 DbBigrelation.insert_NDREF(con, way.idref, newnode.idref, newnode.getCounter());
113110
114111 before = new OsmNode(newnode);
115112 }
116113 }
117- while (before.lat != osmnode.lat);
114+ while (newnode != null);
118115 }
119116 }
120117 }
121118 }
122119
123120 /*
124- * Output wite from DATABASE to OUTPUT file.
121+ *
122+ */
123+ Logger.logger.info("リレーションを読み出します。");
124+ Iterator<Relation> irelations = relations.iterator();
125+ while (irelations.hasNext()) {
126+ Relation relation = irelations.next();
127+ relation.loadMember(con);
128+ System.out.println("RELATION: "+ relation.show());
129+
130+ Iterator<Member> iii = relation.members.iterator();
131+ while (iii.hasNext()) {
132+ Member member = iii.next();
133+
134+ // MEMBER->WAY
135+ Way way = new Way();
136+ if (DbBigrelation.getWay(con, way, member.ref)) {
137+ DbBigrelation.getTags(con, way.tags, way.idref);
138+ DbBigrelation.getOsmnodes(con, way.waynodes, way.idref);
139+
140+ Way newway = new Way(way);
141+ newway.waynodes = new ArrayList<OsmNode>();
142+
143+ // 分割点を調べて、分割点でWAYを分割する。
144+ // WAYNODEの最初と最後は調べない
145+ for (int i = 0; i < way.waynodes.size(); i++) {
146+ OsmNode osmnode = way.waynodes.get(i);
147+ if (i == 0) {
148+ // 最初のノード
149+ newway.waynodes.add(osmnode);
150+ }
151+ else if ((i+1) == way.waynodes.size()) {
152+ // 最終のノード
153+ newway.waynodes.add(osmnode);
154+
155+ // 分割WAYをDATABASEに保存する
156+ if (newway.idref <= 0) {
157+ insertWAY2db(con, newway);
158+ System.out.println("\tNew WAY: "+ newway.show());
159+
160+ // NEWWAYをMEMBERに追加する
161+ Member newmember = new Member(member);
162+ newmember.idref = DbBigrelation.getMEMBER_MinId(con);
163+ newmember.ref = newway.idref;
164+ newmember.relationid = relation.id;
165+ insertMEMBER2db(con, newmember);
166+ }
167+
168+ // 元のWAYをDBから削除する
169+ }
170+ else {
171+ if (isLatBoundary(osmnode.lat)) {
172+ // WAYをboundaryノードで分割する
173+ OsmNode newnode = new OsmNode(osmnode);
174+ newnode.idref = DbBigrelation.getOsmnode_MinId(con);
175+ DbBigrelation.insert_NODE(con, newnode);
176+ newway.waynodes.add(newnode);
177+
178+ // NEWWAYをDBに追加する
179+ insertWAY2db(con, newway);
180+ System.out.println("\tNew WAY: "+ newway.show());
181+
182+ // NEWWAYをMEMBERに追加する
183+ Member newmember = new Member(member);
184+ newmember.idref = DbBigrelation.getMEMBER_MinId(con);
185+ newmember.ref = newway.idref;
186+ newmember.relationid = relation.id;
187+ insertMEMBER2db(con, newmember);
188+
189+ // この分割ノードから開始される新しいWAYを生成する
190+ newway = new Way(way);
191+ newway.waynodes = new ArrayList<OsmNode>();
192+ newway.waynodes.add(osmnode);
193+ }
194+ else {
195+ newway.waynodes.add(osmnode);
196+ }
197+ }
198+ }
199+ }
200+ }
201+ }
202+
203+ /*
204+ * Output write from DATABASE to OUTPUT file.
125205 */
126206 outputDb(con, "new.osm");
127207 }
@@ -131,66 +211,84 @@ public class RelationCutter {
131211 }
132212
133213 public static OsmNode bundary(Connection con, OsmNode before, OsmNode osmnode) throws IOException, SQLException {
134- // exp) lat=35.549817, lon=139.137575
135214 double lat1 = getLatBundary(before.lat);
136- //double lon1 = getLonBundary(before.lon);
137215 double lat2 = getLatBundary(osmnode.lat);
138- //double lon2 = getLonBundary(osmnode.lon);
139216 if (lat1 == lat2) {
140217 return null;
141218 }
142- OsmNode bundary;
219+ //double lon1 = getLonBundary(before.lon);
220+ //double lon2 = getLonBundary(osmnode.lon);
143221
144- if ((lat2 - lat1) < 0) {
145- // East to West
222+ OsmNode bundary = null;
223+
224+ if ((lat2 - lat1) < 0.0D) {
225+ // North to South
146226 if ((lat1 == osmnode.lat) || (lat1 == before.lat)) {
147227 return null;
148228 }
149229
150- double delta = (lat1 - osmnode.lat) / (before.lat - osmnode.lat);
151- double dLon = (before.lon - osmnode.lon) * delta;
152- dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
153-
154- // Bundary (LAT,LON) = (lat1, dLon)
155- bundary = new OsmNode(before);
156- bundary.lat = lat1;
157- bundary.lon = osmnode.lon + dLon;
158-
159- System.out.println("["+ osmnode.lat +" <==("+ bundary.lat +":"+ bundary.lon +")<== "+ before.lat +"]");
230+ double delta = (before.lat - lat1) / (before.lat - osmnode.lat);
231+ if ((osmnode.lon - before.lon) >= 0.0D) {
232+ // West to East
233+ double dLon = (osmnode.lon - before.lon) * delta;
234+ dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
235+ bundary = new OsmNode(before);
236+ bundary.lat = lat1;
237+ bundary.lon = before.lon + dLon;
238+ }
239+ else {
240+ // East to West
241+ double dLon = (before.lon - osmnode.lon) * delta;
242+ dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
243+ bundary = new OsmNode(before);
244+ bundary.lat = lat1;
245+ bundary.lon = before.lon - dLon;
246+ }
160247 }
161248 else {
162- // West to East
249+ // South to North
163250 if ((lat2 == before.lat) || (lat2 == osmnode.lat)) {
164251 return null;
165252 }
166253
167254 double delta = (lat2 - before.lat) / (osmnode.lat - before.lat);
168- double dLon = (osmnode.lon - before.lon) * delta;
169- dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
170-
171- // Bundary (LAT,LON) = (lat2, dLon)
172- bundary = new OsmNode(before);
173- bundary.lat = lat2;
174- bundary.lon = before.lon + dLon;
175-
176- System.out.println("["+ before.lat +" ==>("+ bundary.lat +":"+ bundary.lon +")==> "+ osmnode.lat +"]");
255+ if ((osmnode.lon - before.lon) >= 0.0D) {
256+ // West to East
257+ double dLon = (osmnode.lon - before.lon) * delta;
258+ dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
259+ bundary = new OsmNode(before);
260+ bundary.lat = lat2;
261+ bundary.lon = before.lon + dLon;
262+ }
263+ else {
264+ // East to West
265+ double dLon = (before.lon - osmnode.lon) * delta;
266+ dLon = (double)(((long)(dLon * 10000000L)) / 10000000.0D);
267+ bundary = new OsmNode(before);
268+ bundary.lat = lat2;
269+ bundary.lon = before.lon - dLon;
270+ }
177271 }
272+ System.out.println("["+ before.lat +" ==>("+ bundary.lat +":"+ bundary.lon +")==> "+ osmnode.lat +"]");
178273
179- // 新規WAYをDBに追加する
274+ // 新規NODEをDBに追加する
180275 long nodeid = insertOsmNode2db(con, bundary);
181276 System.out.println("\tNew Bundary node: "+ bundary.show());
182277 bundary.idref = nodeid;
183278 return bundary;
184279 }
185280
281+ public static boolean isLatBoundary(double lat) {
282+ double latd = (lat - (int)lat) * 48.0D;
283+ latd = (double)((int)latd / 48.0D);
284+ latd = (double)(((long)(latd * 10000000L)) / 10000000.0D);
285+ return (lat == latd);
286+ }
287+
186288 public static double getLatBundary(double lat) {
187289 double latd = (lat - (int)lat) * 48.0D;
188290 latd = (double)((int)latd / 48.0D);
189291 latd = (double)(((long)(latd * 10000000L)) / 10000000.0D);
190- double bound = (double)((int)lat + latd);
191- if (bound == lat) {
192- return (bound - 0.0208333D);
193- }
194292 return (double)((int)lat + latd);
195293 }
196294
@@ -198,10 +296,6 @@ public class RelationCutter {
198296 double lond = (lon - (int)lon) * 32.0D;
199297 lond = (double)((int)lond / 32.0D);
200298 lond = (double)(((long)(lond * 10000000L)) / 10000000.0D);
201- double bound = (double)((int)lon + lond);
202- if (bound == lon) {
203- return (bound - 0.0312500D);
204- }
205299 return (double)((int)lon + lond);
206300 }
207301
@@ -475,7 +569,7 @@ public class RelationCutter {
475569 * @throws IOException
476570 * @throws SQLException
477571 */
478- public static void importMEMBER(Connection con, Node node, long id) throws IOException, SQLException {
572+ public static void importMEMBER(Connection con, Node node, long relationid) throws IOException, SQLException {
479573 // node = MEMBER
480574 String refStr = "";
481575 String typeStr = "";
@@ -493,8 +587,14 @@ public class RelationCutter {
493587 if ((attr = nodeMap.getNamedItem("role")) != null) {
494588 roleStr = attr.getNodeValue();
495589 }
590+ Member member = new Member();
591+ member.idref = DbBigrelation.getMEMBER_MinId(con);
592+ member.ref = Long.parseLong(refStr);
593+ member.typeStr = typeStr;
594+ member.roleStr = roleStr;
595+ member.relationid = relationid;
496596
497- DbBigrelation.insert_MEMBER(con, id, Long.parseLong(refStr), typeStr, roleStr);
597+ DbBigrelation.insert_MEMBER(con, member);
498598 }
499599 }
500600
@@ -521,78 +621,80 @@ public class RelationCutter {
521621 }
522622 }
523623
624+ /**
625+ * create new OSMNODE in database
626+ * @param con
627+ * @param node
628+ * @return
629+ * @throws IOException
630+ * @throws SQLException
631+ */
524632 public static long insertOsmNode2db(Connection con, OsmNode node) throws IOException, SQLException {
525- long id = DbBigrelation.getOsmnode_MinId(con);
526- if (id < 0) {
527- id = id - 1L;
528- }
529- else {
530- id = -1;
633+ if (node.idref == 0L) {
634+ long id = DbBigrelation.getOsmnode_MinId(con);
635+ if (id < 0) {
636+ id = id - 1L;
637+ }
638+ else {
639+ id = -1;
640+ }
641+ node.idref = id;
531642 }
532- node.idref = id;
533643 DbBigrelation.insert_NODE(con, node);
534- return id;
644+ DbBigrelation.insert_TAG(con, node.idref, "fixme", "node(id="+ node.idref +")");
645+ return node.idref;
535646 }
536647
537648 /**
538- * <gml:Point gml:id="n1">
539- * <gml:pos>35.14591397 139.10569573</gml:pos>
540- * </gml:Point>
541- *
649+ * create new WAY in database
542650 * @param con
543- * @param node
651+ * @param way
652+ * @return
544653 * @throws IOException
545654 * @throws SQLException
546655 */
547- public static void showGmlPoint(Connection con, Node node) throws IOException, SQLException {
548- String positionStr = "";
549- String latStr = "";
550- String lonStr = "";
551- String idStr = "";
552-
553- NamedNodeMap nodeMap = node.getAttributes();
554- if ( null != nodeMap ) {
555- for ( int j=0; j<nodeMap.getLength(); j++ ) {
556- if (nodeMap.item(j).getNodeName().equals("gml:id")) {
557- idStr = nodeMap.item(j).getNodeValue();
558- }
656+ public static long insertWAY2db(Connection con, Way way) throws IOException, SQLException {
657+ if (way.idref == 0L) {
658+ long id = DbBigrelation.getOsmnode_MinId(con);
659+ if (id < 0) {
660+ id = id - 1L;
559661 }
560- }
561-
562- NodeList nodes = node.getChildNodes();
563- for (int i=0; i < nodes.getLength(); i++) {
564- Node node2 = nodes.item(i);
565- if (node2.getNodeName().equals("gml:pos")) {
566- positionStr = node2.getTextContent().trim();
567- String[] str4Ary = positionStr.split(" ");
568- latStr = str4Ary[0];
569- lonStr = str4Ary[1];
570-
571- PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
572- double lat = Double.parseDouble(latStr);
573- double lon = Double.parseDouble(lonStr);
574- Logger.logger.info("UPDATE bus_stop SET lat='"+ latStr +"',lon='"+ lonStr +"',fixed='"+ 0 +"' WHERE idref='"+ idStr +"'");
575-
576- ps6.setDouble(1, lat);
577- ps6.setDouble(2, lon);
578- ps6.setInt(3, 0);
579- ps6.setString(4, idStr);
580- ps6.executeUpdate();
581- ps6.close();
662+ else {
663+ id = -1;
582664 }
665+ way.idref = id;
583666 }
667+ DbBigrelation.insert_WAY(con, way);
668+ DbBigrelation.insert_TAG(con, way.idref, "fixme", "way(id="+ way.idref +")");
669+
670+ way.waynodes = new ArrayList<OsmNode>();
671+ for (int i=0; i < way.waynodes.size(); i++) {
672+ OsmNode waynode = way.waynodes.get(i);
673+ DbBigrelation.insert_NDREF(con, way.idref, waynode.idref, (double)i);
674+ }
675+ return way.idref;
584676 }
585677
586- static boolean checkFile(File f) {
587- String name = f.getName();
588- if (!name.startsWith("P11-")) {
589- return false;
590- }
591- if (!name.toUpperCase().endsWith(".XML")) {
592- return false;
678+ /**
679+ * create new WAY in database
680+ * @param con
681+ * @param way
682+ * @return
683+ * @throws IOException
684+ * @throws SQLException
685+ */
686+ public static long insertMEMBER2db(Connection con, Member member) throws IOException, SQLException {
687+ if (member.idref == 0L) {
688+ long id = DbBigrelation.getMEMBER_MinId(con);
689+ if (id < 0) {
690+ id = id - 1L;
691+ }
692+ else {
693+ id = -1;
694+ }
695+ member.idref = id;
593696 }
594- return true;
697+ DbBigrelation.insert_MEMBER(con, member);
698+ return member.idref;
595699 }
596-
597-
598700 }
\ No newline at end of file
--- a/src/osm/jp/Way.java
+++ b/src/osm/jp/Way.java
@@ -1,5 +1,10 @@
11 package osm.jp;
22
3+import java.sql.Connection;
4+import java.sql.SQLException;
5+import java.util.ArrayList;
6+import java.util.Iterator;
7+
38 /**
49 *
510 * <way id='161839750'
@@ -21,8 +26,50 @@ public class Way {
2126 public String versionStr = "";
2227 public long changeset = 0L;
2328
29+ ArrayList<Tag> tags = new ArrayList<Tag>();
30+ ArrayList<OsmNode> waynodes = new ArrayList<OsmNode>();
31+
32+ public Way() {
33+ this.idref = 0L;
34+ this.timestampStr = "";
35+ this.uid = 0L;
36+ this.userStr = "";
37+ this.visibleStr = "";
38+ this.versionStr = "";
39+ this.changeset = 0L;
40+ }
41+
42+ public Way(Way source) {
43+ this.idref = source.idref;
44+ this.timestampStr = source.timestampStr;
45+ this.uid = source.uid;
46+ this.userStr = source.userStr;
47+ this.visibleStr = source.visibleStr;
48+ this.versionStr = source.versionStr;
49+ this.changeset = source.changeset;
50+
51+ this.tags = new ArrayList<Tag>();
52+ Iterator<Tag> itag = tags.iterator();
53+ while (itag.hasNext()) {
54+ Tag tag = itag.next();
55+ this.tags.add(tag);
56+ }
57+
58+ this.waynodes = new ArrayList<OsmNode>();
59+ Iterator<OsmNode> inode = waynodes.iterator();
60+ while (inode.hasNext()) {
61+ OsmNode waynode = inode.next();
62+ this.waynodes.add(waynode);
63+ }
64+ }
65+
2466 public String show() {
2567 return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'");
2668 }
2769
70+ public int loadTag(Connection con) throws SQLException {
71+ tags = new ArrayList<Tag>();
72+ DbBigrelation.getTags(con, tags, this.idref);
73+ return tags.size();
74+ }
2875 }