• R/O
  • HTTP
  • SSH
  • HTTPS

ConvAddr: Commit

OSM用の地名ノードに変換する


Commit MetaInfo

Revision22ad421b7a1567889e1ab6806c64db9a14d75011 (tree)
Time2016-04-30 00:09:29
Authoryuuhayashi <hayashi.yuu@gmai...>
Commiteryuuhayashi

Log Message

最新のJOSMに対応するために、OSMファイルのversionを0.5 から 0.6 にアップした。

Change Summary

Incremental Difference

--- a/build.xml
+++ b/build.xml
@@ -27,7 +27,7 @@
2727 [STEP 2] コンパイル
2828 -->
2929 <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" >
3131 <include name="**" />
3232 <exclude name="**/*.smap" />
3333
--- a/src/osm/jp/ConvAddr.java
+++ b/src/osm/jp/ConvAddr.java
@@ -71,19 +71,23 @@ public class ConvAddr {
7171 try {
7272 // CSVファイルを読み取ってDB.table.ISJ_CHO に格納する
7373 int fcounter = 0;
74+ int year = 0;
7475 if (args.length > index) {
7576 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+ }
7882 }
7983 else {
8084 File dir = new File(".");
8185 File[] files = dir.listFiles();
8286 for (File iFile : files) {
83- if (checkFile(iFile)) {
87+ if ((year = checkFile(iFile)) > 0) {
8488 logger.info("ファイル '"+ iFile.getName() +"' を読み込みます。");
8589 fcounter++;
86- inputFile(con, iFile);
90+ inputFile(con, iFile, year);
8791 }
8892 }
8993 }
@@ -134,7 +138,7 @@ public class ConvAddr {
134138 * @param iFile source file
135139 * @throws Exception
136140 */
137- public static void inputFile (Connection con, File iFile) throws Exception {
141+ public static void inputFile (Connection con, File iFile, int year) throws Exception {
138142 int iCounter = 0;
139143
140144 iCounter = 0;
@@ -148,7 +152,7 @@ public class ConvAddr {
148152 }
149153
150154 // CSVレコードを'table.ISJ_CHO'に書き込む
151- iCounter += DbAddr.insert(con, csvRec);
155+ iCounter += DbAddr.insert(con, csvRec, year);
152156 }
153157
154158 logger.info("地名数["+ iCounter +"]");
@@ -216,7 +220,7 @@ public class ConvAddr {
216220 double maxLon = 0.0;
217221 double minLon = 180.0;
218222
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");
220224 ResultSet rset7 = ps7.executeQuery();
221225 while (rset7.next()) {
222226 String prefecturecode = rset7.getString(1);
@@ -228,6 +232,7 @@ public class ConvAddr {
228232 double lat = rset7.getDouble(7);
229233 double lon = rset7.getDouble(8);
230234 int typecode = rset7.getInt(9);
235+ int year = rset7.getInt("year");
231236
232237 //--------------------------------------------
233238 // Wiki見出し2: 都道府県コード
@@ -309,9 +314,9 @@ public class ConvAddr {
309314
310315 // OSM file header
311316 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' ?>");
313318 ow.newLine();
314- ow.write("<osm version=\"0.5\" generator=\"ReadKIBAN\">");
319+ ow.write("<osm version='0.6' upload='true' generator='ConvAddr'>");
315320 ow.newLine();
316321
317322 // GPX file header
@@ -348,7 +353,7 @@ public class ConvAddr {
348353
349354 // OSM node
350355 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);
352357 ow.write(osm_node);
353358 ow.newLine();
354359
@@ -419,28 +424,26 @@ public class ConvAddr {
419424 * 4 = 不明 = locality
420425 * @return
421426 */
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";
426431 switch (typecode) {
427432 case 1:
428- osm_node += "<tag k=\"place\" v=\"quarter\"/>\n";
433+ osm_node += "<tag k='place' v='quarter'/>\n";
429434 break;
430435 case 2:
431- osm_node += "<tag k=\"place\" v=\"neighbourhood\"/>\n";
436+ osm_node += "<tag k='place' v='neighbourhood'/>\n";
432437 break;
433438 case 3:
434- osm_node += "<tag k=\"place\" v=\"neighbourhood\"/>\n";
439+ osm_node += "<tag k='place7 v='neighbourhood'/>\n";
435440 break;
436441 case 4:
437- osm_node += "<tag k=\"place\" v=\"locality\"/>\n";
442+ osm_node += "<tag k='place' v='locality'/>\n";
438443 }
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";
444447 osm_node += "</node>\n";
445448 return osm_node;
446449 }
@@ -462,39 +465,37 @@ public class ConvAddr {
462465 * @param f
463466 * @return
464467 */
465- static boolean checkFile(File f) {
468+ static int checkFile(File f) {
466469 String name = f.getName();
467470 if (!name.toUpperCase().endsWith(".CSV")) {
468- return false;
471+ return 0;
469472 }
470473
471474 if (name.length() == 11) {
472475 String str = name.substring(2,3);
473476 if (!str.equals("_")) {
474- return false;
477+ return 0;
475478 }
476479
477480 str = name.substring(0,2);
478481 try {
479- Integer.parseInt(str);
482+ Integer.parseInt(str); // 都道府県コード
480483 }
481484 catch (NumberFormatException e) {
482- return false;
485+ return 0;
483486 }
484487
485- str = name.substring(3,6);
488+ str = name.substring(3,7);
486489 try {
487- Integer.parseInt(str);
490+ return Integer.parseInt(str);
488491 }
489- catch (NumberFormatException e) {
490- return false;
491- }
492- return true;
492+ catch (NumberFormatException e) {}
493+ return 0;
493494 }
494495 if (name.length() == 14) {
495496 String str = name.substring(5,6);
496497 if (!str.equals("_")) {
497- return false;
498+ return 0;
498499 }
499500
500501 str = name.substring(0,5);
@@ -502,18 +503,17 @@ public class ConvAddr {
502503 Integer.parseInt(str);
503504 }
504505 catch (NumberFormatException e) {
505- return false;
506+ return 0;
506507 }
507508
508509 str = name.substring(6,10);
509510 try {
510- Integer.parseInt(str);
511+ return Integer.parseInt(str);
511512 }
512513 catch (NumberFormatException e) {
513- return false;
514514 }
515- return true;
515+ return 0;
516516 }
517- return false;
517+ return 0;
518518 }
519519 }
\ No newline at end of file
--- a/src/osm/jp/DbAddr.java
+++ b/src/osm/jp/DbAddr.java
@@ -30,7 +30,7 @@ public class DbAddr {
3030 try {
3131 con = DatabaseTool.openDb("database");
3232
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");
3434 ResultSet rset7 = ps7.executeQuery();
3535 while (rset7.next()) {
3636 CsvRecord rec = getRecord(rset7);
@@ -62,6 +62,7 @@ public class DbAddr {
6262 * 2 = 字 = neighbourhood
6363 * 3 = 丁目 = neighbourhood
6464 * 4 = 不明 = locality
65+ * 11: "位置参照情報の整備年", year INT
6566 *
6667 * 既にテーブルが存在する時には何もしない
6768 * @param con
@@ -71,7 +72,7 @@ public class DbAddr {
7172 String createSt = "create table ISJ_CHO (prefecturecode VARCHAR(10) NOT NULL, prefecture VARCHAR(32), " +
7273 "municipalitycode VARCHAR(20), municipality VARCHAR(128), " +
7374 "namecode VARCHAR(20), name VARCHAR(128), " +
74- "lat DOUBLE, lon DOUBLE, typecode INT, " +
75+ "lat DOUBLE, lon DOUBLE, typecode INT, year INT, " +
7576 "CONSTRAINT ISJ_CHO_pk PRIMARY KEY(prefecturecode,municipalitycode,namecode));";
7677 ConvAddr.logger.info(createSt);
7778 PreparedStatement ps = con.prepareStatement(createSt);
@@ -119,9 +120,9 @@ public class DbAddr {
119120 *
120121 * @param con
121122 */
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 (?,?,?,?,?,?,?,?,?,?)");
125126 try {
126127 PreparedStatement pstmt = con.prepareStatement(sql);
127128 pstmt.setString(1, csvRec.get(0)); // 1: "都道府県コード", prefecturecode
@@ -133,6 +134,7 @@ public class DbAddr {
133134 pstmt.setDouble(7, Double.parseDouble(csvRec.get(6))); // 7: "緯度", lat DOUBLE
134135 pstmt.setDouble(8, Double.parseDouble(csvRec.get(7))); // 8: "経度", lon DOUBLE
135136 pstmt.setInt(9, Integer.parseInt(csvRec.get(9))); // 10: "大字・字・丁目区分コード" typecode INT
137+ pstmt.setInt(10, year); // 11: "位置参照情報の整備年" year INT
136138 pstmt.executeUpdate();
137139 pstmt.close();
138140 return 1;
@@ -159,6 +161,7 @@ public class DbAddr {
159161 rec.add(rset.getString(7)); // lat
160162 rec.add(rset.getString(8)); // lon
161163 rec.add(rset.getString(9)); // typecode
164+ rec.add(rset.getString(10)); // year
162165 return rec;
163166 }
164167 }
\ No newline at end of file
Show on old repository browser