diff --git a/src/osm/jp/api/HttpPOST.java b/src/osm/jp/api/HttpPOST.java index d3636e7..215c00c 100644 --- a/src/osm/jp/api/HttpPOST.java +++ b/src/osm/jp/api/HttpPOST.java @@ -5,7 +5,6 @@ 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; @@ -125,8 +124,9 @@ pw.flush(); } + System.out.println("Sleep 20 sec..."); try { - TimeUnit.SECONDS.sleep(1); + TimeUnit.SECONDS.sleep(20); } catch (InterruptedException e) {} responsecode = urlconn.getResponseCode(); diff --git a/src/osm/jp/api/OsmExist.java b/src/osm/jp/api/OsmExist.java index 1f91186..08df520 100644 --- a/src/osm/jp/api/OsmExist.java +++ b/src/osm/jp/api/OsmExist.java @@ -11,6 +11,7 @@ import org.w3c.dom.Node; public abstract class OsmExist extends Osmdb { + public ArrayList nodelist = new ArrayList<>(); /* public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException { @@ -123,6 +124,7 @@ way.c.d["removed:amenity"="fuel"]; way.c.d["no:amenity"="fuel"]; ); + (._;>;); out meta; ``` */ @@ -151,6 +153,7 @@ point += f.point; } sb.append(");\n"); + sb.append("(._;>;);\n"); sb.append("out body;"); /*-------------------------------------------- @@ -158,9 +161,6 @@ ---------------------------------------------*/ HttpPOST.getQuery(sb.toString()); File xmlFile = new File(HttpPOST.EXIST_FILE); - try { - Thread.sleep(1000); // 5秒 - } catch(InterruptedException e){} /*-------------------------------------------- 受信したXMLファイルをパースする @@ -175,9 +175,17 @@ 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), ""); + nodelist.add(osmnode); + if (osmnode.tags.size() > 0) { + insertExistingNode(hsqldb, osmnode.id, Double.parseDouble(osmnode.latStr), Double.parseDouble(osmnode.lonStr), score(point, osmnode.tags), ""); + } break; case "way": + OsmnodeArea osmway = new OsmnodeArea(itemNodes); + osmway.setPosition(nodelist); + if (osmway.tags.size() > 0) { + insertExistingNode(hsqldb, osmway.id, Double.parseDouble(osmway.latStr), Double.parseDouble(osmway.lonStr), score(point, osmway.tags), ""); + } break; } itemNodes = itemNodes.getNextSibling(); diff --git a/src/osm/jp/api/OsmnodeArea.java b/src/osm/jp/api/OsmnodeArea.java index 631a7d9..07853ac 100644 --- a/src/osm/jp/api/OsmnodeArea.java +++ b/src/osm/jp/api/OsmnodeArea.java @@ -1,38 +1,81 @@ -/* - * 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.Node; /** * OSM.xml の「Area(way)」ノード * 例) *
{@code 
- *  
- *   
- *   
- *   
- *   
- *   
- *   
+ *  
+ *  
+ *  
+ *  
+ *  
  *   
  *   
  *   
  *   
  *   
- * 
+ * 
+ *   
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *   
  * }
* * @author yuu */ -public class OsmnodeArea { - Node areanode = null; +public class OsmnodeArea extends OsmnodeNode { + ArrayList ndList = new ArrayList<>(); public OsmnodeArea(Node node) { - this.areanode = node; + super(node); + + Node ndNode = node.getFirstChild(); + while(ndNode != null) { + String nodeName = ndNode.getNodeName(); + switch (nodeName) { + case "nd": + OsmnodeNd nodeNd = new OsmnodeNd(ndNode); + ndList.add(nodeNd); + break; + } + ndNode = ndNode.getNextSibling(); + } + } + + public void setPosition(ArrayList nodelist) { + int size = 0; + double lat = 0.0D; + double lon = 0.0D; + for (OsmnodeNd nd : ndList) { + OsmnodeNode node1 = getNode(nodelist, nd.ref); + if (node1 != null) { + lat += Double.parseDouble(node1.latStr); + lon += Double.parseDouble(node1.lonStr); + size++; + } + } + lat = lat / size; + lon = lon / size; + this.latStr = String.format("%2.5f", lat); + this.lonStr = String.format("%3.5f", lon); + } + + static OsmnodeNode getNode(ArrayList nodelist, String id) { + for (OsmnodeNode node : nodelist) { + if (node.id.equals(id)) { + return node; + } + } + return null; } } diff --git a/src/osm/jp/api/OsmnodeNode.java b/src/osm/jp/api/OsmnodeNode.java index 12e130b..94a74a5 100644 --- a/src/osm/jp/api/OsmnodeNode.java +++ b/src/osm/jp/api/OsmnodeNode.java @@ -13,6 +13,10 @@ * OSM.xml の「Area(way)」ノード * 例) *
{@code 
+ *  
+ *  
+ *  
+ *  
  *  
  *   
  *   
@@ -20,6 +24,17 @@
  *   
  *   
  * 
+ *   
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *     
+ *   
+ * 
  * }
* * @author yuu @@ -37,8 +52,14 @@ NamedNodeMap attributes = node.getAttributes(); if (attributes != null) { id = attributes.getNamedItem("id").getNodeValue(); - latStr = attributes.getNamedItem("lat").getNodeValue(); - lonStr = attributes.getNamedItem("lon").getNodeValue(); + Node nn = attributes.getNamedItem("lat"); + if (nn != null) { + latStr = nn.getNodeValue(); + } + Node nodeLon = attributes.getNamedItem("lon"); + if (nodeLon != null) { + lonStr = nodeLon.getNodeValue(); + } } Node tagNodes = node.getFirstChild(); diff --git a/test/osm/jp/coverage/OsmExistTest.java b/test/osm/jp/coverage/OsmExistTest.java index 0e62714..2af1e83 100644 --- a/test/osm/jp/coverage/OsmExistTest.java +++ b/test/osm/jp/coverage/OsmExistTest.java @@ -32,28 +32,29 @@ public void test00_main() throws Exception { try { HttpPOST.getQuery("(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;"); + "(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" + + "(._;>;);\n" + + "out body;"); } catch(Exception e) { fail(e.toString());