OSM用の地名ノードに変換する
Revision | 22ad421b7a1567889e1ab6806c64db9a14d75011 (tree) |
---|---|
Time | 2016-04-30 00:09:29 |
Author | yuuhayashi <hayashi.yuu@gmai...> |
Commiter | yuuhayashi |
最新のJOSMに対応するために、OSMファイルのversionを0.5 から 0.6 にアップした。
@@ -27,7 +27,7 @@ | ||
27 | 27 | [STEP 2] コンパイル |
28 | 28 | --> |
29 | 29 | <target name="compile_src" depends="clean" description="コンパイル src"> |
30 | - <javac target="1.6" optimize="off" debug="on" verbose="false" srcdir="${src}" destdir="${classes}" encoding="UTF-8" > | |
30 | + <javac target="1.7" optimize="off" debug="on" verbose="false" srcdir="${src}" destdir="${classes}" encoding="UTF-8" > | |
31 | 31 | <include name="**" /> |
32 | 32 | <exclude name="**/*.smap" /> |
33 | 33 |
@@ -71,19 +71,23 @@ public class ConvAddr { | ||
71 | 71 | try { |
72 | 72 | // CSVファイルを読み取ってDB.table.ISJ_CHO に格納する |
73 | 73 | int fcounter = 0; |
74 | + int year = 0; | |
74 | 75 | if (args.length > index) { |
75 | 76 | File iFile = new File(args[index]); |
76 | - fcounter++; | |
77 | - inputFile(con, iFile); | |
77 | + if ((year = checkFile(iFile)) > 0) { | |
78 | + logger.info("ファイル '"+ iFile.getName() +"' を読み込みます。"); | |
79 | + fcounter++; | |
80 | + inputFile(con, iFile, year); | |
81 | + } | |
78 | 82 | } |
79 | 83 | else { |
80 | 84 | File dir = new File("."); |
81 | 85 | File[] files = dir.listFiles(); |
82 | 86 | for (File iFile : files) { |
83 | - if (checkFile(iFile)) { | |
87 | + if ((year = checkFile(iFile)) > 0) { | |
84 | 88 | logger.info("ファイル '"+ iFile.getName() +"' を読み込みます。"); |
85 | 89 | fcounter++; |
86 | - inputFile(con, iFile); | |
90 | + inputFile(con, iFile, year); | |
87 | 91 | } |
88 | 92 | } |
89 | 93 | } |
@@ -134,7 +138,7 @@ public class ConvAddr { | ||
134 | 138 | * @param iFile source file |
135 | 139 | * @throws Exception |
136 | 140 | */ |
137 | - public static void inputFile (Connection con, File iFile) throws Exception { | |
141 | + public static void inputFile (Connection con, File iFile, int year) throws Exception { | |
138 | 142 | int iCounter = 0; |
139 | 143 | |
140 | 144 | iCounter = 0; |
@@ -148,7 +152,7 @@ public class ConvAddr { | ||
148 | 152 | } |
149 | 153 | |
150 | 154 | // CSVレコードを'table.ISJ_CHO'に書き込む |
151 | - iCounter += DbAddr.insert(con, csvRec); | |
155 | + iCounter += DbAddr.insert(con, csvRec, year); | |
152 | 156 | } |
153 | 157 | |
154 | 158 | logger.info("地名数["+ iCounter +"]"); |
@@ -216,7 +220,7 @@ public class ConvAddr { | ||
216 | 220 | double maxLon = 0.0; |
217 | 221 | double minLon = 180.0; |
218 | 222 | |
219 | - PreparedStatement ps7 = con.prepareStatement("SELECT prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode FROM ISJ_CHO ORDER BY municipalitycode"); | |
223 | + PreparedStatement ps7 = con.prepareStatement("SELECT prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode,year FROM ISJ_CHO ORDER BY municipalitycode"); | |
220 | 224 | ResultSet rset7 = ps7.executeQuery(); |
221 | 225 | while (rset7.next()) { |
222 | 226 | String prefecturecode = rset7.getString(1); |
@@ -228,6 +232,7 @@ public class ConvAddr { | ||
228 | 232 | double lat = rset7.getDouble(7); |
229 | 233 | double lon = rset7.getDouble(8); |
230 | 234 | int typecode = rset7.getInt(9); |
235 | + int year = rset7.getInt("year"); | |
231 | 236 | |
232 | 237 | //-------------------------------------------- |
233 | 238 | // Wiki見出し2: 都道府県コード |
@@ -309,9 +314,9 @@ public class ConvAddr { | ||
309 | 314 | |
310 | 315 | // OSM file header |
311 | 316 | ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8")); |
312 | - ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); | |
317 | + ow.write("<?xml version='1.0' encoding='UTF-8' ?>"); | |
313 | 318 | ow.newLine(); |
314 | - ow.write("<osm version=\"0.5\" generator=\"ReadKIBAN\">"); | |
319 | + ow.write("<osm version='0.6' upload='true' generator='ConvAddr'>"); | |
315 | 320 | ow.newLine(); |
316 | 321 | |
317 | 322 | // GPX file header |
@@ -348,7 +353,7 @@ public class ConvAddr { | ||
348 | 353 | |
349 | 354 | // OSM node |
350 | 355 | int nodeid = dataCount * -1; |
351 | - String osm_node = nodeISJ(nodeid, namecode, name, lat, lon, timeStampStr, typecode); | |
356 | + String osm_node = nodeISJ(nodeid, namecode, name, lat, lon, typecode, year); | |
352 | 357 | ow.write(osm_node); |
353 | 358 | ow.newLine(); |
354 | 359 |
@@ -419,28 +424,26 @@ public class ConvAddr { | ||
419 | 424 | * 4 = 不明 = locality |
420 | 425 | * @return |
421 | 426 | */ |
422 | - public static String nodeISJ(int code, String ref, String name, Double lat, Double lon, String timeStampStr, int typecode) { | |
423 | - String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n"); | |
424 | - osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n"; | |
425 | - osm_node += "<tag k=\"ref\" v=\""+ ref +"\"/>\n"; | |
427 | + public static String nodeISJ(int code, String ref, String name, Double lat, Double lon, int typecode, int year) { | |
428 | + String osm_node = ("<node id='"+ code +"' action='modify' visible='true' lat='"+ lat +"' lon='"+ lon +"'>\n"); | |
429 | + osm_node += "<tag k='name' v='"+ name +"'/>\n"; | |
430 | + osm_node += "<tag k='ref' v='"+ ref +"'/>\n"; | |
426 | 431 | switch (typecode) { |
427 | 432 | case 1: |
428 | - osm_node += "<tag k=\"place\" v=\"quarter\"/>\n"; | |
433 | + osm_node += "<tag k='place' v='quarter'/>\n"; | |
429 | 434 | break; |
430 | 435 | case 2: |
431 | - osm_node += "<tag k=\"place\" v=\"neighbourhood\"/>\n"; | |
436 | + osm_node += "<tag k='place' v='neighbourhood'/>\n"; | |
432 | 437 | break; |
433 | 438 | case 3: |
434 | - osm_node += "<tag k=\"place\" v=\"neighbourhood\"/>\n"; | |
439 | + osm_node += "<tag k='place7 v='neighbourhood'/>\n"; | |
435 | 440 | break; |
436 | 441 | case 4: |
437 | - osm_node += "<tag k=\"place\" v=\"locality\"/>\n"; | |
442 | + osm_node += "<tag k='place' v='locality'/>\n"; | |
438 | 443 | } |
439 | - osm_node += "<tag k=\"fixme\" v=\"既存のノードが存在しないかチェックしてください\"/>\n"; | |
440 | - osm_node += "<tag k=\"source\" v=\"ISJ 2012\"/>\n"; | |
441 | - //osm_node += "<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/isj/\"/>\n"; | |
442 | - //osm_node += "<tag k=\"note\" v=\"National-Land Numerical Information (place) 2012, MLIT Japan\"/>\n"; | |
443 | - //osm_node += "<tag k=\"note:ja\" v=\"国土数値情報(大字・町丁目レベル位置参照情報)2012年 国土交通省\"/>\n"; | |
444 | + osm_node += "<tag k='fixme' v='既存のノードが存在しないかチェックしてください'/>\n"; | |
445 | + osm_node += "<tag k='source' v='街区レベル位置参照情報 国土交通省'/>\n"; | |
446 | + osm_node += "<tag k='source:date' v='"+ year +"'/>\n"; | |
444 | 447 | osm_node += "</node>\n"; |
445 | 448 | return osm_node; |
446 | 449 | } |
@@ -462,39 +465,37 @@ public class ConvAddr { | ||
462 | 465 | * @param f |
463 | 466 | * @return |
464 | 467 | */ |
465 | - static boolean checkFile(File f) { | |
468 | + static int checkFile(File f) { | |
466 | 469 | String name = f.getName(); |
467 | 470 | if (!name.toUpperCase().endsWith(".CSV")) { |
468 | - return false; | |
471 | + return 0; | |
469 | 472 | } |
470 | 473 | |
471 | 474 | if (name.length() == 11) { |
472 | 475 | String str = name.substring(2,3); |
473 | 476 | if (!str.equals("_")) { |
474 | - return false; | |
477 | + return 0; | |
475 | 478 | } |
476 | 479 | |
477 | 480 | str = name.substring(0,2); |
478 | 481 | try { |
479 | - Integer.parseInt(str); | |
482 | + Integer.parseInt(str); // 都道府県コード | |
480 | 483 | } |
481 | 484 | catch (NumberFormatException e) { |
482 | - return false; | |
485 | + return 0; | |
483 | 486 | } |
484 | 487 | |
485 | - str = name.substring(3,6); | |
488 | + str = name.substring(3,7); | |
486 | 489 | try { |
487 | - Integer.parseInt(str); | |
490 | + return Integer.parseInt(str); | |
488 | 491 | } |
489 | - catch (NumberFormatException e) { | |
490 | - return false; | |
491 | - } | |
492 | - return true; | |
492 | + catch (NumberFormatException e) {} | |
493 | + return 0; | |
493 | 494 | } |
494 | 495 | if (name.length() == 14) { |
495 | 496 | String str = name.substring(5,6); |
496 | 497 | if (!str.equals("_")) { |
497 | - return false; | |
498 | + return 0; | |
498 | 499 | } |
499 | 500 | |
500 | 501 | str = name.substring(0,5); |
@@ -502,18 +503,17 @@ public class ConvAddr { | ||
502 | 503 | Integer.parseInt(str); |
503 | 504 | } |
504 | 505 | catch (NumberFormatException e) { |
505 | - return false; | |
506 | + return 0; | |
506 | 507 | } |
507 | 508 | |
508 | 509 | str = name.substring(6,10); |
509 | 510 | try { |
510 | - Integer.parseInt(str); | |
511 | + return Integer.parseInt(str); | |
511 | 512 | } |
512 | 513 | catch (NumberFormatException e) { |
513 | - return false; | |
514 | 514 | } |
515 | - return true; | |
515 | + return 0; | |
516 | 516 | } |
517 | - return false; | |
517 | + return 0; | |
518 | 518 | } |
519 | 519 | } |
\ No newline at end of file |
@@ -30,7 +30,7 @@ public class DbAddr { | ||
30 | 30 | try { |
31 | 31 | con = DatabaseTool.openDb("database"); |
32 | 32 | |
33 | - PreparedStatement ps7 = con.prepareStatement("SELECT prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode FROM ISJ_CHO ORDER BY municipalitycode"); | |
33 | + PreparedStatement ps7 = con.prepareStatement("SELECT prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode,year FROM ISJ_CHO ORDER BY municipalitycode"); | |
34 | 34 | ResultSet rset7 = ps7.executeQuery(); |
35 | 35 | while (rset7.next()) { |
36 | 36 | CsvRecord rec = getRecord(rset7); |
@@ -62,6 +62,7 @@ public class DbAddr { | ||
62 | 62 | * 2 = 字 = neighbourhood |
63 | 63 | * 3 = 丁目 = neighbourhood |
64 | 64 | * 4 = 不明 = locality |
65 | + * 11: "位置参照情報の整備年", year INT | |
65 | 66 | * |
66 | 67 | * 既にテーブルが存在する時には何もしない |
67 | 68 | * @param con |
@@ -71,7 +72,7 @@ public class DbAddr { | ||
71 | 72 | String createSt = "create table ISJ_CHO (prefecturecode VARCHAR(10) NOT NULL, prefecture VARCHAR(32), " + |
72 | 73 | "municipalitycode VARCHAR(20), municipality VARCHAR(128), " + |
73 | 74 | "namecode VARCHAR(20), name VARCHAR(128), " + |
74 | - "lat DOUBLE, lon DOUBLE, typecode INT, " + | |
75 | + "lat DOUBLE, lon DOUBLE, typecode INT, year INT, " + | |
75 | 76 | "CONSTRAINT ISJ_CHO_pk PRIMARY KEY(prefecturecode,municipalitycode,namecode));"; |
76 | 77 | ConvAddr.logger.info(createSt); |
77 | 78 | PreparedStatement ps = con.prepareStatement(createSt); |
@@ -119,9 +120,9 @@ public class DbAddr { | ||
119 | 120 | * |
120 | 121 | * @param con |
121 | 122 | */ |
122 | - public static int insert(Connection con, CsvRecord csvRec) { | |
123 | - String sql = ("INSERT INTO ISJ_CHO (prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode)" + | |
124 | - " VALUES (?,?,?,?,?,?,?,?,?)"); | |
123 | + public static int insert(Connection con, CsvRecord csvRec, int year) { | |
124 | + String sql = ("INSERT INTO ISJ_CHO (prefecturecode,prefecture,municipalitycode,municipality,namecode,name,lat,lon,typecode,year)" + | |
125 | + " VALUES (?,?,?,?,?,?,?,?,?,?)"); | |
125 | 126 | try { |
126 | 127 | PreparedStatement pstmt = con.prepareStatement(sql); |
127 | 128 | pstmt.setString(1, csvRec.get(0)); // 1: "都道府県コード", prefecturecode |
@@ -133,6 +134,7 @@ public class DbAddr { | ||
133 | 134 | pstmt.setDouble(7, Double.parseDouble(csvRec.get(6))); // 7: "緯度", lat DOUBLE |
134 | 135 | pstmt.setDouble(8, Double.parseDouble(csvRec.get(7))); // 8: "経度", lon DOUBLE |
135 | 136 | pstmt.setInt(9, Integer.parseInt(csvRec.get(9))); // 10: "大字・字・丁目区分コード" typecode INT |
137 | + pstmt.setInt(10, year); // 11: "位置参照情報の整備年" year INT | |
136 | 138 | pstmt.executeUpdate(); |
137 | 139 | pstmt.close(); |
138 | 140 | return 1; |
@@ -159,6 +161,7 @@ public class DbAddr { | ||
159 | 161 | rec.add(rset.getString(7)); // lat |
160 | 162 | rec.add(rset.getString(8)); // lon |
161 | 163 | rec.add(rset.getString(9)); // typecode |
164 | + rec.add(rset.getString(10)); // year | |
162 | 165 | return rec; |
163 | 166 | } |
164 | 167 | } |
\ No newline at end of file |