diff --git a/doc/fuel.activity.violet.html b/doc/fuel.activity.violet.html
new file mode 100644
index 0000000..001d89b
--- /dev/null
+++ b/doc/fuel.activity.violet.html
@@ -0,0 +1,268 @@
+
+
+
+
+
+
+
+
+ This file was generated with Violet UML Editor 2.1.0.
+ ( View Source / Download Violet )
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/osm/jp/api/Japan.java b/src/osm/jp/api/Japan.java
index 3127b41..6a45297 100644
--- a/src/osm/jp/api/Japan.java
+++ b/src/osm/jp/api/Japan.java
@@ -1,22 +1,157 @@
package osm.jp.api;
public class Japan {
- public double minLat;
- public double maxLat;
- public double minLon;
- public double maxLon;
-
- public Japan(double minLat, double maxLat, double minLon, double maxLon) {
- this.minLat = minLat;
- this.maxLat = maxLat;
- this.minLon = minLon;
- this.maxLon = maxLon;
- }
+ public double minLat;
+ public double maxLat;
+ public double minLon;
+ public double maxLon;
- public Japan(double minLat, double minLon, double delta) {
- this.minLat = minLat;
- this.maxLat = minLat + delta;
- this.minLon = minLon;
- this.maxLon = minLon + delta;
- }
+ public Japan(double minLat, double maxLat, double minLon, double maxLon) {
+ this.minLat = minLat;
+ this.maxLat = maxLat;
+ this.minLon = minLon;
+ this.maxLon = maxLon;
+ }
+
+ public Japan(double minLat, double minLon, double delta) {
+ this.minLat = minLat;
+ this.maxLat = minLat + delta;
+ this.minLon = minLon;
+ this.maxLon = minLon + delta;
+ }
+
+ public static Japan[] all = new Japan[] {
+ new Japan(140D, 45D, 1D),
+ new Japan(141D, 45D, 1D),
+ new Japan(142D, 45D, 1D),
+
+ new Japan(140D, 44D, 1D),
+ new Japan(141D, 44D, 1D),
+ new Japan(142D, 44D, 1D),
+ new Japan(143D, 44D, 1D),
+ new Japan(144D, 44D, 1D),
+ new Japan(145D, 44D, 1D),
+
+ new Japan(140D, 43D, 1D),
+ new Japan(141D, 43D, 1D),
+ new Japan(142D, 43D, 1D),
+ new Japan(143D, 43D, 1D),
+ new Japan(144D, 43D, 1D),
+ new Japan(145D, 43D, 1D),
+
+ new Japan(139D, 42D, 1D),
+ new Japan(140D, 42D, 1D),
+ new Japan(141D, 42D, 1D),
+ new Japan(142D, 42D, 1D),
+ new Japan(143D, 42D, 1D),
+ new Japan(144D, 42D, 1D),
+ new Japan(145D, 42D, 1D),
+
+ new Japan(139D, 41D, 1D),
+ new Japan(140D, 41D, 1D),
+ new Japan(141D, 41D, 1D),
+
+ new Japan(139D, 40D, 1D),
+ new Japan(140D, 40D, 1D),
+ new Japan(141D, 40D, 1D),
+
+ new Japan(139D, 39D, 1D),
+ new Japan(140D, 39D, 1D),
+ new Japan(141D, 39D, 1D),
+ new Japan(142D, 39D, 1D),
+
+ new Japan(138D, 38D, 1D),
+ new Japan(139D, 38D, 1D),
+ new Japan(140D, 38D, 1D),
+ new Japan(141D, 38D, 1D),
+
+ new Japan(136D, 37D, 1D),
+ new Japan(137D, 37D, 1D),
+ new Japan(138D, 37D, 1D),
+ new Japan(139D, 37D, 1D),
+ new Japan(140D, 37D, 1D),
+ new Japan(141D, 37D, 1D),
+
+ new Japan(132D, 36D, 1D),
+ new Japan(133D, 36D, 1D),
+ new Japan(135D, 36D, 1D),
+ new Japan(136D, 36D, 1D),
+ new Japan(137D, 36D, 1D),
+ new Japan(138D, 36D, 1D),
+ new Japan(139D, 36D, 1D),
+ new Japan(140D, 36D, 1D),
+
+ new Japan(132D, 35D, 1D),
+ new Japan(133D, 35D, 1D),
+ new Japan(134D, 35D, 1D),
+ new Japan(135D, 35D, 1D),
+ new Japan(136D, 35D, 1D),
+ new Japan(137D, 35D, 1D),
+ new Japan(138D, 35D, 1D),
+ new Japan(139D, 35D, 1D),
+ new Japan(140D, 35D, 1D),
+
+ new Japan(129D, 34D, 1D),
+ new Japan(130D, 34D, 1D),
+ new Japan(131D, 34D, 1D),
+ new Japan(132D, 34D, 1D),
+ new Japan(133D, 34D, 1D),
+ new Japan(134D, 34D, 1D),
+ new Japan(135D, 34D, 1D),
+ new Japan(136D, 34D, 1D),
+ new Japan(137D, 34D, 1D),
+ new Japan(138D, 34D, 1D),
+ new Japan(139D, 34D, 1D),
+
+ new Japan(129D, 33D, 1D),
+ new Japan(130D, 33D, 1D),
+ new Japan(131D, 33D, 1D),
+ new Japan(132D, 33D, 1D),
+ new Japan(133D, 33D, 1D),
+ new Japan(134D, 33D, 1D),
+ new Japan(135D, 33D, 1D),
+ new Japan(136D, 33D, 1D),
+ new Japan(139D, 33D, 1D),
+
+ new Japan(128D, 32D, 1D),
+ new Japan(129D, 32D, 1D),
+ new Japan(130D, 32D, 1D),
+ new Japan(131D, 32D, 1D),
+ new Japan(132D, 32D, 1D),
+ new Japan(133D, 32D, 1D),
+ new Japan(139D, 32D, 1D),
+
+ new Japan(129D, 31D, 1D),
+ new Japan(130D, 31D, 1D),
+ new Japan(131D, 31D, 1D),
+
+ new Japan(129D, 30D, 1D),
+ new Japan(130D, 30D, 1D),
+ new Japan(131D, 30D, 1D),
+
+ new Japan(128D, 29D, 1D),
+ new Japan(129D, 29D, 1D),
+
+ new Japan(128D, 28D, 1D),
+ new Japan(129D, 28D, 1D),
+
+ new Japan(127D, 27D, 1D),
+ new Japan(128D, 27D, 1D),
+ new Japan(129D, 27D, 1D),
+
+ new Japan(126D, 26D, 1D),
+ new Japan(127D, 26D, 1D),
+ new Japan(128D, 26D, 1D),
+ new Japan(129D, 26D, 1D),
+
+ new Japan(125D, 25D, 1D),
+
+ new Japan(123D, 24D, 1D),
+ new Japan(124D, 24D, 1D),
+ new Japan(125D, 24D, 1D),
+
+ // 小笠原諸島
+ new Japan(142D, 27D, 1D),
+ new Japan(142D, 26D, 1D)
+ };
}
diff --git a/src/osm/jp/coverage/fuel/DbExist.java b/src/osm/jp/coverage/fuel/DbExist.java
index 862618f..3e71d8c 100644
--- a/src/osm/jp/coverage/fuel/DbExist.java
+++ b/src/osm/jp/coverage/fuel/DbExist.java
@@ -1,6 +1,8 @@
package osm.jp.coverage.fuel;
import java.io.*;
+import java.net.MalformedURLException;
+import java.net.ProtocolException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -15,6 +17,8 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import osm.jp.api.Db;
+import osm.jp.api.HttpPOST;
+import osm.jp.api.Japan;
public class DbExist {
public static final String TABLE_NAME = "FUEL_EXIST";
@@ -35,15 +39,12 @@
con = DatabaseTool.openDb("database");
create(con);
- //
- File gmlDir = new File("GML_FUEL");
- for (File gmlFile : gmlDir.listFiles()) {
- if (checkGMLfile(gmlFile)) {
- int index = "P07-15_".length();
- int areacode = Integer.parseInt(gmlFile.getName().substring(index, index+2));
- inputFile(con, gmlFile, areacode);
- }
- }
+ /**
+ * 既存のOSMガソリンスタンドを読み込む
+ * OSM OverPassAPI を使って、既存のGSデータを取得して、「HSQLDB.FUEL_EXIST」にSTOREする
+ */
+ getJapanCapabilities(con);
+
DbExist.export(con);
}
@@ -55,144 +56,135 @@
}
/**
- * 数値地図情報のGMLデータファイルを読み取ってローカルベータベースへ記録する
+ *
* @param con
- * @param iFile
- * @param areacode
- * @throws FileNotFoundException
+ * @param oFile
+ * @throws MalformedURLException
+ * @throws ProtocolException
+ * @throws IOException
* @throws ClassNotFoundException
* @throws SQLException
- * @throws IOException
- * @throws ParserConfigurationException
- * @throws SAXException
+ * @throws ParserConfigurationException
+ * @throws SAXException
*/
- public static void inputFile (Connection con, File iFile, int areacode) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
+ public static void getJapanCapabilities(Connection con) throws MalformedURLException, ProtocolException, IOException, ClassNotFoundException, SQLException, ParserConfigurationException, SAXException {
+ for (Japan area : Japan.all) {
+ File existingFile = new File("existing.xml");
+ HttpPOST.getCapabilities(existingFile, "amenity", "fuel", area.minLat, area.maxLat, area.minLon, area.maxLon);
+ readExistingFile(con, existingFile);
+ }
+ }
+
+ public static void readExistingFile (Connection con, File existingFile) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
+ int iCounter = 0;
+
DocumentBuilderFactory factory;
DocumentBuilder builder;
+ Node root;
+ iCounter = 0;
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
factory.setValidating(true);
-
- // Root node -->
- Node root = builder.parse(iFile);
- NodeList nodes = root.getChildNodes();
- for (int i=0; i < nodes.getLength(); i++) {
- Node nodePoint = nodes.item(i);
- if (nodePoint.getNodeName().equals("ksj:Dataset")) {
- int iCounter = showNodes(con, nodePoint, areacode);
- System.out.println("("+ areacode +") データ数["+ iCounter +"]");
- }
- }
+ root = builder.parse(existingFile);
+ iCounter += readExistingNodes(con, root);
+ System.out.println("既存ノード数["+ iCounter +"]");
}
- /**
- * node :
- *
- *
- * 43.03442215 141.47026381
- *
- *
- *
- * @param con
- * @param node
- * @param areacode
- * @return
- * @throws IOException
- * @throws SQLException
- */
- public static int showNodes(Connection con, Node node, int areacode) throws IOException, SQLException {
+ static int readExistingNodes(Connection con, Node node) throws IOException, SQLException {
int iCounter = 0;
-
- // Root node :
- // Child node : 43.03442215 141.47026381
- //
+
NodeList nodes = node.getChildNodes();
- for (int i=0; i < nodes.getLength(); i++) {
- Node nodePoint = nodes.item(i);
- switch (nodePoint.getNodeName()) {
- case "gml:Point":
- iCounter++;
- showGmPoint(con, nodePoint, areacode);
- break;
- default:
- System.out.println(nodePoint.getNodeName());
- break;
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node2 = nodes.item(i);
+ if (node2.getNodeName().equals("node")) {
+ iCounter++;
+ importExistingNode(con, node2);
+ }
+ else {
+ iCounter += readExistingNodes(con, node2);
}
}
return iCounter;
}
-
- /**
- * node :
- *
- * 43.03442215 141.47026381
- *
- *
- * @param con
- * @param node
- * @throws IOException
- * @throws SQLException
- */
- public static void showGmPoint(Connection con, Node node, int areacode) throws IOException, SQLException {
+
+ static void importExistingNode(Connection con, Node node) throws IOException, SQLException {
+ String idrefStr = "";
String latStr = "";
String lonStr = "";
- String idStr = "";
+ String brandStr = "";
+ String fixmeStr = "";
+ int score = 0;
- NamedNodeMap attrMap = node.getAttributes();
- if (null != attrMap ) {
- for (int j=0; j < attrMap.getLength(); j++) {
- if (attrMap.item(j).getNodeName().equals("gml:id")) {
- idStr = attrMap.item(j).getNodeValue();
+ NamedNodeMap nodeMap = node.getAttributes();
+ if (nodeMap != null) {
+ for (int j=0; j < nodeMap.getLength(); j++) {
+ switch (nodeMap.item(j).getNodeName()) {
+ case "id":
+ idrefStr = nodeMap.item(j).getNodeValue();
+ break;
+ case "lat":
+ latStr = nodeMap.item(j).getNodeValue();
+ break;
+ case "lon":
+ lonStr = nodeMap.item(j).getNodeValue();
+ break;
+ default:
+ break;
}
}
- }
- NodeList nodes = node.getChildNodes();
- for (int i=0; i < nodes.getLength(); i++) {
- Node node2 = nodes.item(i);
- if (node2.getNodeName().equals("gml:pos")) {
- String positionStr = node2.getTextContent();
- String[] str4Ary = positionStr.split(" ");
- latStr = str4Ary[0];
- lonStr = str4Ary[1];
- break;
+ NodeList nodes = node.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node node2 = nodes.item(i);
+ if (node2.getNodeName().equals("tag")) {
+ NamedNodeMap nodeMap2 = node2.getAttributes();
+ if (null != nodeMap2) {
+ String key = null;
+ String value = null;
+ for (int j=0; j < nodeMap2.getLength(); j++) {
+ if (nodeMap2.item(j).getNodeName().equals("k")) {
+ key = nodeMap2.item(j).getNodeValue();
+ }
+ else if (nodeMap2.item(j).getNodeName().equals("v")) {
+ value = nodeMap2.item(j).getNodeValue();
+ }
+ }
+
+ if ((key != null) && key.toLowerCase().equals("brand") && (value != null)) {
+ brandStr = value;
+ }
+ if ((key != null) && key.toLowerCase().equals("fixme") && (value != null)) {
+ fixmeStr = value;
+ }
+ }
+ }
}
- }
-
- try (PreparedStatement ps = con.prepareStatement("INSERT INTO "+ TABLE_NAME +"(lat,lon,fixed,idref,area) VALUES(?,?,?,?,?)")) {
- double lat = Double.parseDouble(latStr);
- double lon = Double.parseDouble(lonStr);
- ps.setDouble(1, lat);
- ps.setDouble(2, lon);
- ps.setInt(3, 0);
- ps.setString(4, idStr);
- ps.setInt(5, areacode);
- System.out.println("INSERT "+ TABLE_NAME +"("+ idStr +", lat="+ lat +", lon="+ lon +", fixed=0, area="+ areacode +")");
- ps.executeUpdate();
+
+ score = 50;
+ if (brandStr.equals("")) {
+ score = 1;
+ }
+ if (!fixmeStr.equals("")) {
+ score = 1;
+ }
+
+ // idref と nameStr をデータベースに格納する
+ System.out.println("import existing_data : "+ idrefStr +" ("+ latStr +","+ lonStr+")["+ Integer.toString(score) +"]"+ brandStr);
+ try (PreparedStatement ps5 = con.prepareStatement("INSERT INTO "+ TABLE_NAME +" (idref,lat,lon, score) VALUES (?,?,?,?)")) {
+ ps5.setString(1, idrefStr);
+ ps5.setDouble(2, Double.parseDouble(latStr));
+ ps5.setDouble(3, Double.parseDouble(lonStr));
+ ps5.setInt(4, score);
+ ps5.executeUpdate();
+ }
}
}
/**
- * 数値地図情報のデータファイルかどうかを見極める
- * @param f
- * @return
- */
- public static boolean checkGMLfile(File f) {
- if (f.isDirectory()) {
- return false;
- }
- String name = f.getName();
- if (!name.startsWith("P07")) {
- return false;
- }
- return name.toUpperCase().endsWith(".XML");
- }
-
- /**
* 'table.FUEL_EXIST'を新規に作る
* 既にテーブルが存在する時には何もしない
* @param con
@@ -202,7 +194,9 @@
String createSt;
// 'table.FUEL_EXIST'を新規に作る
- createSt = "CREATE TABLE "+ TABLE_NAME +" (idref VARCHAR(12) NOT NULL, lat DOUBLE, lon DOUBLE, score INT PRIMARY KEY(lat, lon));";
+ createSt = "CREATE TABLE "+ TABLE_NAME +" (idref VARCHAR(12) NOT NULL, lat DOUBLE, lon DOUBLE, score INT, PRIMARY KEY(idref));";
+ Db.updateSQL(con, createSt);
+ createSt = "CREATE INDEX "+ TABLE_NAME +"_index ON "+ TABLE_NAME +" (lat, lon);";
Db.updateSQL(con, createSt);
/*
@@ -224,11 +218,11 @@
PreparedStatement ps8 = con.prepareStatement("SELECT idref,lat,lon,score FROM "+ TABLE_NAME);
try (ResultSet rset8 = ps8.executeQuery()) {
while (rset8.next()) {
- String name = rset8.getString(1);
+ String idcode = rset8.getString(1);
Double lat = rset8.getDouble(2);
Double lon = rset8.getDouble(3);
int score = rset8.getInt(4);
- System.out.println(name +","+ lat +","+ lon +","+ score);
+ System.out.println("OSM: "+ idcode +","+ lat +","+ lon +","+ score);
}
}
}