overraide
1 parent 88a8d8e commit 9f8a1de13b7da83f5dda340fdd1e200c63842b8d
@hayashi hayashi authored on 13 May 2018
Showing 2 changed files
View
6
src/osm/jp/coverage/busstop/ToGeoJSON.java
slim = true;
}
}
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);
obj.outputDb(con, "WHERE fixed=1", new File("GML_BUSSTOP", "busstop1.json"), false);
View
29
src/osm/jp/postgis/ToGeoJSON.java
}
*/
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;
}
 
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);
 
String line = "{" +