巨大森林を分割する
Revisão | d657905b22beef4786d7ef00164f20023c50be58 (tree) |
---|---|
Hora | 2013-07-28 20:55:44 |
Autor | hayashi.yuu <hayashi.yuu@gmai...> |
Commiter | hayashi.yuu |
分割点でWAYを分割
@@ -1,3 +1,4 @@ | ||
1 | 1 | #!/bin/sh |
2 | 2 | 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 |
@@ -167,12 +167,14 @@ public class DbBigrelation | ||
167 | 167 | * ref BIGINT NOT NULL |
168 | 168 | * type VARCHAR(128) |
169 | 169 | * role VARCHAR(128) |
170 | + * relationid BIGINT | |
171 | + * cnt DOUBLE | |
170 | 172 | * |
171 | 173 | * @param con |
172 | 174 | * @throws SQLException |
173 | 175 | */ |
174 | 176 | 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);"; | |
176 | 178 | Logger.logger.info(createSt); |
177 | 179 | PreparedStatement ps = con.prepareStatement(createSt); |
178 | 180 | try { |
@@ -280,6 +282,21 @@ public class DbBigrelation | ||
280 | 282 | ps.close(); |
281 | 283 | } |
282 | 284 | |
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 | + | |
283 | 300 | /** |
284 | 301 | * |
285 | 302 | * idref BIGINT NOT NULL |
@@ -339,27 +356,25 @@ public class DbBigrelation | ||
339 | 356 | * role VARCHAR(128) |
340 | 357 | * |
341 | 358 | * @param con |
342 | - * @param idStr | |
343 | - * @param keyStr | |
344 | - * @param valueStr | |
359 | + * @param member | |
345 | 360 | * @throws SQLException |
346 | 361 | */ |
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 | |
352 | 363 | { |
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); | |
359 | 374 | ps6.executeUpdate(); |
360 | 375 | ps6.close(); |
361 | 376 | } |
362 | - | |
377 | + | |
363 | 378 | /** |
364 | 379 | * 'table.NODE'の内容をCSV形式にして標準出力に出力する |
365 | 380 | * 'table.TAG'の内容をCSV形式にして標準出力に出力する |
@@ -813,7 +828,7 @@ public class DbBigrelation | ||
813 | 828 | ow.newLine(); |
814 | 829 | while (ii.hasNext()) { |
815 | 830 | Tag tag = ii.next(); |
816 | - ow.write(" <node "+ tag.show() +" />"); | |
831 | + ow.write(" <tag "+ tag.show() +" />"); | |
817 | 832 | ow.newLine(); |
818 | 833 | } |
819 | 834 | ow.write(" </node>"); |
@@ -840,4 +855,55 @@ public class DbBigrelation | ||
840 | 855 | rset.close(); |
841 | 856 | return idref; |
842 | 857 | } |
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 | + } | |
843 | 909 | } |
\ No newline at end of file |
@@ -10,8 +10,33 @@ public class Member { | ||
10 | 10 | public long ref = 0L; |
11 | 11 | public String typeStr = ""; |
12 | 12 | public String roleStr = ""; |
13 | + public long relationid = 0L; | |
14 | + public double cnt = 0.0D; | |
13 | 15 | |
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 | + */ | |
14 | 39 | public String show() { |
15 | - return ("id='"+ idref +"' ref='"+ ref +"' type='"+ typeStr +"' role='"+ roleStr +"'"); | |
40 | + return ("id='"+ idref +"' type='"+ typeStr +"' ref='"+ ref +"' role='"+ roleStr +"'"); | |
16 | 41 | } |
17 | 42 | } |
@@ -1,5 +1,7 @@ | ||
1 | 1 | package osm.jp; |
2 | 2 | |
3 | +import java.util.ArrayList; | |
4 | + | |
3 | 5 | public class OsmNode { |
4 | 6 | public long idref = 0L; |
5 | 7 | public String timestampStr = ""; |
@@ -12,6 +14,8 @@ public class OsmNode { | ||
12 | 14 | public long changeset = 0L; |
13 | 15 | private double cnt = 0.0D; // Table.NDREF (index counter) |
14 | 16 | |
17 | + public ArrayList<Tag> tags = new ArrayList<Tag>(); | |
18 | + | |
15 | 19 | public OsmNode() { |
16 | 20 | this.idref = 0L; |
17 | 21 | this.timestampStr = ""; |
@@ -39,6 +43,8 @@ public class OsmNode { | ||
39 | 43 | this.cnt = osmnode.cnt; |
40 | 44 | } |
41 | 45 | |
46 | + | |
47 | + | |
42 | 48 | public void setCounter(double cnt) { |
43 | 49 | this.cnt = cnt; |
44 | 50 | } |
@@ -57,7 +63,7 @@ public class OsmNode { | ||
57 | 63 | //if (!this.timestampStr.equals(osmnode.timestampStr)) return false; |
58 | 64 | //if (this.uid != osmnode.uid) return false; |
59 | 65 | //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; | |
61 | 67 | //if (!this.versionStr.equals(osmnode.versionStr)) return false; |
62 | 68 | if (this.lat != osmnode.lat) return false; |
63 | 69 | if (this.lon != osmnode.lon) return false; |
@@ -1,5 +1,9 @@ | ||
1 | 1 | package osm.jp; |
2 | 2 | |
3 | +import java.sql.Connection; | |
4 | +import java.sql.SQLException; | |
5 | +import java.util.ArrayList; | |
6 | + | |
3 | 7 | public class Relation { |
4 | 8 | public long id = 0L; |
5 | 9 | public String timestampStr = ""; |
@@ -9,7 +13,33 @@ public class Relation { | ||
9 | 13 | public String versionStr = ""; |
10 | 14 | public long changeset = 0L; |
11 | 15 | |
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 | + */ | |
12 | 36 | 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 | + } | |
14 | 44 | } |
15 | 45 | } |
@@ -10,12 +10,8 @@ import org.xml.sax.*; | ||
10 | 10 | |
11 | 11 | import java.io.*; |
12 | 12 | import java.sql.Connection; |
13 | -import java.sql.PreparedStatement; | |
14 | 13 | import java.sql.SQLException; |
15 | -import java.text.SimpleDateFormat; | |
16 | 14 | import java.util.ArrayList; |
17 | -import java.util.Calendar; | |
18 | -import java.util.Date; | |
19 | 15 | import java.util.Iterator; |
20 | 16 | |
21 | 17 |
@@ -42,7 +38,7 @@ public class RelationCutter { | ||
42 | 38 | /** |
43 | 39 | * アプリケーション [ConvBusstop] |
44 | 40 | * > java -jar ConvBusstop.jar <オプション> |
45 | - * オプション: -exp 実行する直前にデータベースを初期化する(省略可能) | |
41 | + * オプション: 実行する直前にデータベースを初期化する(省略可能) | |
46 | 42 | */ |
47 | 43 | if (args.length <= 0) { |
48 | 44 | Logger.logger.warning("インポートファイルが指定されていません。"); |
@@ -101,27 +97,111 @@ public class RelationCutter { | ||
101 | 97 | before = new OsmNode(osmnode); |
102 | 98 | continue; |
103 | 99 | } |
100 | + OsmNode newnode = null; | |
104 | 101 | do { |
105 | - OsmNode newnode = bundary(con, before, osmnode); | |
102 | + newnode = bundary(con, before, osmnode); | |
106 | 103 | if (newnode == null) { |
107 | 104 | before = new OsmNode(osmnode); |
108 | 105 | } |
109 | 106 | else { |
110 | - // WAYにbundaryノードを挿入する | |
107 | + // WAYにboundaryノードを挿入する | |
111 | 108 | newnode.setCounter((before.getCounter() + osmnode.getCounter()) / 2.0D); |
112 | 109 | DbBigrelation.insert_NDREF(con, way.idref, newnode.idref, newnode.getCounter()); |
113 | 110 | |
114 | 111 | before = new OsmNode(newnode); |
115 | 112 | } |
116 | 113 | } |
117 | - while (before.lat != osmnode.lat); | |
114 | + while (newnode != null); | |
118 | 115 | } |
119 | 116 | } |
120 | 117 | } |
121 | 118 | } |
122 | 119 | |
123 | 120 | /* |
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. | |
125 | 205 | */ |
126 | 206 | outputDb(con, "new.osm"); |
127 | 207 | } |
@@ -131,66 +211,84 @@ public class RelationCutter { | ||
131 | 211 | } |
132 | 212 | |
133 | 213 | public static OsmNode bundary(Connection con, OsmNode before, OsmNode osmnode) throws IOException, SQLException { |
134 | - // exp) lat=35.549817, lon=139.137575 | |
135 | 214 | double lat1 = getLatBundary(before.lat); |
136 | - //double lon1 = getLonBundary(before.lon); | |
137 | 215 | double lat2 = getLatBundary(osmnode.lat); |
138 | - //double lon2 = getLonBundary(osmnode.lon); | |
139 | 216 | if (lat1 == lat2) { |
140 | 217 | return null; |
141 | 218 | } |
142 | - OsmNode bundary; | |
219 | + //double lon1 = getLonBundary(before.lon); | |
220 | + //double lon2 = getLonBundary(osmnode.lon); | |
143 | 221 | |
144 | - if ((lat2 - lat1) < 0) { | |
145 | - // East to West | |
222 | + OsmNode bundary = null; | |
223 | + | |
224 | + if ((lat2 - lat1) < 0.0D) { | |
225 | + // North to South | |
146 | 226 | if ((lat1 == osmnode.lat) || (lat1 == before.lat)) { |
147 | 227 | return null; |
148 | 228 | } |
149 | 229 | |
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 | + } | |
160 | 247 | } |
161 | 248 | else { |
162 | - // West to East | |
249 | + // South to North | |
163 | 250 | if ((lat2 == before.lat) || (lat2 == osmnode.lat)) { |
164 | 251 | return null; |
165 | 252 | } |
166 | 253 | |
167 | 254 | 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 | + } | |
177 | 271 | } |
272 | + System.out.println("["+ before.lat +" ==>("+ bundary.lat +":"+ bundary.lon +")==> "+ osmnode.lat +"]"); | |
178 | 273 | |
179 | - // 新規WAYをDBに追加する | |
274 | + // 新規NODEをDBに追加する | |
180 | 275 | long nodeid = insertOsmNode2db(con, bundary); |
181 | 276 | System.out.println("\tNew Bundary node: "+ bundary.show()); |
182 | 277 | bundary.idref = nodeid; |
183 | 278 | return bundary; |
184 | 279 | } |
185 | 280 | |
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 | + | |
186 | 288 | public static double getLatBundary(double lat) { |
187 | 289 | double latd = (lat - (int)lat) * 48.0D; |
188 | 290 | latd = (double)((int)latd / 48.0D); |
189 | 291 | latd = (double)(((long)(latd * 10000000L)) / 10000000.0D); |
190 | - double bound = (double)((int)lat + latd); | |
191 | - if (bound == lat) { | |
192 | - return (bound - 0.0208333D); | |
193 | - } | |
194 | 292 | return (double)((int)lat + latd); |
195 | 293 | } |
196 | 294 |
@@ -198,10 +296,6 @@ public class RelationCutter { | ||
198 | 296 | double lond = (lon - (int)lon) * 32.0D; |
199 | 297 | lond = (double)((int)lond / 32.0D); |
200 | 298 | lond = (double)(((long)(lond * 10000000L)) / 10000000.0D); |
201 | - double bound = (double)((int)lon + lond); | |
202 | - if (bound == lon) { | |
203 | - return (bound - 0.0312500D); | |
204 | - } | |
205 | 299 | return (double)((int)lon + lond); |
206 | 300 | } |
207 | 301 |
@@ -475,7 +569,7 @@ public class RelationCutter { | ||
475 | 569 | * @throws IOException |
476 | 570 | * @throws SQLException |
477 | 571 | */ |
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 { | |
479 | 573 | // node = MEMBER |
480 | 574 | String refStr = ""; |
481 | 575 | String typeStr = ""; |
@@ -493,8 +587,14 @@ public class RelationCutter { | ||
493 | 587 | if ((attr = nodeMap.getNamedItem("role")) != null) { |
494 | 588 | roleStr = attr.getNodeValue(); |
495 | 589 | } |
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; | |
496 | 596 | |
497 | - DbBigrelation.insert_MEMBER(con, id, Long.parseLong(refStr), typeStr, roleStr); | |
597 | + DbBigrelation.insert_MEMBER(con, member); | |
498 | 598 | } |
499 | 599 | } |
500 | 600 |
@@ -521,78 +621,80 @@ public class RelationCutter { | ||
521 | 621 | } |
522 | 622 | } |
523 | 623 | |
624 | + /** | |
625 | + * create new OSMNODE in database | |
626 | + * @param con | |
627 | + * @param node | |
628 | + * @return | |
629 | + * @throws IOException | |
630 | + * @throws SQLException | |
631 | + */ | |
524 | 632 | 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; | |
531 | 642 | } |
532 | - node.idref = id; | |
533 | 643 | DbBigrelation.insert_NODE(con, node); |
534 | - return id; | |
644 | + DbBigrelation.insert_TAG(con, node.idref, "fixme", "node(id="+ node.idref +")"); | |
645 | + return node.idref; | |
535 | 646 | } |
536 | 647 | |
537 | 648 | /** |
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 | |
542 | 650 | * @param con |
543 | - * @param node | |
651 | + * @param way | |
652 | + * @return | |
544 | 653 | * @throws IOException |
545 | 654 | * @throws SQLException |
546 | 655 | */ |
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; | |
559 | 661 | } |
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; | |
582 | 664 | } |
665 | + way.idref = id; | |
583 | 666 | } |
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; | |
584 | 676 | } |
585 | 677 | |
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; | |
593 | 696 | } |
594 | - return true; | |
697 | + DbBigrelation.insert_MEMBER(con, member); | |
698 | + return member.idref; | |
595 | 699 | } |
596 | - | |
597 | - | |
598 | 700 | } |
\ No newline at end of file |
@@ -1,5 +1,10 @@ | ||
1 | 1 | package osm.jp; |
2 | 2 | |
3 | +import java.sql.Connection; | |
4 | +import java.sql.SQLException; | |
5 | +import java.util.ArrayList; | |
6 | +import java.util.Iterator; | |
7 | + | |
3 | 8 | /** |
4 | 9 | * |
5 | 10 | * <way id='161839750' |
@@ -21,8 +26,50 @@ public class Way { | ||
21 | 26 | public String versionStr = ""; |
22 | 27 | public long changeset = 0L; |
23 | 28 | |
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 | + | |
24 | 66 | public String show() { |
25 | 67 | return ("id='"+ idref +"' timestamp='"+ timestampStr +"' uid='"+ uid +"' user='"+ userStr +"' visible='"+ visibleStr +"' version='"+ versionStr +"' changeset='"+ changeset +"'"); |
26 | 68 | } |
27 | 69 | |
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 | + } | |
28 | 75 | } |