postoffice CoverageAll
1 parent 1de2eb1 commit b93bfb177eb9a61a107e1dbaa0e2dcaa0a372cc6
@hayashi hayashi authored on 27 Jan 2018
Showing 2 changed files
View
6
src/osm/jp/coverage/postoffice/CoverageAll.java
public class CoverageAll extends ArrayList<Coverage> {
 
public static void main(String[] args) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException, TransformerException
{
File outputFileCsv = new File(DbPostoffice.TABLE_NAME +".csv");
File outputFileJson = new File(DbPostoffice.TABLE_NAME +".json");
File outputFileCsv = new File("coverage.postoffice.csv");
File outputFileJson = new File("coverage.postoffice.json");
osm.jp.postgis.CoverageAll obj = new osm.jp.postgis.CoverageAll(DbPostoffice.TABLE_NAME);
Connection conPost = DatabaseTool.openDb("postgis");
Connection conHsql = DatabaseTool.openDb("database");
try {
obj.load(conPost, conHsql);
obj.outputCSV(outputFileCsv);
obj.outputJson(outputFileJson);
obj.outputJson(outputFileJson, "国土数値情報 郵便局データ(平成25年)");
}
finally {
DatabaseTool.closeDb(conHsql);
DatabaseTool.closeDb(conPost);
View
8
src/osm/jp/postgis/CoverageAll.java
Connection conHsql = DatabaseTool.openDb("database");
try {
obj.load(conPost, conHsql);
obj.outputCSV(outputFileCsv);
obj.outputJson(outputFileJson);
obj.outputJson(outputFileJson, "Data source");
}
finally {
DatabaseTool.closeDb(conHsql);
DatabaseTool.closeDb(conPost);
csv.save();
}
}
public void outputJson(File outputFile) throws FileNotFoundException, UnsupportedEncodingException, IOException {
public void outputJson(File outputFile, String sourcedata) throws FileNotFoundException, UnsupportedEncodingException, IOException {
try (BufferedWriter hw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"))) {
int level = 0;
hw.write(space(level++) + "{");
hw.newLine();
hw.write(space(level) + "\"timestamp\": \""+ LocalDate.now().format(DateTimeFormatter.ISO_DATE) +"\",");
hw.newLine();
hw.write(space(level) + "\"sourcedata\": \"国土数値情報 燃料給油所データ 平成28年(2016)\",");
hw.write(space(level) + "\"sourcedata\": \""+ sourcedata +"\",");
hw.newLine();
hw.write(space(level++) + "\"coverage\": [");
hw.newLine();
boolean head = true;
hw.write(space(level) + "\"name\": \""+ cover.name +"\",");
hw.newLine();
hw.write(space(level) + "\"denominator\": "+ String.valueOf(cover.denominator) +",");
hw.newLine();
hw.write(space(level) + "\"molecule\": "+ String.valueOf(cover.molecule) +",");
hw.newLine();
hw.write(space(level) + "\"par\": "+ String.valueOf(df3.format(cover.par)));
hw.newLine();
 
hw.write(space(--level) + "}");