| | package osm.jp.coverage.busstop; |
---|
| | |
---|
| | import java.io.File; |
---|
| | import java.sql.Connection; |
---|
| | import java.sql.PreparedStatement; |
---|
| | import java.sql.ResultSet; |
---|
| | import java.sql.SQLException; |
---|
| | import java.text.MessageFormat; |
---|
| | import jp.co.areaweb.tools.database.DatabaseTool; |
---|
| | import static org.hamcrest.CoreMatchers.is; |
---|
| | import static org.hamcrest.CoreMatchers.not; |
---|
| | import org.junit.*; |
---|
| | import static org.junit.Assert.*; |
---|
| | import org.junit.runners.MethodSorters; |
---|
| | import osm.jp.api.Coverage; |
---|
| | import osm.jp.api.Japan; |
---|
| | import osm.jp.api.RectArea; |
---|
| | import osm.jp.coverage.DbTest; |
---|
| | import osm.jp.coverage.PoiTest; |
---|
| | import static osm.jp.coverage.busstop.Busstop.NEER; |
---|
| | |
---|
| | /** |
---|
| | * |
---|
| | * @author yuu |
---|
| | */ |
---|
| | @FixMethodOrder (MethodSorters.NAME_ASCENDING) |
---|
| | public class BusstopCheck extends PoiTest { |
---|
| | |
---|
| | @Before |
---|
| | public void setUp() throws Exception { |
---|
| | } |
---|
| | |
---|
| | @After |
---|
| | public void tearDown() throws Exception { |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * java Busstop |
---|
| | * |
---|
| | */ |
---|
| | |
---|
| | /** |
---|
| | * |
---|
| | * |
---|
| | */ |
---|
| | @Test |
---|
| | public void test01Busstop_dataread() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String sql = "SELECT * FROM " |
---|
| | + DbBusstop.TABLE_NAME |
---|
| | +" WHERE (lat > '34.69161765717579') and (lat < '34.697025680375795') and (lon > '135.79486712544522') and (lon < '135.80144696784524')"; |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement(sql); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | while (rset1.next()) { |
---|
| | System.out.println(rset1.getString("gmlid")); |
---|
| | System.out.println(rset1.getInt("area")); |
---|
| | System.out.println(rset1.getInt("fixed1")); |
---|
| | System.out.println(rset1.getString("name")); |
---|
| | System.out.println(rset1.getDouble("lat")); |
---|
| | System.out.println(rset1.getDouble("lon")); |
---|
| | System.out.println(rset1.getBoolean("removed")); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * DbExistBusstop.TABLE_NAME にレコードが1件以上存在すること |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_busstop() { |
---|
| | File dir = new File(Coverage.DB_PORP_LOCALDB); |
---|
| | assertTrue(dir.exists()); |
---|
| | assertTrue(dir.isDirectory()); |
---|
| | |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement("SELECT count(*) FROM "+ DbExistBusstop.TABLE_NAME); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | if (rset1.next()) { |
---|
| | long cnt = rset1.getLong(1); |
---|
| | assertThat((cnt > 0), is(true)); |
---|
| | } |
---|
| | else { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * ノード: 八幡前 (3152604023) |
---|
| | * 場所: 33.9808001, 133.3123441 |
---|
| | * fixme有り |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_3152604023() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement( |
---|
| | "SELECT * FROM "+ DbBusstop.TABLE_NAME +" where name='八幡前' and area=38" |
---|
| | ); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | boolean ari = false; |
---|
| | while (rset1.next()) { |
---|
| | // fixme有り |
---|
| | ari = true; |
---|
| | String gmlid = rset1.getString("gmlid"); |
---|
| | String name = rset1.getString("name"); |
---|
| | int fixed = rset1.getInt("fixed"); |
---|
| | int fixed1 = rset1.getInt("fixed1"); |
---|
| | System.out.println(MessageFormat.format("gmlid: '{0}', name: '{1}', fixed: {2}, fixed1: {3}", gmlid, name, fixed, fixed1)); |
---|
| | assertTrue(fixed < 50); |
---|
| | assertThat(rset1.getBoolean("removed"), is(false)); |
---|
| | } |
---|
| | if (!ari) { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * ノード: 4940018338 (奥牧野) |
---|
| | * 場所: 35.5909251, 139.1498642, area=14 |
---|
| | * highway=bus_stop, name=null, bus=yes, public_transport=platform, operator=神奈中 |
---|
| | * nameなし |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_4940018338() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String gmlid = getGmlid(hsqldb, |
---|
| | Double.parseDouble("35.5909251"), |
---|
| | Double.parseDouble("139.1498642"), 150); |
---|
| | assertNotNull(gmlid); |
---|
| | try ( |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement( |
---|
| | "SELECT * FROM "+ DbBusstop.TABLE_NAME +" where gmlid=? and area=14" |
---|
| | ) |
---|
| | ) { |
---|
| | ps1.setString(1, gmlid); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | if (rset1.next()) { |
---|
| | assertThat(rset1.getString("gmlid"), is(gmlid)); |
---|
| | assertThat(rset1.getInt("fixed1"), is(3)); |
---|
| | assertThat(rset1.getBoolean("removed"), is(false)); |
---|
| | } |
---|
| | else { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * ノード: 古里団地 (2217968698, 2217968723), |
---|
| | * 場所: 35.4002371, 139.4160855, area=14 |
---|
| | * highway=bus_stop, bus=yes, public_transport=platform |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_2217968698() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String gmlid = getGmlid(hsqldb, |
---|
| | Double.parseDouble("35.4002371"), |
---|
| | Double.parseDouble("139.4160855"), 150); |
---|
| | assertNotNull(gmlid); |
---|
| | try ( |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement( |
---|
| | "SELECT * FROM "+ DbBusstop.TABLE_NAME +" where gmlid=? and area=14" |
---|
| | ) |
---|
| | ) { |
---|
| | ps1.setString(1, gmlid); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | if (rset1.next()) { |
---|
| | assertThat(rset1.getInt("fixed1"), is(100)); |
---|
| | assertThat(rset1.getBoolean("removed"), is(false)); |
---|
| | } |
---|
| | else { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * ノード: 海老名高校前 (2043102034) |
---|
| | * 場所: 35.4435042, 139.3878934 |
---|
| | * highway=bus_stop |
---|
| | * 廃止されたバス停、付近にGML(gmlid:n4770, area:14) |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_2043102034() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String gmlid = getGmlid(hsqldb, |
---|
| | Double.parseDouble("35.4435042"), |
---|
| | Double.parseDouble("139.3878934"), 150); |
---|
| | assertNotNull(gmlid); |
---|
| | |
---|
| | String sql = "SELECT * FROM "+ DbBusstop.TABLE_NAME +" where gmlid=? and area=14"; |
---|
| | try (PreparedStatement ps1 = hsqldb.prepareStatement(sql)) { |
---|
| | ps1.setString(1, gmlid); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | if (rset1.next()) { |
---|
| | assertThat(rset1.getString("name"), not("海老名高校前")); |
---|
| | } |
---|
| | else { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * gmlid:n3249, area:14, name:本郷コミュニティセンター |
---|
| | * 35.41318 139.39504 |
---|
| | * |
---|
| | * ノード: 本郷コミュニティセンター (2032107504) |
---|
| | * 場所: 35.4134755, 139.3952826 |
---|
| | * disused:highway=bus_stop |
---|
| | */ |
---|
| | @Test |
---|
| | public void test02Busstop_n3249() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String gmlid = getGmlid(hsqldb, |
---|
| | Double.parseDouble("35.41318"), |
---|
| | Double.parseDouble("139.39504"), 150); |
---|
| | assertNotNull(gmlid); |
---|
| | |
---|
| | String sql = "SELECT * FROM "+ DbBusstop.TABLE_NAME +" where gmlid=? and area=14"; |
---|
| | try (PreparedStatement ps1 = hsqldb.prepareStatement(sql)) { |
---|
| | ps1.setString(1, gmlid); |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | if (rset1.next()) { |
---|
| | assertThat(rset1.getString("name"), is("本郷コミュニティセンター")); |
---|
| | assertThat(rset1.getInt("fixed1"), is(50)); |
---|
| | assertThat(rset1.getBoolean("removed"), is(true)); |
---|
| | } |
---|
| | else { |
---|
| | fail(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * DbExistBusstopが読み取れること |
---|
| | * |
---|
| | */ |
---|
| | @Test |
---|
| | public void test03Busstop_dataread() { |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(Coverage.DB_PORP_LOCALDB)) { |
---|
| | String sqlStr1 = "SELECT * FROM "+ DbExistBusstop.TABLE_NAME; |
---|
| | String sqlStr2 = "SELECT gmlid,lat,lon,fixed,fixed1,area,name FROM "+ DbBusstop.TABLE_NAME |
---|
| | +" WHERE (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)"; |
---|
| | String sqlStr3 = "UPDATE "+ DbBusstop.TABLE_NAME |
---|
| | +" SET fixed1=? WHERE gmlid=? and area=?"; |
---|
| | System.out.println(sqlStr1); |
---|
| | try ( PreparedStatement ps2 = hsqldb.prepareStatement(sqlStr2); |
---|
| | PreparedStatement ps1 = hsqldb.prepareStatement(sqlStr1); |
---|
| | PreparedStatement ps3 = hsqldb.prepareStatement(sqlStr3);) |
---|
| | { |
---|
| | try (ResultSet rset1 = ps1.executeQuery()) { |
---|
| | while (rset1.next()) { |
---|
| | double lat = rset1.getDouble("lat"); |
---|
| | double lon = rset1.getDouble("lon"); |
---|
| | int score = rset1.getInt("score"); |
---|
| | String name = rset1.getString("name"); |
---|
| | if ((name != null) && !name.trim().isEmpty()) { |
---|
| | score = 50; |
---|
| | } |
---|
| | String gmlid; |
---|
| | int area; |
---|
| | int fixed1; |
---|
| | |
---|
| | // 指定の緯度経度を中心とする半径200x2m四方の矩形領域 |
---|
| | assertTrue(lat > 20.0D); |
---|
| | assertTrue(lat < 50.0D); |
---|
| | assertTrue(lon < 155.0D); |
---|
| | assertTrue(lon > 110.0D); |
---|
| | |
---|
| | RectArea rect = new RectArea(lat, lon, NEER*2); // 600m 四方 |
---|
| | System.out.println(sqlStr2 +"["+ rect.minlat +", "+ rect.maxlat +", "+ rect.minlon +", "+ rect.maxlon +"]"); |
---|
| | ps2.setDouble(1, rect.minlat); |
---|
| | ps2.setDouble(2, rect.maxlat); |
---|
| | ps2.setDouble(3, rect.minlon); |
---|
| | ps2.setDouble(4, rect.maxlon); |
---|
| | try (ResultSet rset2 = ps2.executeQuery()) { |
---|
| | while (rset2.next()) { |
---|
| | System.out.print("{"); |
---|
| | gmlid = rset2.getString("gmlid"); |
---|
| | System.out.print("gmlid:"+gmlid +", "); |
---|
| | area = rset2.getInt("area"); |
---|
| | System.out.print("area:"+area +", "); |
---|
| | fixed1 = rset2.getInt("fixed1"); |
---|
| | fixed1 += score; |
---|
| | System.out.print("fixed1:"+fixed1 +", "); |
---|
| | String ksjName = rset2.getString("name"); |
---|
| | System.out.print("ksjName:"+ksjName +", "); |
---|
| | double lat2 = rset2.getDouble("lat"); |
---|
| | System.out.print("lat2:"+lat2 +", "); |
---|
| | double lon2 = rset2.getDouble("lon"); |
---|
| | System.out.print("lon2:"+lon2 +", "); |
---|
| | |
---|
| | double dd = Japan.distanceKm(lat,lon,lat2,lon2); |
---|
| | System.out.print("dd:"+dd +" "); |
---|
| | System.out.println("}"); |
---|
| | |
---|
| | |
---|
| | System.out.println("distance() -> "+ dd +"(km)"); |
---|
| | if ( ((dd * 1000.0D) < NEER) |
---|
| | || (((dd * 1000.0D) < NEER*2) && (name != null) && (name.equals(ksjName)))) |
---|
| | { |
---|
| | System.out.println(sqlStr3 +" ["+ fixed1 +", "+ gmlid +", "+ area +"]"); |
---|
| | ps3.setInt(1, fixed1); |
---|
| | ps3.setString(2, gmlid); |
---|
| | ps3.setInt(3, area); |
---|
| | //ps3.executeUpdate(); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | catch (Exception ex) { |
---|
| | fail(ex.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * (4)DISUSEDをファイルに出力する |
---|
| | * java osm.jp.coverage.busstop.DbBusstop -OUTPUT GML_BUSSTOP/P11-10.removed.txt |
---|
| | * |
---|
| | * @throws Exception |
---|
| | */ |
---|
| | @Test |
---|
| | public void test40_main_output() throws Exception { |
---|
| | int cnt = 0; |
---|
| | String databaseName = Coverage.DB_PORP_LOCALDB; |
---|
| | String tableName = "busstop"; |
---|
| | |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(databaseName)) { |
---|
| | cnt = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE"); |
---|
| | System.out.println("'BUSSTOP REMOVED=TRUE' table count = " + cnt); |
---|
| | } |
---|
| | catch (Exception e) { |
---|
| | fail(e.toString()); |
---|
| | } |
---|
| | |
---|
| | try { |
---|
| | String[] args = new String[]{"-OUTPUT", "P11-10.removed.json.txt"}; |
---|
| | DbBusstop.main(args); |
---|
| | } |
---|
| | catch(Exception e) { |
---|
| | fail(e.toString()); |
---|
| | } |
---|
| | |
---|
| | File file = new File("P11-10.removed.json.txt"); |
---|
| | assertThat(file.exists(), is(true)); |
---|
| | |
---|
| | try (Connection hsqldb = DatabaseTool.openDb(databaseName)) { |
---|
| | int cnt1 = DbTest.getRecordCount(hsqldb, tableName, "REMOVED=TRUE"); |
---|
| | System.out.println("'BUSSTOP REMOVED=TRUE' table count = " + cnt1); |
---|
| | assertThat(cnt1, is(cnt)); |
---|
| | } |
---|
| | catch (Exception e) { |
---|
| | fail(e.toString()); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | String getGmlid(Connection hsqldb, double lat, double lon, int neer) throws SQLException { |
---|
| | double mind = 99999.9D; |
---|
| | String ret = null; |
---|
| | |
---|
| | // 指定の緯度経度を中心とする半径NEERx2m四方の矩形領域 |
---|
| | RectArea rect = new RectArea(lat, lon, neer * 2); // NEERm 四方 |
---|
| | String sqlStr2 = "SELECT * FROM " |
---|
| | + DbBusstop.TABLE_NAME |
---|
| | +" WHERE (lat > ?) and (lat < ?) and (lon > ?) and (lon < ?)"; |
---|
| | try (PreparedStatement ps2 = hsqldb.prepareStatement(sqlStr2)) { |
---|
| | ps2.setDouble(1, rect.minlat); |
---|
| | ps2.setDouble(2, rect.maxlat); |
---|
| | ps2.setDouble(3, rect.minlon); |
---|
| | ps2.setDouble(4, rect.maxlon); |
---|
| | try (ResultSet rset2 = ps2.executeQuery()) { |
---|
| | while (rset2.next()) { |
---|
| | String gmlid = rset2.getString("gmlid"); |
---|
| | double lat2 = rset2.getDouble("lat"); |
---|
| | double lon2 = rset2.getDouble("lon"); |
---|
| | double dd = Japan.distanceKm(lat,lon,lat2,lon2); |
---|
| | if (dd < mind) { |
---|
| | mind = dd; |
---|
| | ret = gmlid; |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | return ret; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |