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 File dir = new File(".");
\r
81 File[] files = dir.listFiles();
\r
82 for (File iFile : files) {
\r
83 if (checkFile(iFile)) {
\r
85 ConvBusstop.clearDb(con);
\r
86 inputFile(con, iFile);
\r
88 String iStr = iFile.getName();
\r
89 iStr = iStr.substring(0, iStr.length() - 4);
\r
93 * --> 'existing.xml'
\r
95 if (!ConvBusstop.nocheck && (fcounter > 0)) {
\r
97 * 既存のOSMデータファイルがなければ、新たにダウンロードする。
\r
98 * OSMデータファイルがあるときは、ダウンロードしないでそれを使う。
\r
100 File existingFile = new File(iStr, "existing.xml");
\r
101 if (!existingFile.isFile()) {
\r
103 * インポートしたデータの緯度経度範囲を読み取る
\r
105 double maxLat = -90.0D;
\r
106 double minLat = 90.0D;
\r
107 double maxLon = -180.0D;
\r
108 double minLon = 180.0D;
\r
109 PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM bus_stop");
\r
110 ResultSet rset8 = ps8.executeQuery();
\r
111 while (rset8.next()) {
\r
112 Double lat = rset8.getDouble("lat");
\r
113 Double lon = rset8.getDouble("lon");
\r
115 if (lat > maxLat) {
\r
118 if (lon > maxLon) {
\r
121 if (lat < minLat) {
\r
124 if (lon < minLon) {
\r
131 * OSM OverPassAPI を使って、既存のOSMバス停のデータを取得して、「existing.xml」に出力する
\r
133 HttpPOST.getCapabilities(new File(iStr), minLat, maxLat, minLon, maxLon);
\r
135 readExistingFile(con, existingFile);
\r
137 PreparedStatement ps1 = con.prepareStatement("SELECT idref,name,lat,lon FROM bus_stop");
\r
138 PreparedStatement ps2 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)");
\r
139 PreparedStatement ps3 = con.prepareStatement("UPDATE bus_stop SET fixed=? WHERE idref=?");
\r
140 PreparedStatement ps4 = con.prepareStatement("SELECT count(idref) FROM existing_data where (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?) and (name = ?)");
\r
141 ResultSet rset1 = ps1.executeQuery();
\r
142 while (rset1.next()) {
\r
143 String idref = rset1.getString("idref");
\r
144 String name = rset1.getString("name");
\r
145 Double lat = rset1.getDouble("lat");
\r
146 Double lon = rset1.getDouble("lon");
\r
148 // 指定の緯度経度を中心とする半径150x2m四方の矩形領域
\r
149 System.out.print(idref + "("+ name + ") ....");
\r
150 RectArea rect = new RectArea(lat, lon, NEER); // 300m 四方
\r
151 ps2.setDouble(1, rect.minlat);
\r
152 ps2.setDouble(2, rect.maxlat);
\r
153 ps2.setDouble(3, rect.minlon);
\r
154 ps2.setDouble(4, rect.maxlon);
\r
155 ResultSet rset2 = ps2.executeQuery();
\r
156 if (rset2.next()) {
\r
157 int count = rset2.getInt(1);
\r
159 System.out.println("."+ count);
\r
160 ps3.setInt(1, count);
\r
161 ps3.setString(2, idref);
\r
162 ps3.executeUpdate();
\r
165 // 指定の緯度経度を中心とする半径150x4m四方の矩形領域
\r
166 System.out.print("***");
\r
167 rect = new RectArea(lat, lon, NEER*2); // 600m 四方
\r
168 ps4.setDouble(1, rect.minlat);
\r
169 ps4.setDouble(2, rect.maxlat);
\r
170 ps4.setDouble(3, rect.minlon);
\r
171 ps4.setDouble(4, rect.maxlon);
\r
172 ps4.setString(5, name);
\r
173 ResultSet rset4 = ps4.executeQuery();
\r
174 if (rset4.next()) {
\r
175 count = rset4.getInt(1);
\r
176 System.out.println(".."+ count);
\r
177 ps3.setInt(1, count);
\r
178 ps3.setString(2, idref);
\r
179 ps3.executeUpdate();
\r
193 // ローカルデータベース内の情報を出力する
\r
194 outputDb(con, iStr);
\r
196 // ローカルデータベース内の情報を「busstop.xml」に出力する
\r
197 int counter = outputDb(con, new File(iStr));
\r
198 System.out.println("["+ counter +"] 変換完了しました。");
\r
201 System.out.println("["+ fcounter +"]つのファイルをインポートしました。");
\r
204 DatabaseTool.closeDb(con);
\r
208 static String[] shiftArgs(String[] args) {
\r
209 String[] values = new String[args.length - 1];
\r
210 for (int i=1; i < args.length; i++) {
\r
211 values[i - 1] = new String(args[i]);
\r
216 public static void readExistingFile (Connection con, File existingFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
\r
219 DocumentBuilderFactory factory;
\r
220 DocumentBuilder builder;
\r
224 factory = DocumentBuilderFactory.newInstance();
\r
225 builder = factory.newDocumentBuilder();
\r
226 factory.setIgnoringElementContentWhitespace(true);
\r
227 factory.setIgnoringComments(true);
\r
228 factory.setValidating(true);
\r
229 root = builder.parse(existingFile);
\r
231 iCounter += readExistingNodes(con, root);
\r
232 System.out.println("既存バス停数["+ iCounter +"]");
\r
235 static int readExistingNodes(Connection con, Node node) throws IOException, SQLException {
\r
238 NodeList nodes = node.getChildNodes();
\r
239 for (int i = 0; i < nodes.getLength(); i++) {
\r
240 Node node2 = nodes.item(i);
\r
241 if (node2.getNodeName().equals("node")) {
\r
243 importExistingNode(con, node2);
\r
246 iCounter += readExistingNodes(con, node2);
\r
252 static void importExistingNode(Connection con, Node node) throws IOException, SQLException {
\r
253 String idrefStr = "";
\r
254 String latStr = "";
\r
255 String lonStr = "";
\r
256 String nameStr = "";
\r
257 PreparedStatement ps5 = con.prepareStatement("INSERT INTO existing_data (idref,lat,lon, name) VALUES (?,?,?,?)");
\r
259 NamedNodeMap nodeMap = node.getAttributes();
\r
260 if (null != nodeMap) {
\r
261 for (int j=0; j < nodeMap.getLength(); j++) {
\r
262 if (nodeMap.item(j).getNodeName().equals("id")) {
\r
263 idrefStr = nodeMap.item(j).getNodeValue();
\r
265 else if (nodeMap.item(j).getNodeName().equals("lat")) {
\r
266 latStr = nodeMap.item(j).getNodeValue();
\r
268 else if (nodeMap.item(j).getNodeName().equals("lon")) {
\r
269 lonStr = nodeMap.item(j).getNodeValue();
\r
273 NodeList nodes = node.getChildNodes();
\r
274 for (int i = 0; i < nodes.getLength(); i++) {
\r
275 Node node2 = nodes.item(i);
\r
276 if (node2.getNodeName().equals("tag")) {
\r
277 NamedNodeMap nodeMap2 = node2.getAttributes();
\r
278 if (null != nodeMap2) {
\r
280 String value = null;
\r
281 for (int j=0; j < nodeMap2.getLength(); j++) {
\r
282 if (nodeMap2.item(j).getNodeName().equals("k")) {
\r
283 key = nodeMap2.item(j).getNodeValue();
\r
285 else if (nodeMap2.item(j).getNodeName().equals("v")) {
\r
286 value = nodeMap2.item(j).getNodeValue();
\r
290 if ((key != null) && key.toLowerCase().equals("name") && (value != null)) {
\r
298 // idref と nameStr をデータベースに格納する
\r
299 System.out.println("import existing_data : "+ idrefStr +" ("+ latStr +","+ lonStr+")"+ nameStr);
\r
300 ps5.setString(1, idrefStr);
\r
301 ps5.setDouble(2, Double.parseDouble(latStr));
\r
302 ps5.setDouble(3, Double.parseDouble(lonStr));
\r
303 ps5.setString(4, nameStr);
\r
304 ps5.executeUpdate();
\r
310 * ソースファイルを読み取ってローカルベータベースへ記録する
\r
313 * @throws FileNotFoundException
\r
314 * @throws ClassNotFoundException
\r
315 * @throws SQLException
\r
316 * @throws IOException
\r
317 * @throws ParserConfigurationException
\r
318 * @throws SAXException
\r
320 public static void inputFile (Connection con, File iFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
\r
322 String timeStampStr = null;
\r
324 String iStr = iFile.getName();
\r
325 File dir = new File(iStr.substring(0, iStr.length() - 4));
\r
328 DocumentBuilderFactory factory;
\r
329 DocumentBuilder builder;
\r
333 factory = DocumentBuilderFactory.newInstance();
\r
334 builder = factory.newDocumentBuilder();
\r
335 factory.setIgnoringElementContentWhitespace(true);
\r
336 factory.setIgnoringComments(true);
\r
337 factory.setValidating(true);
\r
338 root = builder.parse(iStr);
\r
340 iCounter += showNodes(con, root, iStr.substring(0, iStr.length() - 4), timeStampStr);
\r
341 System.out.println("バス停数["+ iCounter +"]");
\r
344 public static void clearDb(Connection con) throws SQLException {
\r
345 Statement stmt = con.createStatement();
\r
346 long count = stmt.executeUpdate("delete from bus_stop");
\r
347 System.out.println("'Database.bus_stop'から "+ count +" 件のデータを削除しました。");
\r
349 count = stmt.executeUpdate("delete from existing_data");
\r
350 System.out.println("'Database.existing_data'から "+ count +" 件のデータを削除しました。");
\r
352 count = stmt.executeUpdate("delete from bus_course");
\r
353 System.out.println("'Database.bus_course'から "+ count +" 件のデータを削除しました。");
\r
355 count = stmt.executeUpdate("delete from bus_ref");
\r
356 System.out.println("'Database.bus_ref'から "+ count +" 件のデータを削除しました。");
\r
360 public static void initDb(Connection con) throws SQLException {
\r
363 // 'table.BUS_STOP'を新規に作る
\r
364 DbBusstop.create(con);
\r
366 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
367 DbBusstop.create(con, createSt);
\r
369 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
370 DbBusstop.create(con, createSt);
\r
372 createSt = "CREATE TABLE bus_ref (idref VARCHAR(12), code INT);";
\r
373 DbBusstop.create(con, createSt);
\r
378 * ローカルデータベース内の情報を出力する
\r
381 * @throws IOException
\r
382 * @throws SQLException
\r
384 public static void outputDb(Connection con, String iCode) throws IOException, SQLException {
\r
385 SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
\r
386 String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
\r
387 File dir = new File(iCode);
\r
390 BufferedWriter ow = null;
\r
391 BufferedWriter gw = null;
\r
392 BufferedWriter hw = null;
\r
393 BufferedWriter ww = null;
\r
396 File htmlFile = new File(iCode +".html");
\r
397 hw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile), "UTF-8"));
\r
398 hw.write("<!DOCTYPE html>");
\r
400 hw.write("<html><head><meta charset=\"utf-8\" /></head>");
\r
402 hw.write("<body><table border='1'>");
\r
405 hw.write("<td>type</td>");
\r
406 hw.write("<td>corp</td>");
\r
407 hw.write("<td>course</td>");
\r
408 hw.write("<td>GPX</td>");
\r
409 hw.write("<td>SAMPLE</td>");
\r
410 hw.write("<td>バス停数</td>");
\r
411 hw.write("<td>未入力</td>");
\r
412 hw.write("<td>既存</td>");
\r
417 File wikiFile = new File(iCode +".wiki.txt");
\r
418 ww = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(wikiFile), "UTF-8"));
\r
419 ww.write("= バス路線毎のマッピング状況 =");
\r
423 String maeCorp = "";
\r
424 boolean firstCorp = true;
\r
426 PreparedStatement ps7 = con.prepareStatement("SELECT code,type,corp,course,ifile FROM bus_course WHERE ifile=? ORDER BY type,corp,course");
\r
427 PreparedStatement ps9 = con.prepareStatement("SELECT idref FROM bus_ref WHERE code=?");
\r
428 PreparedStatement ps8 = con.prepareStatement("SELECT name,lat,lon,fixed FROM bus_stop WHERE idref=?");
\r
429 ps7.setString(1, iCode);
\r
430 ResultSet rset7 = ps7.executeQuery();
\r
431 while (rset7.next()) {
\r
432 int code = rset7.getInt(1);
\r
433 int type = rset7.getInt(2);
\r
434 String corp = rset7.getString(3);
\r
435 String course = rset7.getString(4);
\r
438 File osmFile = new File(dir, iCode + String.format("_%1$08d", code) +".osm");
\r
439 File gpxFile = new File(dir, iCode + String.format("_%1$08d", code) +".gpx");
\r
440 File osmSample = new File(dir, iCode + String.format("_s%1$08d", code) +".osm");
\r
442 System.out.println("course = "+ course);
\r
444 int fixedCount = 0;
\r
445 int unfixedCount = 0;
\r
447 // index file header
\r
449 hw.write("<td>"+ type +"</td>");
\r
450 hw.write("<td>"+ corp +"</td>");
\r
451 hw.write("<td><a href='"+ dir.getName() +"/"+ osmFile.getName() +"'>"+ course +"</a></td>");
\r
452 hw.write("<td><a href='"+ dir.getName() +"/"+ gpxFile.getName() +"'>"+ gpxFile.getName() +"</a></td>");
\r
453 hw.write("<td><a href='"+ dir.getName() +"/"+ osmSample.getName() +"'>"+ osmSample.getName() +"</a></td>");
\r
456 //--------------------------------------------
\r
459 if (!maeCorp.equals(corp)) {
\r
460 if (firstCorp == false) {
\r
467 ww.write("=== "+ corp +" ===");
\r
471 ww.write(":{{JA:Tag|network||"+ corp +"}}");
\r
473 ww.write(":{{JA:Tag|operator||"+ corp +"}}");
\r
477 ww.write("{| class=\"wikitable sortable\" style=\"table-layout: fixed; width: 100%\"");
\r
479 ww.write("!style=\"width: 100px\"| ref");
\r
481 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(マスタ)");
\r
483 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(往路)");
\r
485 ww.write("!class=\"unsortable\" style=\"width: 152px\"| 編集状況(復路)");
\r
487 ww.write("!class=\"unsortable\"| 備考");
\r
490 maeCorp = new String(corp);
\r
496 ww.write("| "+ course +" "); // ref
\r
497 ww.write("|| {{State Route|r=0}} {{relation|0|tools=no}} "); // 編集状況 (マスタ)
\r
498 ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} "); // 編集状況 (往路)
\r
499 ww.write("|| {{State Route|r=0|h=0}} {{relation|0|tools=no}} "); // 編集状況 (復路)
\r
500 ww.write("|| "); // 備考
\r
505 ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));
\r
506 ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
508 ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");
\r
512 gw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(gpxFile), "UTF-8"));
\r
513 gw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
515 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
518 double maxLat = -180.0;
\r
519 double minLat = 180.0;
\r
520 double maxLon = -180.0;
\r
521 double minLon = 180.0;
\r
523 ps9.setInt(1, code);
\r
524 ResultSet rset9 = ps9.executeQuery();
\r
525 while (rset9.next()) {
\r
526 String idref = rset9.getString(1);
\r
528 ps8.setString(1, idref);
\r
529 ResultSet rset8 = ps8.executeQuery();
\r
530 if (rset8.next()) {
\r
532 String name = rset8.getString(1);
\r
533 Double lat = rset8.getDouble(2);
\r
534 Double lon = rset8.getDouble(3);
\r
535 int fixed = rset8.getInt(4);
\r
537 if (lat > maxLat) {
\r
540 if (lon > maxLon) {
\r
543 if (lat < minLat) {
\r
546 if (lon < minLon) {
\r
550 System.out.println("\tway point = "+ idref +", lat="+ lat +", lon="+ lon +", name="+ name);
\r
551 fixedCount += fixed;
\r
556 int nodeid = Integer.parseInt(idref.substring(1)) * -1;
\r
557 String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);
\r
558 ow.write(osm_node);
\r
562 //File txtFile = new File(dir, iCode + idref +".txt");
\r
563 //BufferedWriter gw2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(txtFile), "UTF-8"));
\r
564 //gw2.write(osm_node);
\r
569 gw.write("<wpt lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
\r
570 gw.write(" <time>"+ timeStampStr +"Z</time>\n");
\r
571 gw.write(" <name><![CDATA["+ name +"]]></name>\n");
\r
572 //gw.write(" <link href=\""+ txtFile.getName() +"\"><text>"+ idref +"</text></link>\n");
\r
573 gw.write("</wpt>\n");
\r
582 hw.write("<td>"+ stopCount +"</td>");
\r
583 hw.write("<td>"+ unfixedCount +"</td>");
\r
584 hw.write("<td>"+ fixedCount +"</td>");
\r
589 BufferedWriter ow2 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmSample), "UTF-8"));
\r
590 ow2.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
592 ow2.write("<osm version=\"0.5\" generator=\"ConvBusstop\">");
\r
595 ow2.write(nodeBusstop(code, "SAMPLE", ((maxLat+minLat)/2), ((maxLon+minLon)/2), timeStampStr));
\r
597 ow2.write("</osm>");
\r
602 ow.write("</osm>");
\r
607 gw.write("</gpx>");
\r
616 // index file footer
\r
617 hw.write("</table></body></html>");
\r
622 public static int outputDb(Connection con, File dir) throws IOException, SQLException {
\r
623 File osmFile = new File(dir, "busstop.osm");
\r
626 SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
\r
627 String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
\r
628 BufferedWriter ow = null;
\r
631 ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(osmFile), "UTF-8"));
\r
632 ow.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
\r
634 ow.write("<osm version=\"0.6\" generator=\"ConvBusstop\">");
\r
637 PreparedStatement ps8 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM bus_stop");
\r
638 ResultSet rset8 = ps8.executeQuery();
\r
639 while (rset8.next()) {
\r
640 String idref = rset8.getString("idref");
\r
641 String name = rset8.getString("name");
\r
642 Double lat = rset8.getDouble("lat");
\r
643 Double lon = rset8.getDouble("lon");
\r
644 int fixed = rset8.getInt("fixed");
\r
646 if (ConvBusstop.nocheck || (fixed < 1)) {
\r
649 int nodeid = Integer.parseInt(idref.substring(1)) * -1;
\r
650 String osm_node = nodeBusstop(nodeid, name, lat, lon, timeStampStr);
\r
651 System.out.println(osm_node);
\r
652 ow.write(osm_node);
\r
659 ow.write("</osm>");
\r
665 public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) {
\r
666 String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
\r
667 osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n";
\r
668 osm_node += "<tag k=\"fixme\" v=\"platform/stop_positionを選択して、正しい位置に移動させてください\"/>\n";
\r
669 osm_node += "<tag k=\"source\" v=\"KSJ2\"/>\n";
\r
670 osm_node += "<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11.html\"/>\n";
\r
671 osm_node += "<tag k=\"created_by\" v=\"National-Land-Numerical-Information_MLIT_Japan\"/>\n";
\r
672 osm_node += "<tag k=\"note\" v=\"National-Land Numerical Information (Bus stop) 2012, MLIT Japan\"/>\n";
\r
673 osm_node += "<tag k=\"note:ja\" v=\"国土数値情報(バス停留所)平成24年 国土交通省\"/>\n";
\r
674 osm_node += "<tag k=\"public_transport\" v=\"platform\"/>\n";
\r
675 osm_node += "<tag k=\"public_transport\" v=\"stop_position\"/>\n";
\r
676 osm_node += "<tag k=\"highway\" v=\"bus_stop\"/>\n";
\r
677 osm_node += "<tag k=\"bus\" v=\"yes\"/>\n";
\r
678 osm_node += "</node>\n";
\r
686 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
687 * @param timeStampStr
\r
689 * @throws IOException
\r
690 * @throws SQLException
\r
692 public static int showNodes(Connection con, Node node, String iFileName, String timeStampStr) throws IOException, SQLException {
\r
694 NamedNodeMap nodeMap = node.getAttributes();
\r
695 if ( null != nodeMap ) {
\r
696 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
697 if (nodeMap.item(j).getNodeName().equals("timeStamp")) {
\r
698 timeStampStr = nodeMap.item(j).getNodeValue();
\r
703 NodeList nodes = node.getChildNodes();
\r
704 for (int i=0; i<nodes.getLength(); i++) {
\r
705 Node node2 = nodes.item(i);
\r
706 if (node2.getNodeName().equals("jps:GM_Point")) {
\r
707 showGmPoint(con, node2);
\r
709 else if (node2.getNodeName().equals("gml:Point")) {
\r
710 showGmlPoint(con, node2);
\r
713 else if (node2.getNodeName().equals("ksj:ED01")) {
\r
715 showED01(con, node2, iFileName);
\r
717 else if (node2.getNodeName().equals("ksj:BusStop")) {
\r
719 showBusStop(con, node2, iFileName);
\r
723 iCounter += showNodes(con, node2, iFileName, timeStampStr);
\r
733 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
734 * @throws IOException
\r
735 * @throws SQLException
\r
737 public static void showED01(Connection con, Node node, String iFileName) throws IOException, SQLException {
\r
738 String idrefStr = "";
\r
739 String nameStr = "";
\r
740 PreparedStatement ps1 = con.prepareStatement("SELECT idref FROM bus_stop WHERE idref=?");
\r
741 PreparedStatement ps2 = con.prepareStatement("INSERT INTO bus_stop (idref,name,ifile) VALUES (?,?,?)");
\r
742 PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
\r
743 PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
\r
744 PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
\r
745 PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
\r
747 ArrayList<String[]> bris = new ArrayList<String[]>();
\r
748 NodeList nodes = node.getChildNodes();
\r
749 for (int i=0; i < nodes.getLength(); i++) {
\r
750 Node node2 = nodes.item(i);
\r
751 if (node2.getNodeName().equals("ksj:POS")) {
\r
752 NamedNodeMap nodeMap = node2.getAttributes();
\r
753 if (null != nodeMap) {
\r
754 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
755 if (nodeMap.item(j).getNodeName().equals("idref")) {
\r
756 idrefStr = nodeMap.item(j).getNodeValue();
\r
757 System.out.println("found idref='"+ idrefStr +"'");
\r
763 else if (node2.getNodeName().equals("ksj:BSN")) {
\r
764 nameStr = node2.getTextContent();
\r
766 else if (node2.getNodeName().equals("ksj:BRI")) {
\r
767 String[] rtn = anaComm(node2);
\r
774 // idref と nameStr をデータベースに格納する
\r
775 boolean insert = true;
\r
776 ps1.setString(1, idrefStr);
\r
777 ResultSet rset = ps1.executeQuery();
\r
784 ps2.setString(1, idrefStr);
\r
785 ps2.setString(2, nameStr);
\r
786 ps2.setString(3, iFileName);
\r
787 System.out.println("INSERT INTO bus_stop (idref,name,ifile) VALUES ('"+ idrefStr +"','"+ nameStr +"','"+ iFileName +"')");
\r
788 ps2.executeUpdate();
\r
791 for (String[] rtn : bris) {
\r
793 ps3.setString(1, rtn[1]);
\r
794 ps3.setString(2, rtn[2]);
\r
795 ps3.setString(3, iFileName);
\r
796 rset = ps3.executeQuery();
\r
798 code = rset.getInt(1);
\r
803 ps6.setString(1, iFileName);
\r
804 ResultSet rset6 = ps6.executeQuery();
\r
805 if (rset6.next()) {
\r
806 code = rset6.getInt(1);
\r
811 System.out.println("code="+code);
\r
812 ps4.setInt(1, code);
\r
813 ps4.setInt(2, Integer.parseInt(rtn[0]));
\r
814 ps4.setString(3, rtn[2]);
\r
815 ps4.setString(4, rtn[1]);
\r
816 ps4.setString(5, iFileName);
\r
817 ps4.executeUpdate();
\r
820 ps5.setString(1, idrefStr);
\r
821 ps5.setInt(2, code);
\r
822 ps5.executeUpdate();
\r
833 * <ksj:BusStop gml:id="ED01_1">
\r
834 * <ksj:position xlink:href="#n1"/>
\r
835 * <ksj:busStopName>城堀</ksj:busStopName>
\r
836 * <ksj:busRouteInformation>
\r
837 * <ksj:BusRouteInformation>
\r
838 * <ksj:busType>1</ksj:busType>
\r
839 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
840 * <ksj:busLineName>小01</ksj:busLineName>
\r
841 * </ksj:BusRouteInformation>
\r
842 * </ksj:busRouteInformation>
\r
843 * <ksj:busRouteInformation>
\r
844 * <ksj:BusRouteInformation>
\r
845 * <ksj:busType>1</ksj:busType>
\r
846 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
847 * <ksj:busLineName>湯07</ksj:busLineName>
\r
848 * </ksj:BusRouteInformation>
\r
849 * </ksj:busRouteInformation>
\r
850 * <ksj:busRouteInformation>
\r
851 * <ksj:BusRouteInformation>
\r
852 * <ksj:busType>1</ksj:busType>
\r
853 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
854 * <ksj:busLineName>湯11</ksj:busLineName>
\r
855 * </ksj:BusRouteInformation>
\r
856 * </ksj:busRouteInformation>
\r
861 * @param iFileName // ソースファイル名(拡張子を含まない)
\r
862 * @throws IOException
\r
863 * @throws SQLException
\r
865 public static void showBusStop(Connection con, Node node, String iFileName) throws IOException, SQLException {
\r
866 String idrefStr = "";
\r
867 String nameStr = "";
\r
868 PreparedStatement ps2 = con.prepareStatement("UPDATE bus_stop SET name=?,ifile=? WHERE idref=?");
\r
869 PreparedStatement ps3 = con.prepareStatement("SELECT code FROM bus_course WHERE course=? AND corp=? AND ifile=?");
\r
870 PreparedStatement ps4 = con.prepareStatement("INSERT INTO bus_course (code,type,corp,course,ifile) VALUES (?,?,?,?,?)");
\r
871 PreparedStatement ps5 = con.prepareStatement("INSERT INTO bus_ref (idref,code) VALUES (?,?)");
\r
872 PreparedStatement ps6 = con.prepareStatement("SELECT max(code) FROM bus_course WHERE ifile=?");
\r
874 ArrayList<String[]> bris = new ArrayList<String[]>();
\r
875 NodeList nodes = node.getChildNodes();
\r
876 for (int i=0; i < nodes.getLength(); i++) {
\r
877 Node node2 = nodes.item(i);
\r
878 if (node2.getNodeName().equals("ksj:position")) {
\r
879 NamedNodeMap nodeMap = node2.getAttributes();
\r
880 if (null != nodeMap) {
\r
881 for ( int j=0; j < nodeMap.getLength(); j++ ) {
\r
882 if (nodeMap.item(j).getNodeName().equals("xlink:href")) {
\r
883 idrefStr = nodeMap.item(j).getNodeValue();
\r
884 idrefStr = idrefStr.substring(1);
\r
885 System.out.println("found idref='"+ idrefStr +"'");
\r
891 else if (node2.getNodeName().equals("ksj:busStopName")) {
\r
892 nameStr = node2.getTextContent();
\r
894 else if (node2.getNodeName().equals("ksj:busRouteInformation")) {
\r
895 String[] rtn = anaCommJGD(node2);
\r
902 // idref と nameStr をデータベースに格納する
\r
903 ps2.setString(1, nameStr);
\r
904 ps2.setString(2, iFileName);
\r
905 ps2.setString(3, idrefStr);
\r
906 ps2.executeUpdate();
\r
908 for (String[] rtn : bris) {
\r
910 ps3.setString(1, rtn[1]);
\r
911 ps3.setString(2, rtn[2]);
\r
912 ps3.setString(3, iFileName);
\r
913 ResultSet rset = ps3.executeQuery();
\r
915 code = rset.getInt(1);
\r
920 ps6.setString(1, iFileName);
\r
921 ResultSet rset6 = ps6.executeQuery();
\r
922 if (rset6.next()) {
\r
923 code = rset6.getInt(1);
\r
928 System.out.println("course="+ code +" : "+ rtn[0] +" : "+ rtn[1] +" : "+ rtn[2] );
\r
929 ps4.setInt(1, code);
\r
930 ps4.setInt(2, Integer.parseInt(rtn[0]));
\r
931 ps4.setString(3, rtn[2]);
\r
932 ps4.setString(4, rtn[1]);
\r
933 ps4.setString(5, iFileName);
\r
934 ps4.executeUpdate();
\r
937 ps5.setString(1, idrefStr);
\r
938 ps5.setInt(2, code);
\r
939 ps5.executeUpdate();
\r
948 public static String[] anaComm(Node briNode) {
\r
949 String[] rtn = new String[3];
\r
950 rtn[0] = ""; // corp type
\r
951 rtn[1] = ""; // course name
\r
952 rtn[2] = ""; // corp name
\r
954 NodeList nodes = briNode.getChildNodes();
\r
955 for (int i=0; i < nodes.getLength(); i++) {
\r
956 Node node2 = nodes.item(i);
\r
957 if (node2.getNodeName().equals("ksj:BSC")) {
\r
958 rtn[0] = node2.getTextContent();
\r
960 else if (node2.getNodeName().equals("ksj:BLN")) {
\r
961 rtn[1] = node2.getTextContent();
\r
963 else if (node2.getNodeName().equals("ksj:BOC")) {
\r
964 rtn[2] = node2.getTextContent();
\r
972 * <ksj:busRouteInformation>
\r
973 * <ksj:BusRouteInformation>
\r
974 * <ksj:busType>1</ksj:busType>
\r
975 * <ksj:busOperationCompany>箱根登山バス</ksj:busOperationCompany>
\r
976 * <ksj:busLineName>小01</ksj:busLineName>
\r
977 * </ksj:BusRouteInformation>
\r
978 * </ksj:busRouteInformation>
\r
983 public static String[] anaCommJGD(Node briNode) {
\r
984 String[] rtn = new String[3];
\r
987 NodeList nodes2 = briNode.getChildNodes();
\r
988 for (int i=0; i < nodes2.getLength(); i++) {
\r
989 Node node2 = nodes2.item(i);
\r
990 if (node2.getNodeName().equals("ksj:BusRouteInformation")) {
\r
991 NodeList nodes3 = node2.getChildNodes();
\r
992 for (int j=0; j < nodes3.getLength(); j++) {
\r
993 Node node3 = nodes3.item(j);
\r
994 if (node3.getNodeName().equals("ksj:busType")) {
\r
995 rtn[0] = new String(node3.getTextContent());
\r
998 else if (node3.getNodeName().equals("ksj:busLineName")) {
\r
999 rtn[1] = new String(node3.getTextContent());
\r
1002 else if (node3.getNodeName().equals("ksj:busOperationCompany")) {
\r
1003 rtn[2] = new String(node3.getTextContent());
\r
1016 public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {
\r
1017 String positionStr = "";
\r
1018 String latStr = "";
\r
1019 String lonStr = "";
\r
1020 String idStr = "";
\r
1022 NamedNodeMap nodeMap = node.getAttributes();
\r
1023 if ( null != nodeMap ) {
\r
1024 for ( int j=0; j<nodeMap.getLength(); j++ ) {
\r
1025 if (nodeMap.item(j).getNodeName().equals("id")) {
\r
1026 idStr = nodeMap.item(j).getNodeValue();
\r
1031 NodeList nodes = node.getChildNodes();
\r
1032 for (int i=0; i < nodes.getLength(); i++) {
\r
1033 Node node2 = nodes.item(i);
\r
1034 if (node2.getNodeName().equals("jps:GM_Point.position")) {
\r
1035 NodeList nodes3 = node2.getChildNodes();
\r
1036 for (int j=0; j < nodes3.getLength(); j++) {
\r
1037 Node node3 = nodes3.item(j);
\r
1038 if (node3.getNodeName().equals("jps:DirectPosition")) {
\r
1039 NodeList nodes4 = node3.getChildNodes();
\r
1040 for (int k=0; k < nodes4.getLength(); k++) {
\r
1041 Node node4 = nodes4.item(k);
\r
1042 if (node4.getNodeName().equals("DirectPosition.coordinate")) {
\r
1043 positionStr = node4.getTextContent();
\r
1044 String[] str4Ary = positionStr.split(" ");
\r
1045 latStr = str4Ary[0];
\r
1046 lonStr = str4Ary[1];
\r
1054 PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
\r
1055 double lat = Double.parseDouble(latStr);
\r
1056 double lon = Double.parseDouble(lonStr);
\r
1057 ps6.setDouble(1, lat);
\r
1058 ps6.setDouble(2, lon);
\r
1059 // ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
\r
1061 ps6.setString(4, idStr);
\r
1062 System.out.println("UPDATE bus_stop("+ idStr +") lat="+ lat +", lon="+ lon +", fixed=0");
\r
1063 ps6.executeUpdate();
\r
1070 * <gml:Point gml:id="n1">
\r
1071 * <gml:pos>35.14591397 139.10569573</gml:pos>
\r
1076 * @throws IOException
\r
1077 * @throws SQLException
\r
1079 public static void showGmlPoint(Connection con, Node node) throws IOException, SQLException {
\r
1080 String positionStr = "";
\r
1081 String latStr = "";
\r
1082 String lonStr = "";
\r
1083 String idStr = "";
\r
1085 NamedNodeMap nodeMap = node.getAttributes();
\r
1086 if ( null != nodeMap ) {
\r
1087 for ( int j=0; j<nodeMap.getLength(); j++ ) {
\r
1088 if (nodeMap.item(j).getNodeName().equals("gml:id")) {
\r
1089 idStr = nodeMap.item(j).getNodeValue();
\r
1094 NodeList nodes = node.getChildNodes();
\r
1095 for (int i=0; i < nodes.getLength(); i++) {
\r
1096 Node node2 = nodes.item(i);
\r
1097 if (node2.getNodeName().equals("gml:pos")) {
\r
1098 positionStr = node2.getTextContent().trim();
\r
1099 String[] str4Ary = positionStr.split(" ");
\r
1100 latStr = str4Ary[0];
\r
1101 lonStr = str4Ary[1];
\r
1103 PreparedStatement ps6 = con.prepareStatement("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES (?,?,?,?)");
\r
1104 double lat = Double.parseDouble(latStr);
\r
1105 double lon = Double.parseDouble(lonStr);
\r
1106 System.out.println("INSERT INTO bus_stop (lat,lon,fixed,idref) VALUES ('"+ latStr +"','"+ lonStr +"','0','"+ idStr +"')");
\r
1108 ps6.setDouble(1, lat);
\r
1109 ps6.setDouble(2, lon);
\r
1110 //ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
\r
1112 ps6.setString(4, idStr);
\r
1113 ps6.executeUpdate();
\r
1119 static boolean checkFile(File f) {
\r
1120 String name = f.getName();
\r
1121 if (!name.startsWith("P11-")) {
\r
1124 if (!name.toUpperCase().endsWith(".XML")) {
\r