| |
---|
| | } |
---|
| | */ |
---|
| | |
---|
| | 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 = "{" + |
---|
| |
---|
| | |