diff --git a/src/osm/jp/coverage/fuel/ToGeoJSON.java b/src/osm/jp/coverage/fuel/ToGeoJSON.java index 1607280..fa7f32e 100644 --- a/src/osm/jp/coverage/fuel/ToGeoJSON.java +++ b/src/osm/jp/coverage/fuel/ToGeoJSON.java @@ -27,12 +27,14 @@ public static final String JSON_FILE_NAME = "fuel.json"; public static void main (String[] argv) throws Exception { - outputDb(DatabaseTool.openDb("postgis")); + Connection con = DatabaseTool.openDb("postgis"); + outputDb(con, "WHERE fixed=0", new File("fuel0.json")); + outputDb(con, "WHERE fixed>0 and fixed<50", new File("fuel1.json")); + outputDb(con, "WHERE fixed>49", new File("fuel2.json")); } - public static void outputDb(Connection con) throws Exception { - File csvFile = new File(JSON_FILE_NAME); - try (BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8"))) { + public static void outputDb(Connection con, String whereStr, File outputFile) throws Exception { + try (BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))) { String line = "{" + "\"type\": \"FeatureCollection\"," + "\"features\": ["; @@ -42,15 +44,27 @@ PreparedStatement ps8 = con.prepareStatement("SELECT row_to_json(feature) FROM (" + "select 'Feature' As type, ST_AsGeoJSON(ST_Transform(t_fuel.geom,4326))::json As geometry, row_to_json((" - + "SELECT p FROM (SELECT t_fuel.idref, t_fuel.fixed) AS p)) AS properties From t_fuel) As feature"); + + "SELECT p FROM (SELECT t_fuel.idref, t_fuel.fixed) AS p)) AS properties From t_fuel "+ whereStr +" order by area,idref) As feature"); try (ResultSet rset8 = ps8.executeQuery()) { + boolean top = true; while (rset8.next()) { + if (top) { + top = false; + } + else { + line = ","; + System.out.println(line); + ow.write(line); + ow.newLine(); + } line = rset8.getString(1); - System.out.println(line); + System.out.print(line); ow.write(line); - ow.newLine(); } } + System.out.println(); + ow.newLine(); + line = "]}"; System.out.println(line); ow.write(line);