diff --git a/build.xml b/build.xml index 42a8bb9..29c8232 100644 --- a/build.xml +++ b/build.xml @@ -14,7 +14,8 @@ - + + @@ -32,17 +33,12 @@ - + - - - - - - + @@ -74,7 +70,6 @@ - @@ -88,7 +83,8 @@ - + + @@ -99,11 +95,12 @@ - + + - + diff --git a/osmCoverage.jar b/osmCoverage.jar new file mode 100644 index 0000000..7dddcae --- /dev/null +++ b/osmCoverage.jar Binary files differ diff --git a/src/Demo.sh b/src/Demo.sh index 9398633..6de0fba 100755 --- a/src/Demo.sh +++ b/src/Demo.sh @@ -1 +1,2 @@ -java -cp .:postgis.jar:hayashi_0225.jar:postgresql-9.4.1212.jar Demo +#java -cp .:osmCoverage.jar:hayashi_0225.jar:postgresql-9.4.1212.jar Demo +java -cp .:osmCoverage.jar:hayashi_0225.jar:postgresql-9.4.1212.jar:hsqldb_2.2.9.jar osm.jp.coverage.busstop.Busstop diff --git a/src/database.properties b/src/database.properties new file mode 100644 index 0000000..e66e66c --- /dev/null +++ b/src/database.properties @@ -0,0 +1,4 @@ +db_driver=org.hsqldb.jdbcDriver +db_url=jdbc:hsqldb:file:./database/db +db_user=sa +db_passwd= diff --git a/src/osm/jp/api/HttpGET.java b/src/osm/jp/api/HttpGET.java deleted file mode 100644 index bcde9ad..0000000 --- a/src/osm/jp/api/HttpGET.java +++ /dev/null @@ -1,302 +0,0 @@ -package osm.jp.api; - -import java.net.*; -import java.io.*; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -/** - * Java HTTP クライアントサンプル - HttpURLConnection 版 - - * - * @author 68user http://X68000.q-e-d.net/~68user/ - */ -public class HttpGET { - //public static String host = "http://api06.dev.openstreetmap.org"; - public static String host = "http://api.openstreetmap.org"; - - public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException { - getCapabilities(); - - /* - - - - - - - - - - */ - - double minlon = 139.4197591d; - double maxlon = 139.4279939d; - double minlat = 35.4320438d; - double maxlat = 35.4375923d; - HttpGET.getMap(minlon, minlat, maxlon, maxlat); - - HttpGET.getMap(35.4350644157973d, 139.423684433498d, 50); // あやせ荘 - HttpGET.getMap(35.4341675801122d, 139.418362759267d, 50); // 武者奇橋 - HttpGET.getMap(35.4369651010672d, 139.426400070915d, 50); // 綾瀬市役所 - } - - public static void getCapabilities() throws MalformedURLException, ProtocolException, IOException { - System.out.println(host + "/api/capabilities"); - URL url = new URL(host + "/api/capabilities"); - - HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); - urlconn.setRequestMethod("GET"); - urlconn.setInstanceFollowRedirects(false); - urlconn.setRequestProperty("Accept-Language", "ja;q=0.7,en;q=0.3"); - urlconn.connect(); - - System.out.println("レスポンスコード[" + urlconn.getResponseCode() + "] " + - "レスポンスメッセージ[" + urlconn.getResponseMessage() + "]"); - System.out.println("\n---- ボディ ----"); - - BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream())); - - while (true){ - String line = reader.readLine(); - if ( line == null ){ - break; - } - System.out.println(line); - } - - reader.close(); - urlconn.disconnect(); - } - - - public static final double BIG_Y = (6378137.0d + 6356752.314d) / 2d; // 地球の平均半径(m) - public static final double LAT1 = Math.PI * 2d * BIG_Y / 360d; // 緯度1度の距離(m) - public static int getMap(double lat, double lon, int m) throws MalformedURLException, ProtocolException, IOException { - double dLat = m / LAT1; // 距離を表す緯度(差分) - double minlat = lat - dLat; // 底辺(緯度) - double maxlat = lat + dLat; // 上辺(緯度) - - double y = Math.cos(lat / 180.0d * Math.PI) * BIG_Y; // 緯線上の地球の半径 - double lon1 = (y * 2.0d * Math.PI) / 360; // 経度1度の距離(m) - double dLon = m / lon1; // 距離を表す経度(差分) - double minlon = lon - dLon; // 左辺 - double maxlon = lon + dLon; // 右辺 - - System.out.println("緯線上の地球の半径= "+ y); - System.out.println("緯度1秒の長さ(m)= "+ LAT1 / 3600); - System.out.println("経度1秒の長さ(m)= "+ lon1 / 3600); - - return getMap(minlon, minlat, maxlon, maxlat); - } - - public static int getMap(RectArea center) throws MalformedURLException, ProtocolException, IOException { - return getMap(center.minlon, center.minlat, center.maxlon, center.maxlat); - } - - public static int getMap(double minlon, double minlat, double maxlon, double maxlat) throws MalformedURLException, ProtocolException, IOException { - String param = host + "/api/0.6/map" + "?bbox="+ Double.toString(minlon) +","+ Double.toString(minlat) +","+ Double.toString(maxlon) +","+ Double.toString(maxlat); - - System.out.println(param); - URL url = new URL(param); - - HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); - urlconn.setRequestMethod("GET"); - urlconn.setInstanceFollowRedirects(false); - urlconn.setRequestProperty("Accept-Language", "ja;q=0.7,en;q=0.3"); - urlconn.connect(); - - System.out.println("レスポンスコード[" + urlconn.getResponseCode() + "] " + - "レスポンスメッセージ[" + urlconn.getResponseMessage() + "]"); - System.out.println("\n---- ボディ ----"); - - //------------------------------------------ - DocumentBuilderFactory factory; - DocumentBuilder builder; - Node root; - - try { - factory = DocumentBuilderFactory.newInstance(); - builder = factory.newDocumentBuilder(); - factory.setIgnoringElementContentWhitespace(true); - factory.setIgnoringComments(true); - factory.setValidating(true); - root = builder.parse(urlconn.getInputStream()); - - counter = 0; - checkNodes(root); - } catch (ParserConfigurationException e0) { - System.out.println(e0.getMessage()); - } catch (SAXException e1){ - System.out.println(e1.getMessage()); - } catch (IOException e2) { - System.out.println(e2.getMessage()); - } - - System.out.println("バス停数["+ counter +"]"); - urlconn.disconnect(); - - return counter; - } - - public void sendCMD(String api) throws MalformedURLException, ProtocolException, IOException { - System.out.println(host + api); - URL url = new URL(host + api); - - HttpURLConnection urlconn = (HttpURLConnection)url.openConnection(); - urlconn.setRequestMethod("GET"); - urlconn.setInstanceFollowRedirects(false); - urlconn.setRequestProperty("Accept-Language", "ja;q=0.7,en;q=0.3"); - urlconn.connect(); - - System.out.println("レスポンスコード[" + urlconn.getResponseCode() + "] " + - "レスポンスメッセージ[" + urlconn.getResponseMessage() + "]"); - System.out.println("\n---- ボディ ----"); - - BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream())); - - while (true){ - String line = reader.readLine(); - if ( line == null ){ - break; - } - System.out.println(line); - } - - reader.close(); - urlconn.disconnect(); - } - - public static int counter; - public static void checkNodes(Node node) { - if (isBusstop(node)) { - counter++; - showNode(node); - } - - NodeList nodes = node.getChildNodes(); - for (int i=0; i"+ node.getNodeValue()); - - NodeList nodes = node.getChildNodes(); - for (int i=0; i"); - } - - class RectArea { - public double minlon; - public double maxlon; - public double minlat; - public double maxlat; - - /** - * 矩形領域を中心点と中心点からの距離(メートル)でセットする - * - * @param lat // 中心点の緯度 - * @param lon // 中心点の経度 - * @param m // 距離 領域の一辺の長さの半分 - */ - public RectArea(double lat, double lon, int m) { - double BIG_Y = (40000000.0d / 2.0d / Math.PI); // 地球の半径 - double LAT1 = (10000000.0d / 90.0d); // 緯度1度の距離(m) - double dLat = m / LAT1; // 距離を表す緯度(差分) - minlat = lat - dLat; // 底辺(緯度) - maxlat = lat + dLat; // 上辺(緯度) - double y = Math.sin((90.0d - lat) / 180.0d) * BIG_Y; // 緯線上の地球の半径 - double lon1 = y * 2.0d * Math.PI; // 経度1度の距離(m) - double dLon = m / lon1; // 距離を表す経度(差分) - minlon = lon - dLon; // 左辺 - maxlon = lon + dLon; // 右辺 - } - } -} diff --git a/src/osm/jp/api/HttpPOST.java b/src/osm/jp/api/HttpPOST.java index d66b6cc..c24f88b 100644 --- a/src/osm/jp/api/HttpPOST.java +++ b/src/osm/jp/api/HttpPOST.java @@ -36,18 +36,26 @@ // 送信 PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(urlconn.getOutputStream(), "utf-8"))); pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); - pw.print(""); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); + pw.print(" "); pw.print(""); pw.close(); // closeで送信完了 diff --git a/src/osm/jp/coverage/busstop/Busstop.java b/src/osm/jp/coverage/busstop/Busstop.java new file mode 100644 index 0000000..4f50bf2 --- /dev/null +++ b/src/osm/jp/coverage/busstop/Busstop.java @@ -0,0 +1,865 @@ +package osm.jp.coverage.busstop; +import osm.jp.api.HttpPOST; + +import javax.xml.parsers.*; +import javax.xml.transform.TransformerException; + +import org.w3c.dom.*; +import org.xml.sax.*; + +import java.io.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.SimpleDateFormat; +import java.util.ArrayList; + +import jp.co.areaweb.tools.database.*; + +public class Busstop { + + String filter = ""; + String urlStr = ""; + + public static final boolean DB_INIT = false; + + // 近くのバス停を探す範囲(バス停を中心としたNEER×2m四方の領域 + static final int NEER = 150; // 150m(0.15km) + static boolean nocheck = false; + + public static SimpleDateFormat timeStampFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + + /** + * メイン + * + * java -cp .:ConvBusstop.jar:hayashi_0225.jar:hsqldb_2.2.9.jar osm.jp.ConvBusstop