package osm.jp.coverage.fuel; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import jp.co.areaweb.tools.database.DatabaseTool; import osm.jp.api.Coverage; /** * PostGISデータをCarto用のCSVファイルに出力する。 * 出力ファイル名: "fuel.csv" * テーブル名: t_fuel * インデックス: ix_fuel_geom * gid PostGISの識別ID * fixed OSMのバス停が周辺に存在するかどうか、存在しない場合は0,存在する場合は1。ブランド有りは50。 * geom PostGIS形式の位置情報(4612:) * @author yuu * */ public class ToCartoCSV { public static final String CSV_FILE_NAME = "t_fuel.carto.csv"; public static void main (String[] argv) throws Exception { outputDb(DatabaseTool.openDb(Coverage.DB_PORP_GISDB)); } public static void outputDb(Connection con) throws Exception { File csvFile = new File(CSV_FILE_NAME); try (BufferedWriter ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(csvFile), "UTF-8"))) { String line = "idref,score,geom"; System.out.println(line); ow.write(line); ow.newLine(); PreparedStatement ps8 = con.prepareStatement("SELECT gmlid,area,geom,fixed FROM t_fuel"); try (ResultSet rset8 = ps8.executeQuery()) { while (rset8.next()) { String gmlid = rset8.getString("gmlid"); String geom = rset8.getString("geom"); int score = rset8.getInt("fixed"); int area = rset8.getInt("area"); score = (score > 1 ? 2 : score); line = ""+ gmlid +","+ area +","+ score +","+ geom +""; System.out.println(line); ow.write(line); ow.newLine(); } } ow.flush(); } } }