• R/O
  • HTTP
  • SSH
  • HTTPS

convbusstop: Commit


Commit MetaInfo

Revisión47ac5f1328893651dfb9960370af20552bc8bdc5 (tree)
Tiempo2017-01-09 08:24:01
Autoryuuhayashi <hayashi.yuu@gmai...>
Commiteryuuhayashi

Log Message

結果をPostGISへインポートさせるSQLファイルを出力する機能を追加

Cambiar Resumen

Diferencia incremental

--- a/.classpath
+++ /dev/null
@@ -1,8 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<classpath>
3- <classpathentry kind="src" path="src"/>
4- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5- <classpathentry kind="lib" path="lib/hayashi_0225.jar"/>
6- <classpathentry kind="lib" path="lib/hsqldb_2.2.9.jar"/>
7- <classpathentry kind="output" path="classes"/>
8-</classpath>
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@ bin/
44 classes/
55 sample/
66 dest/
7+**/ConvBusstop.jar
78
89 P*-*_GML/
910
@@ -13,6 +14,8 @@ P*-*_GML/
1314 .externalToolBuilders/
1415 .metadata
1516 .settings
17+.project
18+.classpath
1619
1720 # ============ #
1821 # OS generated #
--- a/.project
+++ /dev/null
@@ -1,42 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8"?>
2-<projectDescription>
3- <name>convbusstop</name>
4- <comment></comment>
5- <projects>
6- </projects>
7- <buildSpec>
8- <buildCommand>
9- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
10- <triggers>full,incremental,</triggers>
11- <arguments>
12- <dictionary>
13- <key>LaunchConfigHandle</key>
14- <value>&lt;project&gt;/.externalToolBuilders/New_Builder.launch</value>
15- </dictionary>
16- </arguments>
17- </buildCommand>
18- <buildCommand>
19- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
20- <triggers>full,incremental,</triggers>
21- <arguments>
22- <dictionary>
23- <key>LaunchConfigHandle</key>
24- <value>&lt;project&gt;/.externalToolBuilders/Ant_Builder.launch</value>
25- </dictionary>
26- </arguments>
27- </buildCommand>
28- <buildCommand>
29- <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
30- <triggers>full,incremental,</triggers>
31- <arguments>
32- <dictionary>
33- <key>LaunchConfigHandle</key>
34- <value>&lt;project&gt;/.externalToolBuilders/org.eclipse.jdt.core.javabuilder.launch</value>
35- </dictionary>
36- </arguments>
37- </buildCommand>
38- </buildSpec>
39- <natures>
40- <nature>org.eclipse.jdt.core.javanature</nature>
41- </natures>
42-</projectDescription>
Binary files a/ConvBusstop.jar and /dev/null differ
--- a/build.xml
+++ b/build.xml
@@ -31,7 +31,7 @@
3131 [STEP 2] コンパイル
3232 -->
3333 <target name="compile_src" depends="clean" description="コンパイル src">
34- <javac target="1.6" source="1.6" optimize="off" debug="on" verbose="false" srcdir="${src}" destdir="${classes}" encoding="UTF-8" includeantruntime="false">
34+ <javac target="1.8" source="1.8" optimize="off" debug="on" verbose="false" srcdir="${src}" destdir="${classes}" encoding="UTF-8" includeantruntime="false">
3535 <include name="**" />
3636 <exclude name="**/*.smap" />
3737
--- a/src/osm/jp/ConvBusstop.java
+++ b/src/osm/jp/ConvBusstop.java
@@ -203,6 +203,9 @@ public class ConvBusstop {
203203 // ローカルデータベース内の情報を「busstop.xml」に出力する
204204 int counter = outputDb(con, new File(iStr));
205205 System.out.println("["+ counter +"] 変換完了しました。");
206+
207+ // ローカルデータベース内の情報をPostGIS用の「busstop.sql」に出力する
208+ ToPostgis.outputDb(con, new File(iStr));
206209 }
207210 }
208211 System.out.println("["+ fcounter +"]つのファイルをインポートしました。");
--- /dev/null
+++ b/src/osm/jp/ToPostgis.java
@@ -0,0 +1,65 @@
1+package osm.jp;
2+
3+import java.io.BufferedWriter;
4+import java.io.File;
5+import java.io.FileOutputStream;
6+import java.io.IOException;
7+import java.io.OutputStreamWriter;
8+import java.sql.Connection;
9+import java.sql.PreparedStatement;
10+import java.sql.ResultSet;
11+import java.sql.SQLException;
12+
13+/**
14+ * 国土数値情報から読み取ったデータをPostGISへインサートするためのSQLファイルに出力する。
15+ * 出力ファイル名: "busstop.sql"
16+ * テーブル名: t_busstop
17+ * インデックス: ix_busstop_geom
18+ * gid PostGISの識別ID
19+ * name バス停名称
20+ * fixed OSMのバス停が周辺に存在するかどうか、存在しない場合は0,存在する場合はその数。
21+ * geom PostGIS形式の位置情報(4612:)
22+ * @author yuu
23+ *
24+ */
25+public class ToPostgis {
26+ public static final String SQL_FILE_NAME = "busstop.sql";
27+
28+ public static int outputDb(Connection con, File dir) throws IOException, SQLException {
29+ File sqlFile = new File(dir, SQL_FILE_NAME);
30+ int counter = 0;
31+
32+ BufferedWriter ow = null;
33+
34+ // OSM file header
35+ ow = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sqlFile), "UTF-8"));
36+ ow.write("CREATE TABLE t_busstop ("
37+ + "gid SERIAL PRIMARY KEY,"
38+ + "name text,"
39+ + "fixed integer,"
40+ + "geom GEOMETRY(POINT, 4612)"
41+ + ");");
42+ ow.newLine();
43+ ow.write("CREATE INDEX ix_busstop_geom ON t_busstop USING GiST (geom);");
44+ ow.newLine();
45+
46+ PreparedStatement ps8 = con.prepareStatement("SELECT idref,name,lat,lon,fixed FROM bus_stop");
47+ ResultSet rset8 = ps8.executeQuery();
48+ while (rset8.next()) {
49+ String idref = rset8.getString("idref");
50+ String name = rset8.getString("name");
51+ Double lat = rset8.getDouble("lat");
52+ Double lon = rset8.getDouble("lon");
53+ int fixed = rset8.getInt("fixed");
54+
55+ counter++;
56+ String osm_node = "insert into t_busstop(name,fixed,geom) VALUES('"+ name +"',"+ fixed +" , ST_GeomFromText('POINT("+ Double.toString(lon) +" "+ Double.toString(lat) +")', 4612));";
57+ System.out.println(osm_node);
58+ ow.write(osm_node);
59+ ow.newLine();
60+ }
61+ rset8.close();
62+ ow.close();
63+ return counter;
64+ }
65+}
Show on old repository browser