• R/O
  • HTTP
  • SSH
  • HTTPS

convbusstop: Commit


Commit MetaInfo

Revisióncf7654815c3579f06dd1d879619022b38e315b33 (tree)
Tiempo2015-03-04 23:59:21
Autoryuuhayashi <hayashi.yuu@gmai...>
Commiteryuuhayashi

Log Message

Template 'osmTag.xml'.に、対応。

Cambiar Resumen

Diferencia incremental

--- a/src/osm/jp/ConvBusstop.java
+++ b/src/osm/jp/ConvBusstop.java
@@ -2,7 +2,12 @@ package osm.jp;
22 import osm.jp.api.HttpPOST;
33
44 import javax.xml.parsers.*;
5+import javax.xml.transform.OutputKeys;
6+import javax.xml.transform.Transformer;
57 import javax.xml.transform.TransformerException;
8+import javax.xml.transform.TransformerFactory;
9+import javax.xml.transform.dom.DOMSource;
10+import javax.xml.transform.stream.StreamResult;
611
712 import org.w3c.dom.*;
813 import org.xml.sax.*;
@@ -369,8 +374,11 @@ public class ConvBusstop {
369374 * @param iCode
370375 * @throws IOException
371376 * @throws SQLException
377+ * @throws TransformerException
378+ * @throws ParserConfigurationException
379+ * @throws SAXException
372380 */
373- public static void outputDb(Connection con, String iCode) throws IOException, SQLException {
381+ public static void outputDb(Connection con, String iCode) throws IOException, SQLException, SAXException, ParserConfigurationException, TransformerException {
374382 SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
375383 String timeStampStr = timeStampFmt.format(new Date(Calendar.getInstance().getTimeInMillis()));
376384 File dir = new File(iCode);
@@ -608,7 +616,7 @@ public class ConvBusstop {
608616 hw.close();
609617 }
610618
611- public static int outputDb(Connection con, File dir) throws IOException, SQLException {
619+ public static int outputDb(Connection con, File dir) throws IOException, SQLException, SAXException, ParserConfigurationException, TransformerException {
612620 File osmFile = new File(dir, "busstop.osm");
613621 int counter = 0;
614622
@@ -651,21 +659,79 @@ public class ConvBusstop {
651659 return counter;
652660 }
653661
654- public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) {
655- String osm_node = ("<node id=\""+ code +"\" timestamp=\""+ timeStampStr +"Z\" lat=\""+ lat +"\" lon=\""+ lon +"\">\n");
656- osm_node += "<tag k=\"name\" v=\""+ name +"\"/>\n";
657- osm_node += "<tag k=\"fixme\" v=\"platform/stop_positionを選択して、正しい位置に移動させてください\"/>\n";
658- osm_node += "<tag k=\"source\" v=\"KSJ2\"/>\n";
659- osm_node += "<tag k=\"source_ref\" v=\"http://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P11.html\"/>\n";
660- osm_node += "<tag k=\"created_by\" v=\"National-Land-Numerical-Information_MLIT_Japan\"/>\n";
661- osm_node += "<tag k=\"note\" v=\"National-Land Numerical Information (Bus stop) 2012, MLIT Japan\"/>\n";
662- osm_node += "<tag k=\"note:ja\" v=\"国土数値情報(バス停留所)平成24年 国土交通省\"/>\n";
663- osm_node += "<tag k=\"public_transport\" v=\"platform\"/>\n";
664- osm_node += "<tag k=\"public_transport\" v=\"stop_position\"/>\n";
665- osm_node += "<tag k=\"highway\" v=\"bus_stop\"/>\n";
666- osm_node += "<tag k=\"bus\" v=\"yes\"/>\n";
667- osm_node += "</node>\n";
668- return osm_node;
662+ public static Element osmTemplateNode = null;
663+
664+ public static String nodeBusstop(int code, String name, Double lat, Double lon, String timeStampStr) throws SAXException, IOException, ParserConfigurationException, TransformerException {
665+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
666+ factory.setIgnoringElementContentWhitespace(true);
667+ factory.setIgnoringComments(true);
668+ factory.setValidating(true);
669+
670+ if (osmTemplateNode == null) {
671+ Document root = factory.newDocumentBuilder().parse(new File("osmTag.xml"));
672+ osmTemplateNode = root.getDocumentElement();
673+ }
674+
675+ Document document = factory.newDocumentBuilder().newDocument(); // Documentの生成
676+ Element node = document.createElement("node");
677+ document.appendChild(node);
678+
679+ node.setAttribute("id", String.valueOf(code));
680+ node.setAttribute("timestamp", timeStampStr + "Z");
681+ node.setAttribute("lat", String.valueOf(lat));
682+ node.setAttribute("lon", String.valueOf(lon));
683+
684+
685+ NodeList nodes = osmTemplateNode.getChildNodes();
686+ for (int i = 0; i < nodes.getLength(); i++) {
687+ Node node2 = nodes.item(i);
688+
689+ if (node2.getNodeName().equals("tag")) {
690+ NamedNodeMap nodeMap2 = node2.getAttributes();
691+ if (null != nodeMap2) {
692+ String key = null;
693+ String value = null;
694+ for (int j=0; j < nodeMap2.getLength(); j++) {
695+ if (nodeMap2.item(j).getNodeName().equals("k")) {
696+ key = nodeMap2.item(j).getNodeValue();
697+ }
698+ else if (nodeMap2.item(j).getNodeName().equals("v")) {
699+ value = nodeMap2.item(j).getNodeValue();
700+ }
701+ }
702+ if ((key != null) && (value != null)) {
703+ Element tag = document.createElement("tag");
704+ tag.setAttribute("k", key);
705+ tag.setAttribute("v", value);
706+ node.appendChild(tag);
707+ }
708+ }
709+ }
710+ else if (node2.getNodeName().equals("ksj")) {
711+ NamedNodeMap nodeMap2 = node2.getAttributes();
712+ if (null != nodeMap2) {
713+ for (int j=0; j < nodeMap2.getLength(); j++) {
714+ if (nodeMap2.item(j).getNodeName().equals("busStopName")) {
715+ Element tagName = document.createElement("tag");
716+ tagName.setAttribute("k", nodeMap2.item(j).getNodeValue());
717+ tagName.setAttribute("v", name);
718+ node.appendChild(tagName);
719+ }
720+ else if (nodeMap2.item(j).getNodeName().equals("busOperationCompany")) {
721+ }
722+ else if (nodeMap2.item(j).getNodeName().equals("busLineName")) {
723+ }
724+ }
725+ }
726+ }
727+ }
728+
729+ StringWriter sw = new StringWriter();
730+ TransformerFactory tfactory = TransformerFactory.newInstance();
731+ Transformer transformer = tfactory.newTransformer();
732+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
733+ transformer.transform(new DOMSource(node), new StreamResult(sw));
734+ return sw.toString();
669735 }
670736
671737 /**
--- /dev/null
+++ b/src/osmTag.xml
@@ -0,0 +1,9 @@
1+<?xml version="1.0" encoding="utf-8" ?>
2+<node>
3+ <ksj busStopName="name" busOperationCompany="operator" busLineName ="network" />
4+ <tag k="highway" v="bus_stop"/>
5+ <tag k="public_transport" v="platform"/>
6+ <tag k="bus" v="yes"/>
7+ <tag k="fixme" v="このバス停を正しい位置に移動させてください"/>
8+ <tag k="source" v="KSJ2 2012"/>
9+</node>
Show on old repository browser