移植 showGmlPoint
1 parent e75e80e commit c32498f80742d11abf35397edb08ea0d5d437a1b
@hayashi hayashi authored on 30 Sep 2017
Showing 2 changed files
View
104
src/osm/jp/coverage/busstop/Busstop.java
}
return null;
}
 
public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {
String positionStr = "";
String latStr = "";
String lonStr = "";
String idStr = "";
 
NamedNodeMap nodeMap = node.getAttributes();
if ( null != nodeMap ) {
for ( int j=0; j<nodeMap.getLength(); j++ ) {
if (nodeMap.item(j).getNodeName().equals("id")) {
idStr = nodeMap.item(j).getNodeValue();
}
}
}
 
NodeList nodes = node.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("jps:GM_Point.position")) {
NodeList nodes3 = node2.getChildNodes();
for (int j=0; j < nodes3.getLength(); j++) {
Node node3 = nodes3.item(j);
if (node3.getNodeName().equals("jps:DirectPosition")) {
NodeList nodes4 = node3.getChildNodes();
for (int k=0; k < nodes4.getLength(); k++) {
Node node4 = nodes4.item(k);
if (node4.getNodeName().equals("DirectPosition.coordinate")) {
positionStr = node4.getTextContent();
String[] str4Ary = positionStr.split(" ");
latStr = str4Ary[0];
lonStr = str4Ary[1];
break;
}
}
break;
}
}
 
PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?");
double lat = Double.parseDouble(latStr);
double lon = Double.parseDouble(lonStr);
ps6.setDouble(1, lat);
ps6.setDouble(2, lon);
// ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
ps6.setInt(3, 0);
ps6.setString(4, idStr);
System.out.println("UPDATE bus_stop("+ idStr +") lat="+ lat +", lon="+ lon +", fixed=0");
ps6.executeUpdate();
ps6.close();
}
}
}
 
/**
* <gml:Point gml:id="n1">
* <gml:pos>35.14591397 139.10569573</gml:pos>
* </gml:Point>
*
* @param con
* @param node
* @param areacode
* @throws IOException
* @throws SQLException
*/
public static void showGmlPoint(Connection con, Node node, int areacode) throws IOException, SQLException {
String positionStr = "";
String latStr = "";
String lonStr = "";
String idStr = "";
 
NamedNodeMap nodeMap = node.getAttributes();
if ( null != nodeMap ) {
for ( int j=0; j<nodeMap.getLength(); j++ ) {
if (nodeMap.item(j).getNodeName().equals("gml:id")) {
idStr = nodeMap.item(j).getNodeValue();
}
}
}
 
NodeList nodes = node.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("gml:pos")) {
positionStr = node2.getTextContent().trim();
String[] str4Ary = positionStr.split(" ");
latStr = str4Ary[0];
lonStr = str4Ary[1];
 
PreparedStatement ps6 = con.prepareStatement("INSERT INTO bus_stop (lat,lon,fixed, area,idref) VALUES (?,?,?,?,?)");
double lat = Double.parseDouble(latStr);
double lon = Double.parseDouble(lonStr);
System.out.println("INSERT INTO bus_stop (lat,lon,fixed,area, idref) VALUES ('"+ latStr +"','"+ lonStr +"','0',"+ areacode +",'"+ idStr +"')");
 
ps6.setDouble(1, lat);
ps6.setDouble(2, lon);
//ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
ps6.setInt(3, 0);
ps6.setInt(4, areacode);
ps6.setString(5, idStr);
ps6.executeUpdate();
ps6.close();
}
}
}
}
View
164
src/osm/jp/coverage/busstop/DbBusstop.java
package osm.jp.coverage.busstop;
 
import java.io.*;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import static osm.jp.coverage.busstop.Busstop.showBusStop;
import static osm.jp.coverage.busstop.Busstop.showED01;
import static osm.jp.coverage.busstop.Busstop.showGmPoint;
import static osm.jp.coverage.busstop.Busstop.showGmlPoint;
 
public class DbBusstop {
public static final String TABLE_NAME = "bus_stop";
public static boolean DROP = false;
}
return iCounter;
}
 
public static void showGmPoint(Connection con, Node node) throws IOException, SQLException {
String positionStr = "";
String latStr = "";
String lonStr = "";
String idStr = "";
 
NamedNodeMap nodeMap = node.getAttributes();
if ( null != nodeMap ) {
for ( int j=0; j<nodeMap.getLength(); j++ ) {
if (nodeMap.item(j).getNodeName().equals("id")) {
idStr = nodeMap.item(j).getNodeValue();
}
}
}
 
NodeList nodes = node.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("jps:GM_Point.position")) {
NodeList nodes3 = node2.getChildNodes();
for (int j=0; j < nodes3.getLength(); j++) {
Node node3 = nodes3.item(j);
if (node3.getNodeName().equals("jps:DirectPosition")) {
NodeList nodes4 = node3.getChildNodes();
for (int k=0; k < nodes4.getLength(); k++) {
Node node4 = nodes4.item(k);
if (node4.getNodeName().equals("DirectPosition.coordinate")) {
positionStr = node4.getTextContent();
String[] str4Ary = positionStr.split(" ");
latStr = str4Ary[0];
lonStr = str4Ary[1];
break;
}
}
break;
}
}
 
try (PreparedStatement ps6 = con.prepareStatement("UPDATE bus_stop SET lat=?,lon=?,fixed=? WHERE idref=?")) {
double lat = Double.parseDouble(latStr);
double lon = Double.parseDouble(lonStr);
ps6.setDouble(1, lat);
ps6.setDouble(2, lon);
// ps6.setInt(3, (ConvBusstop.nocheck ? 0 : HttpGET.getMap(lat, lon, NEER)));
ps6.setInt(3, 0);
ps6.setString(4, idStr);
System.out.println("UPDATE bus_stop("+ idStr +") lat="+ lat +", lon="+ lon +", fixed=0");
ps6.executeUpdate();
}
}
}
}
 
/**
* <gml:Point gml:id="n1">
* <gml:pos>35.14591397 139.10569573</gml:pos>
* </gml:Point>
*
* @param con
* @param node
* @param areacode
* @throws IOException
* @throws SQLException
*/
public static void showGmlPoint(Connection con, Node node, int areacode) throws IOException, SQLException {
String positionStr = "";
String latStr = "";
String lonStr = "";
String idStr = "";
 
NamedNodeMap nodeMap = node.getAttributes();
if ( null != nodeMap ) {
for ( int j=0; j<nodeMap.getLength(); j++ ) {
if (nodeMap.item(j).getNodeName().equals("gml:id")) {
idStr = nodeMap.item(j).getNodeValue();
}
}
}
 
NodeList nodes = node.getChildNodes();
for (int i=0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("gml:pos")) {
positionStr = node2.getTextContent().trim();
String[] str4Ary = positionStr.split(" ");
latStr = str4Ary[0];
lonStr = str4Ary[1];
 
try (PreparedStatement ps6 = con.prepareStatement("INSERT INTO bus_stop (lat,lon,fixed, area,idref) VALUES (?,?,?,?,?)")) {
double lat = Double.parseDouble(latStr);
double lon = Double.parseDouble(lonStr);
System.out.println("INSERT INTO bus_stop (lat,lon,fixed,area, idref) VALUES ('"+ latStr +"','"+ lonStr +"','0',"+ areacode +",'"+ idStr +"')");
ps6.setDouble(1, lat);
ps6.setDouble(2, lon);
ps6.setInt(3, 0);
ps6.setInt(4, areacode);
ps6.setString(5, idStr);
ps6.executeUpdate();
}
}
}
}
/**
* 'table.BUS_STOP'を新規に作る
* 既にテーブルが存在する時には何もしない
* @param conHsql
}
}
}
/**
* HSQLDB: "SELECT idref,area,fixed,lat,lon FROM FUEL"
* POSTGIS "insert into t_FUEL(idref,fixed,area,geom) VALUES('n000001',0,0, ST_GeomFromText('POINT(136.9695284611471 35.10300377075564)', 4612));"
*
* @param conHsql
* @param conPost
* @throws java.io.FileNotFoundException
* @throws java.lang.ClassNotFoundException
* @throws java.sql.SQLException
* @throws java.io.IOException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException
*/
public static void transport (Connection conHsql, Connection conPost) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
try (PreparedStatement ps1 = conPost.prepareStatement("SELECT gid,name,area,fixed,ST_Y(geom) AS lat,ST_X(geom) AS lon FROM t_busstop")) {
try (ResultSet rset1 = ps1.executeQuery()) {
while (rset1.next()) {
long gid = rset1.getLong("gid");
String name = rset1.getString("name");
int area = rset1.getInt("area");
int fixed = rset1.getInt("fixed");
double lat = rset1.getDouble("lat");
double lon = rset1.getDouble("lon");
String sqlStr = "INSERT INTO bus_stop (gid,lat,lon,fixed,idref,area,up,fixed1) VALUES(?,?,?,?,?,?,0,0)";
try (PreparedStatement ps = conHsql.prepareStatement(sqlStr)) {
ps.setLong(1, gid);
ps.setString(2, BigDecimal.valueOf(lat).toPlainString());
ps.setString(3, BigDecimal.valueOf(lon).toPlainString());
ps.setInt(4, fixed);
ps.setString(5, idref);
ps.setInt(6, area);
System.out.println(sqlStr);
ps.executeUpdate();
}
}
}
}
}
 
 
/**
* 'table.BUS_STOP'の内容をCSV形式にして標準出力に出力する
* @param con
*/
}
if (!name.toUpperCase().endsWith(".XML")) {
return false;
}
if (Integer.parseInt(name.substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)) == areacode) {
return true;
}
return false;
return Integer.parseInt(name.substring(GML_DIR_PREFIX.length(), GML_DIR_PREFIX.length()+2)) == areacode;
}
/**
* 数値地図情報のデータディレクトリかどうかを見極める
String name = f.getName();
if (!name.startsWith(GML_DIR_PREFIX)) {
return false;
}
if (!name.toUpperCase().endsWith(GML_DIR_PRIFIX)) {
return false;
}
return true;
return name.toUpperCase().endsWith(GML_DIR_PRIFIX);
}
 
public static final String GML_DIR_PREFIX = "P11-10_";
public static final String GML_DIR_PRIFIX = "_GML";