2 import osm.jp.api.HttpPOST;
\r
4 import javax.xml.parsers.*;
\r
5 import javax.xml.transform.TransformerException;
\r
7 import org.w3c.dom.*;
\r
8 import org.xml.sax.*;
\r
11 import java.sql.Connection;
\r
12 import java.sql.PreparedStatement;
\r
13 import java.sql.ResultSet;
\r
14 import java.sql.SQLException;
\r
15 import java.sql.Statement;
\r
16 import java.text.SimpleDateFormat;
\r
17 import java.util.ArrayList;
\r
18 import java.util.Calendar;
\r
19 import java.util.Date;
\r
21 import jp.co.areaweb.tools.database.*;
\r
23 public class ConvBusstop {
\r
28 public static final boolean DB_INIT = false;
\r
30 // 近くのバス停を探す範囲(バス停を中心としたNEER×2m四方の領域
\r
31 static final int NEER = 150;
\r
32 static boolean nocheck = false;
\r
37 * java -cp .:ConvBusstop.jar:hayashi_0225.jar:hsqldb_2.2.9.jar osm.jp.ConvBusstop <option>
\r
38 * OPTION: -nocheck OSMデータ上に既存のバス停が存在するかどうかをチェックしない
\r
39 * OPTION: -check OSMデータ上に既存のバス停が存在するかどうかをチェックする
\r
41 * @throws IOException
\r
42 * @throws SQLException
\r
43 * @throws ClassNotFoundException
\r
44 * @throws FileNotFoundException
\r
45 * @throws TransformerException
\r
46 * @throws SAXException
\r
47 * @throws ParserConfigurationException */
\r
48 public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException, TransformerException
\r
51 if (args.length > index) {
\r
52 if (args[index].equals("-check")) {
\r
53 ConvBusstop.nocheck = false;
\r
56 else if (args[index].equals("-nocheck")) {
\r
57 ConvBusstop.nocheck = true;
\r
63 * アプリケーション [ConvBusstop]
\r
64 * > java -jar ConvBusstop.jar <オプション>
\r
65 * オプション: -exp 実行する直前にデータベースを初期化する(省略可能)
\r
67 File dbdir = new File("database");
\r
68 if (!dbdir.isDirectory()) {
\r
72 Connection con = DatabaseTool.openDb("database");
\r
73 ConvBusstop.initDb(con);
\r
80 if (args.length > index) {
\r
81 File iFile = new File(args[index]);
\r
83 inputFile(con, iFile);
\r
86 File dir = new File(".");
\r
87 File[] files = dir.listFiles();
\r
88 for (File iFile : files) {
\r
89 if (checkFile(iFile)) {
\r
91 ConvBusstop.clearDb(con);
\r
92 inputFile(con, iFile);
\r
96 System.out.println("["+ fcounter +"]つのファイルをインポートしました。");
\r
100 * --> 'existing.xml'
\r
102 if (!ConvBusstop.nocheck && (fcounter > 0)) {
\r
104 * 既存のOSMデータファイルがなければ、新たにダウンロードする。
\r
105 * OSMデータファイルがあるときは、ダウンロードしないでそれを使う。
\r
107 File existingFile = new File("existing.xml");
\r
108 if (!existingFile.isFile()) {
\r
110 * インポートしたデータの緯度経度範囲を読み取る
\r
112 double maxLat = -90.0D;
\r
113 double minLat = 90.0D;
\r
114 double maxLon = -180.0D;
\r
115 double minLon = 180.0D;
\r
116 PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop");
\r
117 ResultSet rset8 = ps8.executeQuery();
\r
118 while (rset8.next()) {
\r
119 Double lat = rset8.getDouble("lat");
\r
120 Double lon = rset8.getDouble("lon");
\r
122 if (lat > maxLat) {
\r
125 if (lon > maxLon) {
\r
128 if (lat < minLat) {
\r
131 if (lon < minLon) {
\r
138 * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する
\r
140 HttpPOST.getCapabilities(minLat, maxLat, minLon, maxLon);
\r
142 readExistingFile(con, existingFile);
\r
144 PreparedStatement ps1 = con.prepareStatement("SELECT idref,name,lat,lon FROM bus_stop");
\r
145 PreparedStatement ps2 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)");
\r
146 PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?");
\r
147 PreparedStatement ps4 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?) and (name = ?)");
\r
148 ResultSet rset1 = ps1.executeQuery();
\r
149 while (rset1.next()) {
\r
150 String idref = rset1.getString("idref");
\r
151 String name = rset1.getString("name");
\r
152 Double lat = rset1.getDouble("lat");
\r
153 Double lon = rset1.getDouble("lon");
\r
155 // 指定の緯度経度を中心とする半径150x2m四方の矩形領域
\r
156 System.out.print(idref + "("+ name + ") ....");
\r
157 RectArea rect = new RectArea(lat, lon, NEER); // 300m 四方
\r
158 ps2.setDouble(1, rect.minlat);
\r
159 ps2.setDouble(2, rect.maxlat);
\r
160 ps2.setDouble(3, rect.minlon);
\r
161 ps2.setDouble(4, rect.maxlon);
\r
162 ResultSet rset2 = ps2.executeQuery();
\r
163 if (rset2.next()) {
\r
164 int count = rset2.getInt(1);
\r
166 System.out.println("."+ count);
\r
167 ps3.setInt(1, count);
\r
168 ps3.setString(2, idref);
\r
169 ps3.executeUpdate();
\r
172 // 指定の緯度経度を中心とする半径150x4m四方の矩形領域
\r
173 System.out.print("***");
\r
174 rect = new RectArea(lat, lon, NEER*2); // 600m 四方
\r
175 ps4.setDouble(1, rect.minlat);
\r
176 ps4.setDouble(2, rect.maxlat);
\r
177 ps4.setDouble(3, rect.minlon);
\r
178 ps4.setDouble(4, rect.maxlon);
\r
179 ps4.setString(5, name);
\r
180 ResultSet rset4 = ps4.executeQuery();
\r
181 if (rset4.next()) {
\r
182 count = rset4.getInt(1);
\r
183 System.out.println(".."+ count);
\r
184 ps3.setInt(1, count);
\r
185 ps3.setString(2, idref);
\r
186 ps3.executeUpdate();
\r
199 // ローカルデータベース内の情報を出力する
\r
200 if (args.length > index) {
\r
201 File iFile = new File(args[index]);
\r
202 String iStr = iFile.getName();
\r
203 outputDb(con, iStr.substring(0, iStr.length() - 4));
\r
206 File dir = new File(".");
\r
207 File[] files = dir.listFiles();
\r
208 for (File iFile : files) {
\r
209 if (checkFile(iFile)) {
\r
210 String iStr = iFile.getName();
\r
211 outputDb(con, iStr.substring(0, iStr.length() - 4));
\r
216 // ローカルデータベース内の情報を「busstop.xml」に出力する
\r
217 int counter = outputDb(con);
\r
219 System.out.println("["+ counter +"] 変換完了しました。");
\r
222 DatabaseTool.closeDb(con);
\r
226 static String[] shiftArgs(String[] args) {
\r
227 String[] values = new String[args.length - 1];
\r
228 for (int i=1; i < args.length; i++) {
\r
229 values[i - 1] = new String(args[i]);
\r
234 public static void readExistingFile (Connection con, File existingFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
\r
237 DocumentBuilderFactory factory;
\r
238 DocumentBuilder builder;
\r
242 factory = DocumentBuilderFactory.newInstance();
\r
243 builder = factory.newDocumentBuilder();
\r
244 factory.setIgnoringElementContentWhitespace(true);
\r
245 factory.setIgnoringComments(true);
\r
246 factory.setValidating(true);
\r
247 root = builder.parse(existingFile);
\r
249 iCounter += readExistingNodes(con, root);
\r
250 System.out.println("既存バス停数["+ iCounter +"]");
\r
253 static int readExistingNodes(Connection con, Node node) throws IOException, SQLException {
\r
256 NodeList nodes = node.getChildNodes();
\r
257 for (int i = 0; i < nodes.getLength(); i++) {
\r
258 Node node2 = nodes.item(i);
\r
259 if (node2.getNodeName().equals("node")) {
\r
261 importExistingNode(con, node2);
\r
264 iCounter += readExistingNodes(con, node2);
\r
270 static void importExistingNode(Connection con, Node node) throws IOException, SQLException {
\r
271 String idrefStr = "";
\r
272 String latStr = "";
\r
273 String lonStr = "";
\r
274 String nameStr = "";
\r
275 PreparedStatement ps5 = con.prepareStatement("INSERT INTO existing_data (idref,lat,lon, name) VALUES (?,?,?,?)");
\r
277 NamedNodeMap nodeMap = node.getAttributes();
\r
278 if (null != nodeMap) {
\r
279 for (int j=0; j < nodeMap.getLength(); j++) {
\r
280 if (nodeMap.item(j).getNodeName().equals("id")) {
\r
281 idrefStr = nodeMap.item(j).getNodeValue();
\r
283 else if (nodeMap.item(j).getNodeName().equals("lat")) {
\r
284 latStr = nodeMap.item(j).getNodeValue();
\r
286 else if (nodeMap.item(j).getNodeName().equals("lon")) {
\r
287 lonStr = nodeMap.item(j).getNodeValue();
\r
291 NodeList nodes = node.getChildNodes();
\r
292 for (int i = 0; i < nodes.getLength(); i++) {
\r
293 Node node2 = nodes.item(i);
\r
294 if (node2.getNodeName().equals("tag")) {
\r
295 NamedNodeMap nodeMap2 = node2.getAttributes();
\r
296 if (null != nodeMap2) {
\r
298 String value = null;
\r
299 for (int j=0; j < nodeMap2.getLength(); j++) {
\r
300 if (nodeMap2.item(j).getNodeName().equals("k")) {
\r
301 key = nodeMap2.item(j).getNodeValue();
\r
303 else if (nodeMap2.item(j).getNodeName().equals("v")) {
\r
304 value = nodeMap2.item(j).getNodeValue();
\r
308 if ((key != null) && key.toLowerCase().equals("name") && (value != null)) {
\r
316 // idref と nameStr をデータベースに格納する
\r
317 System.out.println("import existing_data : "+ idrefStr +" ("+ latStr +","+ lonStr+")"+ nameStr);
\r
318 ps5.setString(1, idrefStr);
\r
319 ps5.setDouble(2, Double.parseDouble(latStr));
\r
320 ps5.setDouble(3, Double.parseDouble(lonStr));
\r
321 ps5.setString(4, nameStr);
\r
322 ps5.executeUpdate();
\r
328 * ソースファイルを読み取ってローカルベータベースへ記録する
\r
331 * @throws FileNotFoundException
\r
332 * @throws ClassNotFoundException
\r
333 * @throws SQLException
\r
334 * @throws IOException
\r
335 * @throws ParserConfigurationException
\r
336 * @throws SAXException
\r
338 public static void inputFile (Connection con, File iFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
\r
340 String timeStampStr = null;
\r
342 String iStr = iFile.getName();
\r
343 File dir = new File(iStr.substring(0, iStr.length() - 4));
\r
346 DocumentBuilderFactory factory;
\r
347 DocumentBuilder builder;
\r
351 factory = DocumentBuilderFactory.newInstance();
\r
352 builder = factory.newDocumentBuilder();
\r
353 factory.setIgnoringElementContentWhitespace(true);
\r
354 factory.setIgnoringComments(true);
\r
355 factory.setValidating(true);
\r
356 root = builder.parse(iStr);
\r
358 iCounter += showNodes(con, root, iStr.substring(0, iStr.length() - 4), timeStampStr);
\r
359 System.out.println("バス停数["+ iCounter +"]");
\r
362 public static void clearDb(Connection con) throws SQLException {
\r
363 Statement stmt = con.createStatement();
\r
364 long count = stmt.executeUpdate("delete from bus_stop");
\r
365 System.out.println("'Database.bus_stop'から "+ count +" 件のデータを削除しました。");
\r
367 count = stmt.executeUpdate("delete from existing_data");
\r
368 System.out.println("'Database.existing_data'から "+ count +" 件のデータを削除しました。");
\r
370 count = stmt.executeUpdate("delete from bus_course");
\r
371 System.out.println("'Database.bus_course'から "+ count +" 件のデータを削除しました。");
\r
373 count = stmt.executeUpdate("delete from bus_ref");
\r
374 System.out.println("'Database.bus_ref'から "+ count +" 件のデータを削除しました。");
\r
378 public static void initDb(Connection con) throws SQLException {
\r
381 // 'table.BUS_STOP'を新規に作る
\r
382 DbBusstop.create(con);
\r
384 createSt = "CREATE TABLE existing_data (idref VARCHAR(12) NOT NULL, name VARCHAR(128), lat DOUBLE, lon DOUBLE, CONSTRAINT existing_pk PRIMARY KEY(idref, lat, lon));";
\r
385 DbBusstop.create(con, createSt);
\r
387 createSt = "CREATE TABLE bus_course (code int, type int, corp VARCHAR(128) NOT NULL, course VARCHAR(512), ifile VARCHAR(128), CONSTRAINT bus_course_pk PRIMARY KEY(code));";
\r
388 DbBusstop.create(con, createSt);
\r
390 createSt = "CREATE TABLE bus_ref (idref VARCHAR(12), code INT);";
\r
391 DbBusstop.create(con, createSt);
\r
396 * ローカルデータベース内の情報を出力する
\r
399 * @throws IOException
\r
400 * @throws SQLException
\r
402 public static void outputDb(Connection con, String iCode) throws IOException, SQLException {
\r
403 SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
\r
404 String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
\r
405 File dir = new File(iCode);
\r
408 BufferedWriter ow = null;
\r
409 BufferedWriter gw = null;
\r
410 BufferedWriter hw = null;
\r
411 BufferedWriter ww = null;
\r
414 File htmlFile = new File(iCode +".html");
\r
415 hw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
\r
416 hw.write("<!DOCTYPE html>");
\r
418 hw.write("<html><head><meta charset=\"utf-8\" /></head>");
\r
420 hw.write("<body><table border='1'>");
\r
423 hw.write("<td>type</td>");
\r
424 hw.write("<td>corp</td>");
\r
425 hw.write("<td>course</td>");
\r
426 hw.write("<td>GPX</td>");
\r
427 hw.write("<td>SAMPLE</td>");
\r
428 hw.write("<td>バス停数</td>");
\r
429 hw.write("<td>未入力</td>");
\r
430 hw.write("<td>既存</td>");
\r
435 File wikiFile = new File(iCode +".wiki.txt");
\r
436 ww = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wikiFile), "UTF-8"));
\r
437 ww.write("= バス路線毎のマッピング状況 =");
\r
441 String maeCorp = "";
\r
442 boolean firstCorp = true;
\r
444 PreparedStatement ps7 = con.prepareStatement("SELECT code,type,corp,course,ifile FROM bus_course WHERE ifile=? ORDER BY type,corp,course");
\r
445 PreparedStatement ps9 = con.prepareStatement("SELECT idref FROM bus_ref WHERE code=?");
\r
446 PreparedStatement ps8 = con.prepareStatement("SELECT name,lat,lon,fixed FROM bus_stop WHERE idref=?");
\r
447 ps7.setString(1, iCode);
\r
448 ResultSet rset7 = ps7.executeQuery();
\r
449 while (rset7.next()) {
\r
450 int code = rset7.getInt(1);
\r
451 int type = rset7.getInt(2);
\r
452 String corp = rset7.getString(3);
\r
453 String course = rset7.getString(4);
\r
456 File osmFile = new File(dir, iCode + String.format("_%1$08d", code) +".osm");
\r
457 File gpxFile = new File(dir, iCode + String.format("_%1$08d", code) +".gpx");
\r
458 File osmSample = new File(dir, iCode + String.format("_s%1$08d", code) +".osm");
\r
460 System.out.println("course = "+ course);
\r
462 int fixedCount = 0;
\r
463 int unfixedCount = 0;
\r
465 // index file header
\r
467 hw.write("<td>"+ type +"</td>");
\r
468 hw.write("<td>"+ corp +"</td>");
\r
469 hw.write("<td><a href='"+ dir.getName() +"/"+ osmFile.getName() +"'>"+ course +"</a></td>");
\r
470 hw.write("<td><a href='"+ dir.getName() +"/"+ gpxFile.getName() +"'>"+ gpxFile.getName() +"</a></td>");
\r
471 hw.write("<td><a href='"+ dir.getName() +"/"+ osmSample.getName() +"'>"+ osmSample.getName() +"</a></td>");
\r
474 //--------------------------------------------
\r
477 if (!maeCorp.equals(corp)) {
\r
478 if (firstCorp == false) {
\r
485 ww.write("=== "+ corp +" ===");
\r
489 ww.write(":{{JA:Tag|network||"+ corp +"}}");
\r
491 ww.write(":{{JA:Tag|operator||"+ corp +"}}");
\r
495 ww.write("{| class=\"wikitable sortable\" style=\"table-layout: fixed; width: 100%\"");
\r
497 ww.write("!style=\"width: 100px\"| ref");
\r
499 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(マスタ)");
\r
501 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(往路)");
\r
503 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(復路)");
\r
505 ww.write("!class=\"unsortable\"| 備考");
\r
508 maeCorp = new String(corp);
\r
514 ww.write("| "+ course +" "); // ref
\r
515 ww.write("|| {{State Route|r=0}} {{relation|0|tools=no}} "); // 編集状況 (マスタ)
\r
516 ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} "); // 編集状況 (往路)
\r
517 ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} "); // 編集状況 (復路)
\r
518 ww.write("|| "); // 備考
\r
523 ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));
\r
524 ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
526 ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");
\r
530 gw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gpxFile), "UTF-8"));
\r
531 gw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
533 gw.write("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"osmtracker-android\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd \">");
\r
536 double maxLat = -180.0;
\r
537 double minLat = 180.0;
\r
538 double maxLon = -180.0;
\r
539 double minLon = 180.0;
\r
541 ps9.setInt(1, code);
\r
542 ResultSet rset9 = ps9.executeQuery();
\r
543 while (rset9.next()) {
\r
544 String idref = rset9.getString(1);
\r
546 ps8.setString(1, idref);
\r
547 ResultSet rset8 = ps8.executeQuery();
\r
548 if (rset8.next()) {
\r
550 String name = rset8.getString(1);
\r
551 Double lat = rset8.getDouble(2);
\r
552 Double lon = rset8.getDouble(3);
\r
553 int fixed = rset8.getInt(4);
\r
555 if (lat > maxLat) {
\r
558 if (lon > maxLon) {
\r
561 if (lat < minLat) {
\r
564 if (lon < minLon) {
\r
568 System.out.println("\tway point = "+ idref +", lat="+ lat +", lon="+ lon +", name="+ name);
\r
569 fixedCount += fixed;
\r
574 int nodeid = Integer.parseInt(idref.substring(1)) * -1;
\r
575 String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);
\r
576 ow.write(osm_node);
\r
580 //File txtFile = new File(dir, iCode + idref +".txt");
\r
581 //BufferedWriter gw2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(txtFile), "UTF-8"));
\r
582 //gw2.write(osm_node);
\r
587 gw.write("<wpt lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
\r
588 gw.write(" <time>"+ timeStampStr +"Z</time>\n");
\r
589 gw.write(" <name><![CDATA["+ name +"]]></name>\n");
\r
590 //gw.write(" <link href=\""+ txtFile.getName() +"\"><text>"+ idref +"</text></link>\n");
\r
591 gw.write("</wpt>\n");
\r
600 hw.write("<td>"+ stopCount +"</td>");
\r
601 hw.write("<td>"+ unfixedCount +"</td>");
\r
602 hw.write("<td>"+ fixedCount +"</td>");
\r
607 BufferedWriter ow2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmSample), "UTF-8"));
\r
608 ow2.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
610 ow2.write("<osm version=\"0.5\" generator=\"ConvBusstop\">");
\r
613 ow2.write(nodeBusstop(code, "SAMPLE", ((maxLat+minLat)/2), ((maxLon+minLon)/2), timeStampStr));
\r
615 ow2.write("</osm>");
\r
620 ow.write("</osm>");
\r
625 gw.write("</gpx>");
\r
634 // index file footer
\r
635 hw.write("</table></body></html>");
\r
640 public static int outputDb(Connection con) throws IOException, SQLException {
\r
641 File osmFile = new File("busstop.osm");
\r
644 SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
\r
645 String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
\r
646 BufferedWriter ow = null;
\r
649 ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));
\r
650 ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
652 ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");
\r
655 PreparedStatement ps8 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM bus_stop");
\r
656 ResultSet rset8 = ps8.executeQuery();
\r
657 while (rset8.next()) {
\r
658 String idref = rset8.getString("idref");
\r
659 String name = rset8.getString("name");
\r
660 Double lat = rset8.getDouble("lat");
\r
661 Double lon = rset8.getDouble("lon");
\r
662 int fixed = rset8.getInt("fixed");
\r
664 if (ConvBusstop.nocheck || (fixed < 1)) {
\r
667 int nodeid = Integer.parseInt(idref.substring(1)) * -1;
\r
668 String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);
\r
669 System.out.println(osm_node);
\r
670 ow.write(osm_node);
\r
677 ow.write("</osm>");
\r
683 public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) {
\r
684 String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
\r
685 osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n";
\r
686 osm_node += "<tag k=\"fixme\" v=\"platform/stop_positionを選択して、正しい位置に移動させてください\"/>\n";
\r
687 osm_node += "<tag k=\"source\" v=\"KSJ2\"/>\n";
\r
688 osm_node += "<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11.html\"/>\n";
\r
689 osm_node += "<tag k=\"created_by\" v=\"National-Land-Numerical-Information_MLIT_Japan\"/>\n";
\r
690 osm_node += "<tag k=\"note\" v=\"National-Land Numerical Information (Bus stop) 2012, MLIT Japan\"/>\n";
\r
691 osm_node += "<tag k=\"note:ja\" v=\"国土数値情報(バス停留所)平成24年 国土交通省\"/>\n";
\r
692 osm_node += "<tag k=\"public_transport\" v=\"platform\"/>\n";
\r
693 osm_node += "<tag k=\"public_transport\" v=\"stop_position\"/>\n";
\r
694 osm_node += "<tag k=\"highway\" v=\"bus_stop\"/>\n";
\r
695 osm_node += "<tag k=\"bus\" v=\"yes\"/>\n";
\r
696 osm_node += "</node>\n";
\r
704 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
705 * @param timeStampStr
\r
707 * @throws IOException
\r
708 * @throws SQLException
\r
710 public static int showNodes(Connection con, Node node, String iFileName, String timeStampStr) throws IOException, SQLException {
\r
712 NamedNodeMap nodeMap = node.getAttributes();
\r
713 if ( null != nodeMap ) {
\r
714 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
715 if (nodeMap.item(j).getNodeName().equals("timeStamp")) {
\r
716 timeStampStr = nodeMap.item(j).getNodeValue();
\r
721 NodeList nodes = node.getChildNodes();
\r
722 for (int i=0; i<nodes.getLength(); i++) {
\r
723 Node node2 = nodes.item(i);
\r
724 if (node2.getNodeName().equals("jps:GM_Point")) {
\r
725 showGmPoint(con, node2);
\r
727 else if (node2.getNodeName().equals("gml:Point")) {
\r
728 showGmlPoint(con, node2);
\r
731 else if (node2.getNodeName().equals("ksj:ED01")) {
\r
733 showED01(con, node2, iFileName);
\r
735 else if (node2.getNodeName().equals("ksj:BusStop")) {
\r
737 showBusStop(con, node2, iFileName);
\r
741 iCounter += showNodes(con, node2, iFileName, timeStampStr);
\r
751 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
752 * @throws IOException
\r
753 * @throws SQLException
\r
755 public static void showED01(Connection con, Node node, String iFileName) throws IOException, SQLException {
\r
756 String idrefStr = "";
\r
757 String nameStr = "";
\r
758 PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?");
\r
759 PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)");
\r
760 PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
\r
761 PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
\r
762 PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
\r
763 PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
\r
765 ArrayList<String[]> bris = new ArrayList<String[]>();
\r
766 NodeList nodes = node.getChildNodes();
\r
767 for (int i=0; i < nodes.getLength(); i++) {
\r
768 Node node2 = nodes.item(i);
\r
769 if (node2.getNodeName().equals("ksj:POS")) {
\r
770 NamedNodeMap nodeMap = node2.getAttributes();
\r
771 if (null != nodeMap) {
\r
772 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
773 if (nodeMap.item(j).getNodeName().equals("idref")) {
\r
774 idrefStr = nodeMap.item(j).getNodeValue();
\r
775 System.out.println("found idref='"+ idrefStr +"'");
\r
781 else if (node2.getNodeName().equals("ksj:BSN")) {
\r
782 nameStr = node2.getTextContent();
\r
784 else if (node2.getNodeName().equals("ksj:BRI")) {
\r
785 String[] rtn = anaComm(node2);
\r
792 // idref と nameStr をデータベースに格納する
\r
793 boolean insert = true;
\r
794 ps1.setString(1, idrefStr);
\r
795 ResultSet rset = ps1.executeQuery();
\r
802 ps2.setString(1, idrefStr);
\r
803 ps2.setString(2, nameStr);
\r
804 ps2.setString(3, iFileName);
\r
805 System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')");
\r
806 ps2.executeUpdate();
\r
809 for (String[] rtn : bris) {
\r
811 ps3.setString(1, rtn[1]);
\r
812 ps3.setString(2, rtn[2]);
\r
813 ps3.setString(3, iFileName);
\r
814 rset = ps3.executeQuery();
\r
816 code = rset.getInt(1);
\r
821 ps6.setString(1, iFileName);
\r
822 ResultSet rset6 = ps6.executeQuery();
\r
823 if (rset6.next()) {
\r
824 code = rset6.getInt(1);
\r
829 System.out.println("code="+code);
\r
830 ps4.setInt(1, code);
\r
831 ps4.setInt(2, Integer.parseInt(rtn[0]));
\r
832 ps4.setString(3, rtn[2]);
\r
833 ps4.setString(4, rtn[1]);
\r
834 ps4.setString(5, iFileName);
\r
835 ps4.executeUpdate();
\r
838 ps5.setString(1, idrefStr);
\r
839 ps5.setInt(2, code);
\r
840 ps5.executeUpdate();
\r
851 * <ksj:BusStop gml:id="ED01_1">
\r
852 * <ksj:position xlink:href="#n1"/>
\r
853 * <ksj:busStopName>城堀</ksj:busStopName>
\r
854 * <ksj:busRouteInformation>
\r
855 * <ksj:BusRouteInformation>
\r
856 * <ksj:busType>1</ksj:busType>
\r
857 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
858 * <ksj:busLineName>小01</ksj:busLineName>
\r
859 * </ksj:BusRouteInformation>
\r
860 * </ksj:busRouteInformation>
\r
861 * <ksj:busRouteInformation>
\r
862 * <ksj:BusRouteInformation>
\r
863 * <ksj:busType>1</ksj:busType>
\r
864 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
865 * <ksj:busLineName>湯07</ksj:busLineName>
\r
866 * </ksj:BusRouteInformation>
\r
867 * </ksj:busRouteInformation>
\r
868 * <ksj:busRouteInformation>
\r
869 * <ksj:BusRouteInformation>
\r
870 * <ksj:busType>1</ksj:busType>
\r
871 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
872 * <ksj:busLineName>湯11</ksj:busLineName>
\r
873 * </ksj:BusRouteInformation>
\r
874 * </ksj:busRouteInformation>
\r
879 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
880 * @throws IOException
\r
881 * @throws SQLException
\r
883 public static void showBusStop(Connection con, Node node, String iFileName) throws IOException, SQLException {
\r
884 String idrefStr = "";
\r
885 String nameStr = "";
\r
886 PreparedStatement ps2 = con.prepareStatement("UPDATE bus_stop SET name=?,ifile=? WHERE idref=?");
\r
887 PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
\r
888 PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
\r
889 PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
\r
890 PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
\r
892 ArrayList<String[]> bris = new ArrayList<String[]>();
\r
893 NodeList nodes = node.getChildNodes();
\r
894 for (int i=0; i < nodes.getLength(); i++) {
\r
895 Node node2 = nodes.item(i);
\r
896 if (node2.getNodeName().equals("ksj:position")) {
\r
897 NamedNodeMap nodeMap = node2.getAttributes();
\r
898 if (null != nodeMap) {
\r
899 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
900 if (nodeMap.item(j).getNodeName().equals("xlink:href")) {
\r
901 idrefStr = nodeMap.item(j).getNodeValue();
\r
902 idrefStr = idrefStr.substring(1);
\r
903 System.out.println("found idref='"+ idrefStr +"'");
\r
909 else if (node2.getNodeName().equals("ksj:busStopName")) {
\r
910 nameStr = node2.getTextContent();
\r
912 else if (node2.getNodeName().equals("ksj:busRouteInformation")) {
\r
913 String[] rtn = anaCommJGD(node2);
\r
920 // idref と nameStr をデータベースに格納する
\r
921 ps2.setString(1, nameStr);
\r
922 ps2.setString(2, iFileName);
\r
923 ps2.setString(3, idrefStr);
\r
924 ps2.executeUpdate();
\r
926 for (String[] rtn : bris) {
\r
928 ps3.setString(1, rtn[1]);
\r
929 ps3.setString(2, rtn[2]);
\r
930 ps3.setString(3, iFileName);
\r
931 ResultSet rset = ps3.executeQuery();
\r
933 code = rset.getInt(1);
\r
938 ps6.setString(1, iFileName);
\r
939 ResultSet rset6 = ps6.executeQuery();
\r
940 if (rset6.next()) {
\r
941 code = rset6.getInt(1);
\r
946 System.out.println("course="+ code +" : "+ rtn[0] +" : "+ rtn[1] +" : "+ rtn[2] );
\r
947 ps4.setInt(1, code);
\r
948 ps4.setInt(2, Integer.parseInt(rtn[0]));
\r
949 ps4.setString(3, rtn[2]);
\r
950 ps4.setString(4, rtn[1]);
\r
951 ps4.setString(5, iFileName);
\r
952 ps4.executeUpdate();
\r
955 ps5.setString(1, idrefStr);
\r
956 ps5.setInt(2, code);
\r
957 ps5.executeUpdate();
\r
966 public static String[] anaComm(Node briNode) {
\r
967 String[] rtn = new String[3];
\r
968 rtn[0] = ""; // corp type
\r
969 rtn[1] = ""; // course name
\r
970 rtn[2] = ""; // corp name
\r
972 NodeList nodes = briNode.getChildNodes();
\r
973 for (int i=0; i < nodes.getLength(); i++) {
\r
974 Node node2 = nodes.item(i);
\r
975 if (node2.getNodeName().equals("ksj:BSC")) {
\r
976 rtn[0] = node2.getTextContent();
\r
978 else if (node2.getNodeName().equals("ksj:BLN")) {
\r
979 rtn[1] = node2.getTextContent();
\r
981 else if (node2.getNodeName().equals("ksj:BOC")) {
\r
982 rtn[2] = node2.getTextContent();
\r
990 * <ksj:busRouteInformation>
\r
991 * <ksj:BusRouteInformation>
\r
992 * <ksj:busType>1</ksj:busType>
\r
993 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
994 * <ksj:busLineName>小01</ksj:busLineName>
\r
995 * </ksj:BusRouteInformation>
\r
996 * </ksj:busRouteInformation>
\r
1001 public static String[] anaCommJGD(Node briNode) {
\r
1002 String[] rtn = new String[3];
\r
1005 NodeList nodes2 = briNode.getChildNodes();
\r
1006 for (int i=0; i < nodes2.getLength(); i++) {
\r
1007 Node node2 = nodes2.item(i);
\r
1008 if (node2.getNodeName().equals("ksj:BusRouteInformation")) {
\r
1009 NodeList nodes3 = node2.getChildNodes();
\r
1010 for (int j=0; j < nodes3.getLength(); j++) {
\r
1011 Node node3 = nodes3.item(j);
\r
1012 if (node3.getNodeName().equals("ksj:busType")) {
\r
1013 rtn[0] = new String(node3.getTextContent());
\r
1016 else if (node3.getNodeName().equals("ksj:busLineName")) {
\r
1017 rtn[1] = new String(node3.getTextContent());
\r
1020 else if (node3.getNodeName().equals("ksj:busOperationCompany")) {
\r
1021 rtn[2] = new String(node3.getTextContent());
\r
1034 public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {
\r
1035 String positionStr = "";
\r
1036 String latStr = "";
\r
1037 String lonStr = "";
\r
1038 String idStr = "";
\r
1040 NamedNodeMap nodeMap = node.getAttributes();
\r
1041 if ( null != nodeMap ) {
\r
1042 for ( int j=0; j<nodeMap.getLength(); j++ ) {
\r
1043 if (nodeMap.item(j).getNodeName().equals("id")) {
\r
1044 idStr = nodeMap.item(j).getNodeValue();
\r
1049 NodeList nodes = node.getChildNodes();
\r
1050 for (int i=0; i < nodes.getLength(); i++) {
\r
1051 Node node2 = nodes.item(i);
\r
1052 if (node2.getNodeName().equals("jps:GM_Point.position")) {
\r
1053 NodeList nodes3 = node2.getChildNodes();
\r
1054 for (int j=0; j < nodes3.getLength(); j++) {
\r
1055 Node node3 = nodes3.item(j);
\r
1056 if (node3.getNodeName().equals("jps:DirectPosition")) {
\r
1057 NodeList nodes4 = node3.getChildNodes();
\r
1058 for (int k=0; k < nodes4.getLength(); k++) {
\r
1059 Node node4 = nodes4.item(k);
\r
1060 if (node4.getNodeName().equals("DirectPosition.coordinate")) {
\r
1061 positionStr = node4.getTextContent();
\r
1062 String[] str4Ary = positionStr.split(" ");
\r
1063 latStr = str4Ary[0];
\r
1064 lonStr = str4Ary[1];
\r
1072 PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
\r
1073 double lat = Double.parseDouble(latStr);
\r
1074 double lon = Double.parseDouble(lonStr);
\r
1075 ps6.setDouble(1, lat);
\r
1076 ps6.setDouble(2, lon);
\r
1077 // ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
\r
1079 ps6.setString(4, idStr);
\r
1080 System.out.println("UPDATE bus_stop("+ idStr +") lat="+ lat +", lon="+ lon +", fixed=0");
\r
1081 ps6.executeUpdate();
\r
1088 * <gml:Point gml:id="n1">
\r
1089 * <gml:pos>35.14591397 139.10569573</gml:pos>
\r
1094 * @throws IOException
\r
1095 * @throws SQLException
\r
1097 public static void showGmlPoint(Connection con, Node node) throws IOException, SQLException {
\r
1098 String positionStr = "";
\r
1099 String latStr = "";
\r
1100 String lonStr = "";
\r
1101 String idStr = "";
\r
1103 NamedNodeMap nodeMap = node.getAttributes();
\r
1104 if ( null != nodeMap ) {
\r
1105 for ( int j=0; j<nodeMap.getLength(); j++ ) {
\r
1106 if (nodeMap.item(j).getNodeName().equals("gml:id")) {
\r
1107 idStr = nodeMap.item(j).getNodeValue();
\r
1112 NodeList nodes = node.getChildNodes();
\r
1113 for (int i=0; i < nodes.getLength(); i++) {
\r
1114 Node node2 = nodes.item(i);
\r
1115 if (node2.getNodeName().equals("gml:pos")) {
\r
1116 positionStr = node2.getTextContent().trim();
\r
1117 String[] str4Ary = positionStr.split(" ");
\r
1118 latStr = str4Ary[0];
\r
1119 lonStr = str4Ary[1];
\r
1121 PreparedStatement ps6 = con.prepareStatement("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES (?,?,?,?)");
\r
1122 double lat = Double.parseDouble(latStr);
\r
1123 double lon = Double.parseDouble(lonStr);
\r
1124 System.out.println("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES ('"+ latStr +"','"+ lonStr +"','0','"+ idStr +"')");
\r
1126 ps6.setDouble(1, lat);
\r
1127 ps6.setDouble(2, lon);
\r
1128 //ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
\r
1130 ps6.setString(4, idStr);
\r
1131 ps6.executeUpdate();
\r
1137 static boolean checkFile(File f) {
\r
1138 String name = f.getName();
\r
1139 if (!name.startsWith("P11-")) {
\r
1142 if (!name.toUpperCase().endsWith(".XML")) {
\r