diff --git a/doc/Japan-BOX.ods b/doc/Japan-BOX.ods new file mode 100644 index 0000000..a8bb863 --- /dev/null +++ b/doc/Japan-BOX.ods Binary files differ diff --git a/doc/overpass.xml b/doc/overpass.xml new file mode 100644 index 0000000..f283cfa --- /dev/null +++ b/doc/overpass.xml @@ -0,0 +1,105 @@ + + +The data included in this document is from www.openstreetmap.org. The data is made available under ODbL. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/osm/jp/api/Feature.java b/src/osm/jp/api/Feature.java new file mode 100644 index 0000000..15c4269 --- /dev/null +++ b/src/osm/jp/api/Feature.java @@ -0,0 +1,18 @@ +package osm.jp.api; + +public class Feature { + public static int NODE = 1; + public static int AREA = 2; + + int node = 0; + String key = null; + String v = null; + int point = 0; + + public Feature(int node, String k, String v, int point) { + this.node = node; + this.key = k; + this.v = v; + this.point = point; + } +} diff --git a/src/osm/jp/api/HttpPOST.java b/src/osm/jp/api/HttpPOST.java index d5406de..dd9e572 100644 --- a/src/osm/jp/api/HttpPOST.java +++ b/src/osm/jp/api/HttpPOST.java @@ -5,20 +5,12 @@ import java.util.Map; import java.util.concurrent.TimeUnit; import java.io.*; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.SQLIntegrityConstraintViolationException; import java.sql.SQLSyntaxErrorException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.hsqldb.HsqlException; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; /** * Java HTTP クライアントサンプル - HttpURLConnection 版 - @@ -30,22 +22,23 @@ //public static String host = "http://api.openstreetmap.org"; public static String host = "http://overpass-api.de"; public static final String EXIST_FILE = "exist.osm.xml"; - public static final String TABLE_NAME = "OSM_EXIST"; + public static final String TABLE_NAME = "OSM_EXIST"; /* + */ public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException { - double minlat = 35.13d; - double maxlat = 35.66d; - double minlon = 138.99d; - double maxlon = 139.79d; + double minlat = 35.00d; + double maxlat = 36.00d; + double minlon = 138.00d; + double maxlon = 140.00d; //getCapabilities(new File("output.xml"), "highway", "bus_stop", minlat, maxlat, minlon, maxlon); //getCapabilities(new File("output.xml"), "highway", "disused:bus_stop", minlat, maxlat, minlon, maxlon); //getCapabilities(new File("output.xml"), "amenity", "bus_station", minlat, maxlat, minlon, maxlon); //getCapabilities(new File("output.xml"), "public_transport", "platform", minlat, maxlat, minlon, maxlon); - getCapabilities("public_transport", "stop_position", minlat, maxlat, minlon, maxlon, "node"); + //getCapabilities("public_transport", "stop_position", minlat, maxlat, minlon, maxlon, "node"); getCapabilities("amenity", "fuel", minlat, maxlat, minlon, maxlon, "way"); + getCapabilities("amenity", "fuel", minlat, maxlat, minlon, maxlon, "node"); } - */ /** * 'HSQLDB.table.OSM_EXIST'を新規に作る @@ -206,15 +199,11 @@ /** * File(HttpPOST.EXIST_FILE)を読み取って、データベースに反映させる。
* その際に、OSMノードを評価し、scoreを算定する - * @param con 反映先のデータベースコネクタ(HSQLDB) - * @param point 評価ポイント[POINT_NO|POINT_BRAND|POINT_NAME] 1: 'brand' 2:'name' - * @throws FileNotFoundException File(HttpPOST.EXIST_FILE)が存在しない - * @throws ClassNotFoundException - * @throws SQLException データベースエラー - * @throws IOException - * @throws ParserConfigurationException - * @throws SAXException + * param con 反映先のデータベースコネクタ(HSQLDB) + * param point 評価ポイント[POINT_NO|POINT_BRAND|POINT_NAME] 1: 'brand' 2:'name' */ + /* + public void readExistingFile (Connection con, int point) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException { DocumentBuilderFactory factory; @@ -232,6 +221,9 @@ int iCounter = readExistingNodes(con, root, point); System.out.println("既存ノード数["+ iCounter +"]"); } + */ + + /* public int readAreaNodes(Connection con, Node node) throws IOException, SQLException { int iCounter = 0; @@ -251,6 +243,9 @@ } return iCounter; } + */ + + /* public void importAreaNode(Connection con, Node node) throws IOException, SQLException { String idrefStr = ""; @@ -290,7 +285,10 @@ } } } + */ + /* + public int readExistingNodes(Connection con, Node node, int point) throws IOException, SQLException { int iCounter = 0; @@ -313,7 +311,10 @@ } return iCounter; } + */ + /* + public void importExistingNode(Connection con, Node node, int point) throws IOException, SQLException { String idrefStr = ""; String latStr = ""; @@ -396,7 +397,9 @@ } } } + */ + /* public void importExistingArea(Connection con, Node node, int point) throws IOException, SQLException { String idrefStr = ""; double maxlat = -90.0D; @@ -487,7 +490,15 @@ } } } - + */ + + /** + * + * @param con + * @param idref + * @return + * @throws SQLException + */ public static Position getNdPosition(Connection con, String idref) throws SQLException { PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM AREA_NODE where idref=?"); ps8.setString(1, idref); @@ -500,4 +511,44 @@ } return null; } + + + public static File overpassAPI(String query) { + StringBuilder sb = new StringBuilder(); + File outputFile = new File("overpassAPI.xml"); + + try { + // https://overpass-api.de/api/interpreter + URL url = new URL("https://overpass-api.de/api/interpreter"); + + HttpURLConnection connection = null; + + try (FileWriter fw = new FileWriter(outputFile);) { + connection = (HttpURLConnection) url.openConnection(); + connection.setDoOutput(true); + connection.setRequestMethod("POST"); + + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8)); + writer.write(query); + writer.flush(); + + if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { + try (InputStreamReader isr = new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8); + BufferedReader reader = new BufferedReader(isr)) { + String line; + while ((line = reader.readLine()) != null) { + fw.append(line); + } + } + } + } finally { + if (connection != null) { + connection.disconnect(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return outputFile; + } } diff --git a/src/osm/jp/api/Japan.java b/src/osm/jp/api/Japan.java index b4a1497..3c25162 100644 --- a/src/osm/jp/api/Japan.java +++ b/src/osm/jp/api/Japan.java @@ -1,10 +1,10 @@ package osm.jp.api; public class Japan { - public double minLat; - public double maxLat; - public double minLon; - public double maxLon; + public double minLat; // 緯度 + public double maxLat; // 緯度 + public double minLon; // 経度 + public double maxLon; // 経度 public static String[] areaArgs = {"全国","北海道","青森県","岩手県","宮城県","秋田県","山形県","福島県","茨城県","栃木県","群馬県","埼玉県","千葉県","東京都","神奈川県","新潟県","富山県","石川県","福井県","山梨県","長野県","岐阜県","静岡県","愛知県","三重県","滋賀県","京都府","大阪府","兵庫県","奈良県","和歌山県","鳥取県","島根県","岡山県","広島県","山口県","徳島県","香川県","愛媛県","高知県","福岡県","佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"}; public static final double ONE_KM_LAT = 0.009013372D; // 1km距離を表す緯度(差分) @@ -189,4 +189,77 @@ new Japan(142D, 27D, 1D), new Japan(142D, 26D, 1D) }; + + public static Japan[] all2 = new Japan[] { + new Japan(122D, 24D, 2D), + new Japan(124D, 24D, 2D), + new Japan(126D, 26D, 2D), + new Japan(128D, 26D, 2D), + new Japan(128D, 28D, 2D), + new Japan(128D, 30D, 2D), + new Japan(128D, 32D, 2D), + new Japan(128D, 34D, 2D), + new Japan(130D, 30D, 2D), + new Japan(130D, 32D, 2D), + new Japan(130D, 34D, 2D), + new Japan(132D, 32D, 2D), + new Japan(132D, 34D, 2D), + new Japan(132D, 36D, 2D), + new Japan(134D, 32D, 2D), + new Japan(134D, 34D, 2D), + new Japan(134D, 36D, 2D), + new Japan(136D, 32D, 2D), + new Japan(136D, 34D, 2D), + new Japan(136D, 36D, 2D), + new Japan(138D, 32D, 2D), + new Japan(138D, 34D, 2D), + new Japan(138D, 36D, 2D), + new Japan(138D, 38D, 2D), + new Japan(138D, 40D, 2D), + new Japan(138D, 42D, 2D), + new Japan(140D, 34D, 2D), + new Japan(140D, 36D, 2D), + new Japan(140D, 38D, 2D), + new Japan(140D, 40D, 2D), + new Japan(140D, 42D, 2D), + new Japan(140D, 44D, 2D), + new Japan(142D, 38D, 2D), + new Japan(142D, 42D, 2D), + new Japan(142D, 44D, 2D), + new Japan(144D, 42D, 2D), + new Japan(144D, 44D, 2D), + + // 小笠原諸島 + new Japan(142D, 26D, 2D) + }; + + + public static Japan[] all3 = new Japan[] { + new Japan(123D, 22D, 3D), + new Japan(123D, 25D, 3D), + new Japan(126D, 25D, 3D), + new Japan(126D, 28D, 3D), + new Japan(126D, 31D, 3D), + new Japan(129D, 25D, 3D), + new Japan(129D, 28D, 3D), + new Japan(129D, 31D, 3D), + new Japan(129D, 34D, 3D), + new Japan(132D, 31D, 3D), + new Japan(132D, 34D, 3D), + new Japan(135D, 31D, 3D), + new Japan(135D, 34D, 3D), + new Japan(135D, 37D, 3D), + new Japan(138D, 31D, 3D), + new Japan(138D, 34D, 3D), + new Japan(138D, 37D, 3D), + new Japan(138D, 40D, 3D), + new Japan(138D, 43D, 3D), + new Japan(141D, 37D, 3D), + new Japan(141D, 40D, 3D), + new Japan(141D, 43D, 3D), + new Japan(144D, 43D, 3D), + + // 小笠原諸島 + new Japan(141D, 25D, 3D) + }; } diff --git a/src/osm/jp/api/OsmExist.java b/src/osm/jp/api/OsmExist.java new file mode 100644 index 0000000..14c7395 --- /dev/null +++ b/src/osm/jp/api/OsmExist.java @@ -0,0 +1,233 @@ +package osm.jp.api; + +import java.io.*; +import java.sql.Connection; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public abstract class OsmExist extends Osmdb { + + /* + public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException { + double minlat = 35.13d; + double maxlat = 35.66d; + double minlon = 138.99d; + double maxlon = 139.79d; + //getCapabilities(new File("output.xml"), "highway", "bus_stop", minlat, maxlat, minlon, maxlon); + //getCapabilities(new File("output.xml"), "highway", "disused:bus_stop", minlat, maxlat, minlon, maxlon); + //getCapabilities(new File("output.xml"), "amenity", "bus_station", minlat, maxlat, minlon, maxlon); + //getCapabilities(new File("output.xml"), "public_transport", "platform", minlat, maxlat, minlon, maxlon); + getCapabilities("public_transport", "stop_position", minlat, maxlat, minlon, maxlon, "node"); + getCapabilities("amenity", "fuel", minlat, maxlat, minlon, maxlon, "way"); + } + */ + + /* + Test data: + ノード: エネオス (2015835273) 場所: 35.4367770, 139.403571TABLE_NAME0 + ノード: ENEOS (1769261234) 場所: 35.4330583, 139.4006876 brand=no + ノード: 出光 (3877535257) 場所: 45.3985390, 141.6882450 brand=no + + select osm_id,amenity,brand,disused,name, + ST_Y(ST_Transform(way,4326)) as lat, + ST_X(ST_Transform(way,4326)) as lon + from planet_osm_point + where amenity='fuel'; + + + ウェイ: 出光 (161877397) ノード + 1738352013 + 1738351984 + 1738352019 + 1738352024 + 1738352017 + 1738352013 + select osm_id,amenity,brand,name,way_area, + ST_Astext(ST_Transform(way,4326)) , + ST_Y(ST_Transform(ST_Centroid(way),4326)) as lat, + ST_X(ST_Transform(ST_Centroid(way),4326)) as lon + from planet_osm_polygon + where amenity='fuel'; + + 161877397;"fuel";"出光";"出光";1415.14;"POLYGON((139.402982078119 35.4372453832977,139.403208992559 35.4373490207424,139.4033330499 35.4371591650393,139.403407160911 35.4370741177365,139.403148446109 35.4369273706731,139.402982078119 35.4372453832977))" + ST_Centroid(way) + + */ + /** + * + *
{@code 
+     *  (
+     *    node[disused:amenity=fuel](35.42,139.39,35.45,139.42);
+     *    way[amenity=fuel](35.42,139.39,35.45,139.42);
+     *    node[amenity=fuel](35.42,139.39,35.45,139.42);
+     *    (way[amenity=fuel](35.42,139.39,35.45,139.42);>;);
+     *  );
+     *  out;
+     * }
+ * + *
{@code 
+     *  select osm_id,amenity,brand,disused,name from planet_osm_point where amenity='fuel';
+     * }
+ * + *
{@code 
+     *  select osm_id,amenity,brand,name,way_area,ST_Astext(ST_Transform(way,4326)) from planet_osm_polygon where amenity='fuel';
+     * 
+     * 168977587;"fuel";"JA";"兼城SS";1378;"POLYGON((127.692529751123 26.1483225993078,127.692852156479 26.1482644594179,127.692800683013 26.1478020809547,127.692690280065 26.1478324815483,127.692623984397 26.1480452048431,127.692529751123 26.1483225993078))"
+     * 
+     * 
+     *  select id,nodes,tags from planet_osm_ways;
+     * }
+ * + * @param hsqldb + * @param osmdb + * @param features + * @return XML + * @throws Exception + */ + /** + * File(HttpPOST.EXIST_FILE)を読み取って、データベースに反映させる。
+ * その際に、OSMノードを評価し、scoreを算定する + * + * @param hsqldb + * @param features + * @throws Exception + */ + public void getJapanCapabilities(Connection hsqldb, ArrayList features) throws Exception { + + /* + ``` + (node(changed:"2018-05-20T09:00:00Z")(34.0,138.0,36.0,140.0);)->.a; + (node(newer:"2018-05-20T09:00:00Z")(34.0,138.0,36.0,140.0);)->.b; + (way(changed:"2018-05-20T09:00:00Z")(34.0,138.0,36.0,140.0);)->.c; + (way(newer:"2018-05-20T09:00:00Z")(34.0,138.0,36.0,140.0);)->.d; + ( + node.a.b["amenity"="fuel"]; + node.a.b["disused:amenity"="fuel"]; + node.a.b["abandoned:amenity"="fuel"]; + node.a.b["demolished:amenity"="fuel"]; + node.a.b["historic:amenity"="fuel"]; + node.a.b["was:amenity"="fuel"]; + node.a.b["removed:amenity"="fuel"]; + node.a.b["no:amenity"="fuel"]; + way.c.d["amenity"="fuel"]; + way.c.d["disused:amenity"="fuel"]; + way.c.d["abandoned:amenity"="fuel"]; + way.c.d["demolished:amenity"="fuel"]; + way.c.d["historic:amenity"="fuel"]; + way.c.d["was:amenity"="fuel"]; + way.c.d["removed:amenity"="fuel"]; + way.c.d["no:amenity"="fuel"]; + ); + out meta; + ``` + */ + Calendar now = Calendar.getInstance(); + now.add(Calendar.DATE, -7); // before 1 week + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String startDate = sdf.format(now.getTime()) +"T09:00:00Z"; + + StringBuilder sb = new StringBuilder(); + for (Japan box : Japan.all2) { + String boxq = String.format("(%d,%d,%d,%d)", box.minLat, box.minLon, box.maxLat, box.maxLon); + sb.append(String.format("(node(changed:\"%s\")%s;)->.a;\n", startDate, boxq)); + sb.append(String.format("(node(newer:\"%s\")%s;)->.b;\n", startDate, boxq)); + sb.append(String.format("(way(changed:\"%s\")%s;)->.c;\n", startDate, boxq)); + sb.append(String.format("(way(newer:\"%s\")%s;)->.d;\n", startDate, boxq)); + sb.append("("); + int point = 0; + for (Feature f : features) { + if (f.node == Feature.NODE) { + sb.append("node.a.b"); + } + else if (f.node == Feature.AREA) { + sb.append("way.c.d"); + } + sb.append(String.format("[\"%s\"=\"%s\"]\n", f.key, f.v)); + point += f.point; + } + sb.append(");\n"); + sb.append("out body;"); + + /*-------------------------------------------- + Overpass API を実行して XMLを受信する + ---------------------------------------------*/ + File xmlFile = HttpPOST.overpassAPI(sb.toString()); + + + /*-------------------------------------------- + 受信したXMLファイルをパースする + ---------------------------------------------*/ + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Document document = documentBuilder.parse(xmlFile); + Node osmNode = document.getDocumentElement(); + Node itemNodes = osmNode.getFirstChild(); + while(itemNodes != null) { + String nodeName = itemNodes.getNodeName(); + switch (nodeName) { + case "node": + OsmnodeNode osmnode = new OsmnodeNode(itemNodes); + insertExistingNode(hsqldb, osmnode.id, Double.parseDouble(osmnode.latStr), Double.parseDouble(osmnode.lonStr), score(point, osmnode.tags), ""); + break; + case "way": + break; + } + itemNodes = itemNodes.getNextSibling(); + } + } + + } + + /** + * + * @param point + * @param tags + * @return + */ + int score(int point, ArrayList tags) { + int score = 50; + if (tags == null) { + return 0; + } + + boolean brandYes = false; + boolean busYes = false; + boolean fixmeYes = false; + boolean nameYes = false; + for (OsmnodeTag tag : tags) { + if (tag.key.startsWith("fixme")) { + fixmeYes = true; + } + else if (tag.key.equals("bus")) { + if (tag.value.equals("yes")) { + busYes = true; + } + } + else if (tag.key.equals("brand")) { + brandYes = true; + } + else if (tag.key.startsWith("name")) { + nameYes = true; + } + } + + if (((point & POINT_NO_BRAND) != 0) && !brandYes) { + score = 1; + } + if (((point & POINT_NO_NAME) != 0) && !nameYes) { + score = 1; + } + if (((point & POINT_FIXME) != 0) && fixmeYes) { + score = 1; + } + if (((point & POINT_BUS_NO) != 0) && !busYes) { + score = 0; + } + return score; + } +} diff --git a/src/osm/jp/api/Osmdb.java b/src/osm/jp/api/Osmdb.java index 2b976a0..9961cdb 100644 --- a/src/osm/jp/api/Osmdb.java +++ b/src/osm/jp/api/Osmdb.java @@ -454,6 +454,8 @@ + /* + void importExistingArea(Connection con, Node node, int point) throws IOException, SQLException { String idrefStr = ""; double maxlat = -90.0D; @@ -544,6 +546,7 @@ } } } + */ static Position getNdPosition(Connection con, String idref) throws SQLException { PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM AREA_NODE where idref=?"); diff --git a/src/osm/jp/api/OsmnodeNode.java b/src/osm/jp/api/OsmnodeNode.java new file mode 100644 index 0000000..12e130b --- /dev/null +++ b/src/osm/jp/api/OsmnodeNode.java @@ -0,0 +1,66 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package osm.jp.api; + +import java.util.ArrayList; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * OSM.xml の「Area(way)」ノード + * 例) + *
{@code 
+ *  
+ *   
+ *   
+ *   
+ *   
+ *   
+ * 
+ * }
+ * + * @author yuu + */ +public class OsmnodeNode { + Node node = null; + String id = null; + String latStr = null; + String lonStr = null; + ArrayList tags = new ArrayList<>(); + + public OsmnodeNode(Node node) { + this.node = node; + + NamedNodeMap attributes = node.getAttributes(); + if (attributes != null) { + id = attributes.getNamedItem("id").getNodeValue(); + latStr = attributes.getNamedItem("lat").getNodeValue(); + lonStr = attributes.getNamedItem("lon").getNodeValue(); + } + + Node tagNodes = node.getFirstChild(); + while(tagNodes != null) { + String nodeName = tagNodes.getNodeName(); + switch (nodeName) { + case "tag": + OsmnodeTag nodetag = new OsmnodeTag(tagNodes); + tags.add(nodetag); + break; + } + tagNodes = tagNodes.getNextSibling(); + } + } + + public String getValue(String key) { + for (OsmnodeTag tag : tags) { + if (tag.key.equals(key)) { + return tag.value; + } + } + return null; + } + +} diff --git a/src/osm/jp/api/OsmnodeTag.java b/src/osm/jp/api/OsmnodeTag.java index 526d5cb..3d0f24b 100644 --- a/src/osm/jp/api/OsmnodeTag.java +++ b/src/osm/jp/api/OsmnodeTag.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package osm.jp.api; import org.w3c.dom.NamedNodeMap; @@ -21,38 +16,27 @@ * * @author yuu */ -public class OsmnodeTag { +public class OsmnodeTag +{ Node tagnode = null; + String key = null; + String value = null; public OsmnodeTag(Node node) { + this.tagnode = node; + + NamedNodeMap nodeMap2 = this.tagnode.getAttributes(); + if (null != nodeMap2) { + for (int j=0; j < nodeMap2.getLength(); j++) { + if (nodeMap2.item(j).getNodeName().equals("k")) { + this.key = nodeMap2.item(j).getNodeValue(); + } + else if (nodeMap2.item(j).getNodeName().equals("v")) { + this.value = nodeMap2.item(j).getNodeValue(); + } + } + } } - /** - * - * @param k keyは大文字小文字を区別しません。小文字で指定すること - * @return - */ - public String getValue(String k) { - NamedNodeMap nodeMap2 = this.tagnode.getAttributes(); - if (null == nodeMap2) { - return null; - } - - 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(k)) { - return value; - } - return null; - } } diff --git a/src/osm/jp/coverage/fuel/OsmExist.java b/src/osm/jp/coverage/fuel/OsmExist.java new file mode 100644 index 0000000..a66e1b2 --- /dev/null +++ b/src/osm/jp/coverage/fuel/OsmExist.java @@ -0,0 +1,54 @@ +package osm.jp.coverage.fuel; + +import java.sql.Connection; +import java.util.ArrayList; +import jp.co.areaweb.tools.database.*; +import osm.jp.api.Feature; + +public class OsmExist extends osm.jp.api.OsmExist { + + /** メイン + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception + { + Connection hsqldb = null; + try { + // DB.tableを作成 + hsqldb = DatabaseTool.openDb("database"); + + ArrayList features = new ArrayList<>(); + features.add(new Feature(Feature.NODE, "amenity", "fuel", POINT_NO_BRAND | POINT_FIXME)); + features.add(new Feature(Feature.NODE, "disused:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "abandoned:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "demolished:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "historic:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "was:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "removed:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.NODE, "no:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "amenity", "fuel", POINT_NO_BRAND | POINT_FIXME)); + features.add(new Feature(Feature.AREA, "disused:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "abandoned:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "demolished:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "historic:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "was:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "removed:amenity", "fuel", POINT_NO)); + features.add(new Feature(Feature.AREA, "no:amenity", "fuel", POINT_NO)); + + /** + * 既存のOSMガソリンスタンドを読み込む + * OSM OverPassAPI を使って、既存のGSデータを取得して、「HSQLDB.FUEL_EXIST」にSTOREする + */ + (new OsmExist()).getJapanCapabilities(hsqldb, features); + + OsmExist.export(hsqldb); + } + finally { + if (hsqldb != null) { + DatabaseTool.closeDb(hsqldb); + } + } + } + +} \ No newline at end of file diff --git a/test/osm/jp/coverage/OsmExistTest.java b/test/osm/jp/coverage/OsmExistTest.java new file mode 100644 index 0000000..8c7f184 --- /dev/null +++ b/test/osm/jp/coverage/OsmExistTest.java @@ -0,0 +1,61 @@ +package osm.jp.coverage; + +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import osm.jp.api.HttpPOST; + +public class OsmExistTest { + + @BeforeClass + public static void setUpClass() throws Exception { + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void test00_main() throws Exception { + try { + HttpPOST.overpassAPI("(node(changed:\"2018-05-20T09:00:00Z\")(34.0,138.0,36.0,140.0);)->.a;\n" + +"(node(newer:\"2018-05-20T09:00:00Z\")(34.0,138.0,36.0,140.0);)->.b;\n" + +"(way(changed:\"2018-05-20T09:00:00Z\")(34.0,138.0,36.0,140.0);)->.c;\n" + +"(way(newer:\"2018-05-20T09:00:00Z\")(34.0,138.0,36.0,140.0);)->.d;\n" + +"(\n" + +" node.a.b[\"amenity\"=\"fuel\"];\n" + +" node.a.b[\"disused:amenity\"=\"fuel\"];\n" + +" node.a.b[\"abandoned:amenity\"=\"fuel\"];\n" + +" node.a.b[\"demolished:amenity\"=\"fuel\"];\n" + +" node.a.b[\"historic:amenity\"=\"fuel\"];\n" + +" node.a.b[\"was:amenity\"=\"fuel\"];\n" + +" node.a.b[\"removed:amenity\"=\"fuel\"];\n" + +" node.a.b[\"no:amenity\"=\"fuel\"];\n" + +" way.c.d[\"amenity\"=\"fuel\"];\n" + +" way.c.d[\"disused:amenity\"=\"fuel\"];\n" + +" way.c.d[\"abandoned:amenity\"=\"fuel\"];\n" + +" way.c.d[\"demolished:amenity\"=\"fuel\"];\n" + +" way.c.d[\"historic:amenity\"=\"fuel\"];\n" + +" way.c.d[\"was:amenity\"=\"fuel\"];\n" + +" way.c.d[\"removed:amenity\"=\"fuel\"];\n" + +" way.c.d[\"no:amenity\"=\"fuel\"];\n" + +");\n" + +"out meta;"); + } + catch(Exception e) { + fail(e.toString()); + } + } + +} \ No newline at end of file diff --git a/test/osm/jp/coverage/Test.java b/test/osm/jp/coverage/Test.java index e9fa003..acd2ca7 100644 --- a/test/osm/jp/coverage/Test.java +++ b/test/osm/jp/coverage/Test.java @@ -56,6 +56,7 @@ DatabaseTool.closeDb(con); } } + /** * 個別の都道府県「GMLディレクトリ」を処理