diff --git a/src/osm/jp/coverage/busstop/Busstop.java b/src/osm/jp/coverage/busstop/Busstop.java index 02efe48..7612e83 100644 --- a/src/osm/jp/coverage/busstop/Busstop.java +++ b/src/osm/jp/coverage/busstop/Busstop.java @@ -366,7 +366,7 @@ if (rset1.next()) { int fixed = rset1.getInt("score"); if (fixed < score) { - System.out.println("import existing_data : [id:"+ idrefStr +"] score="+ Integer.toString(score) +" "+ nameStr); + System.out.println("update existing_data : [id:"+ idrefStr +"] score="+ Integer.toString(score) +" "+ nameStr); PreparedStatement ps5 = con.prepareStatement("UPDATE existing_data SET score=? WHERE idref=?"); ps5.setInt(1, score); ps5.setString(2, idrefStr); @@ -415,7 +415,7 @@ ps2.setInt(4, areacode); ps2.setDouble(5, lon); ps2.setDouble(6, lat); - //System.out.println("INSERT INTO bus_stop (idref,name,fixed,area,lat,lon) VALUES ("+ idref +",'"+ nameStr +"',"+ fixed +","+ areacode +","+ lat +","+ lon +")"); + System.out.println("INSERT INTO bus_stop (idref,name,fixed,area,lat,lon) VALUES ("+ idref +",'"+ nameStr +"',"+ fixed +","+ areacode +","+ lat +","+ lon +")"); ps2.executeUpdate(); } rset1.close(); diff --git a/src/osm/jp/coverage/busstop/ToPostgis.java b/src/osm/jp/coverage/busstop/ToPostgis.java index 920d49c..8c14f8a 100644 --- a/src/osm/jp/coverage/busstop/ToPostgis.java +++ b/src/osm/jp/coverage/busstop/ToPostgis.java @@ -26,6 +26,7 @@ */ public class ToPostgis { public static final String SQL_FILE_NAME = "busstop.sql"; + public static boolean NAGOYA_MODE = false; BufferedWriter ow = null; public ToPostgis(File dir) throws UnsupportedEncodingException, FileNotFoundException { @@ -33,6 +34,14 @@ this.ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sqlFile), "UTF-8")); } + public void setNagoyaMode(boolean mode) { + ToPostgis.NAGOYA_MODE = mode; + } + + public boolean isNagoyaMode() { + return ToPostgis.NAGOYA_MODE; + } + public int outputDb(Connection con) throws IOException, SQLException { int counter = 0; @@ -48,7 +57,13 @@ int score = rset8.getInt("fixed"); counter++; - String osm_node = "insert into nagoya_busstop(name,kana,fixed,area,geom) VALUES('"+ escapeStr(name) +"','"+ escapeStr(kana) +"',"+ score +",0, ST_GeomFromText('POINT("+ Double.toString(lon) +" "+ Double.toString(lat) +")', 4612));"; + String osm_node; + if (isNagoyaMode()) { + osm_node = "insert into nagoya_busstop(name,kana,fixed,area,geom) VALUES('"+ escapeStr(name) +"','"+ escapeStr(kana) +"',"+ score +",0, ST_GeomFromText('POINT("+ Double.toString(lon) +" "+ Double.toString(lat) +")', 4612));"; + } + else { + osm_node = "insert into t_busstop(name,fixed,area,geom) VALUES('"+ escapeStr(name) +"',"+ score +",0, ST_GeomFromText('POINT("+ Double.toString(lon) +" "+ Double.toString(lat) +")', 4612));"; + } System.out.println(osm_node); this.ow.write(osm_node); this.ow.newLine(); @@ -65,7 +80,7 @@ * @return */ public String escapeStr(String name) { - return name.replaceAll("'", "''"); + return ((name == null) ? "" : name.replaceAll("'", "''")); } public void close() {