Newer
Older
osmCoverage / src / osm / jp / coverage / busstop / ToGeoJSON.java
package osm.jp.coverage.busstop;

import java.io.File;
import java.sql.Connection;
import jp.co.areaweb.tools.database.DatabaseTool;

/**
 * PostGISデータをGeoJSONファイルに出力する。
 * 	出力ファイル名:	"./GML_BUSSTOP/busstop.json"
 * 	テーブル名:		t_busstop
 * 		fixed	OSMの周辺に存在するかどうか、存在しない場合は0,存在する場合は1。ブランド有りは50。
 * 		geom	PostGIS形式の位置情報(4612:)
 * SELECT row_to_json(feature) FROM (
select 'Feature' As type, ST_AsGeoJSON(ST_Transform(t_busstop.geom,4326))::json As geometry, row_to_json((
   SELECT p FROM (SELECT t_busstop.idref, t_busstop.fixed) AS p)) AS properties From t_busstop) As feature
* 
 * @author yuu
 *
 */
public class ToGeoJSON {
    public static void main (String[] argv) throws Exception {
        boolean slim = false;
        String gisdb = "gisdb";
        for (String arg : argv) {
            if (arg.equals("-slim")) {
                slim = true;
            }
            else {
                gisdb = arg;
            }
        }
        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,gmlid) As feature";
        Connection con = DatabaseTool.openDb(gisdb);
        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);
        obj.outputDb(con, "WHERE fixed>1", new File("GML_BUSSTOP", "busstop2.json"), false);
    }
}