diff --git a/src/osm/jp/coverage/busstop/ToGeoJSON.java b/src/osm/jp/coverage/busstop/ToGeoJSON.java index c1a000e..ee628cb 100644 --- a/src/osm/jp/coverage/busstop/ToGeoJSON.java +++ b/src/osm/jp/coverage/busstop/ToGeoJSON.java @@ -26,6 +26,12 @@ } } osm.jp.postgis.ToGeoJSON obj = new osm.jp.postgis.ToGeoJSON("busstop"); + obj.sqlForm1 = "SELECT row_to_json(feature) FROM (" + + "select 'Feature' As type, " + + "ST_AsGeoJSON(ST_Transform(t_%s.geom,4326))::json As geometry, " + + "row_to_json((" + + "SELECT p FROM (SELECT t_%s.gmlid, t_%s.fixed) AS p" + + ")) AS properties From t_%s %s order by area,idref) As feature"; Connection con = DatabaseTool.openDb("postgis"); obj.outputDb(con, "", new File("GML_BUSSTOP", "busstop.json"), false); obj.outputDb(con, "WHERE fixed=0", new File("GML_BUSSTOP", "busstop0.json"), false); diff --git a/src/osm/jp/postgis/ToGeoJSON.java b/src/osm/jp/postgis/ToGeoJSON.java index c18b89e..81f6117 100644 --- a/src/osm/jp/postgis/ToGeoJSON.java +++ b/src/osm/jp/postgis/ToGeoJSON.java @@ -46,6 +46,15 @@ */ public String tableName; + public String sqlForm1 = "SELECT row_to_json(feature) FROM (" + + "select 'Feature' As type, " + + "ST_AsGeoJSON(ST_Transform(t_%s.geom,4326))::json As geometry, " + + "row_to_json((" + + "SELECT p FROM (SELECT t_%s.idref, t_%s.fixed) AS p" + + ")) AS properties From t_%s %s order by area,idref) As feature"; + public String sqlForm2 = "SELECT row_to_json(feature) FROM (" + + "select 'Feature' As type, " + + "ST_AsGeoJSON(ST_Transform(t_%s.geom,4326))::json As geometry From t_%s %s order by area,idref) As feature"; public ToGeoJSON(String tableName) { this.tableName = tableName; @@ -53,17 +62,9 @@ public void outputDb(Connection con, String whereStr, File outputFile, boolean slim) throws Exception { try (BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))) { - String sql = "SELECT row_to_json(feature) FROM (" - + "select 'Feature' As type, " - + "ST_AsGeoJSON(ST_Transform(t_"+ this.tableName +".geom,4326))::json As geometry, " - + "row_to_json((" - + "SELECT p FROM (SELECT t_"+ this.tableName +".idref, t_"+ this.tableName +".fixed) AS p" - + ")) AS properties From t_"+ this.tableName +" "+ whereStr +" order by area,idref) As feature"; + String sql = String.format(sqlForm1, tableName,tableName,tableName,tableName,whereStr); if (slim) { - sql = "SELECT row_to_json(feature) FROM (" - + "select 'Feature' As type, " - + "ST_AsGeoJSON(ST_Transform(t_"+ this.tableName +".geom,4326))::json As geometry From t_"+ this.tableName +" " - + whereStr +" order by area,idref) As feature"; + sql = String.format(sqlForm2, tableName,tableName,whereStr); } System.out.println(sql);