Class HttpPOST をabstractに変更
1 parent df761e7 commit a719eb52ca1a0386962e05edec62b391bc81bf98
@hayashi hayashi authored on 18 Nov 2017
Showing 7 changed files
View
0
■■■■■
src/fuel.activity.violet.html
Too large (Show diff)
View
357
src/osm/jp/api/HttpPOST.java
* Java HTTP クライアントサンプル - HttpURLConnection 版 -
*
* @author 68user http://X68000.q-e-d.net/~68user/
*/
public class HttpPOST {
public abstract class HttpPOST {
//public static String host = "http://api06.dev.openstreetmap.org";
//public static String host = "http://api.openstreetmap.org";
public static String host = "http://overpass-api.de";
public static final String EXIST_FILE = "exist.osm.xml";
public static final String TABLE_NAME = "OSM_EXIST";
 
/*
public static void main(String[] args) throws MalformedURLException, ProtocolException, IOException {
double minlat = 35.13d;
double maxlat = 35.66d;
double minlon = 138.99d;
//getCapabilities(new File("output.xml"), "public_transport", "platform", minlat, maxlat, minlon, maxlon);
getCapabilities("public_transport", "stop_position", minlat, maxlat, minlon, maxlon, "node");
getCapabilities("amenity", "fuel", minlat, maxlat, minlon, maxlon, "way");
}
*/
/**
* 'HSQLDB.table.OSM_EXIST'を新規に作る
* 'HSQLDB.table.AREA_NODE'を新規に作る
}
}
}
 
/*
*/
public static void getCapabilities(String key, String value, double minLat, double maxLat, double minLon, double maxLon) throws MalformedURLException, ProtocolException, IOException {
getCapabilities(key, value, minLat, maxLat, minLon, maxLon, "node");
}
 
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
*/
public static void readExistingFile (Connection con, int point) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
int iCounter = 0;
public void readExistingFile (Connection con, int point) throws FileNotFoundException, ClassNotFoundException, SQLException, IOException, ParserConfigurationException, SAXException {
 
DocumentBuilderFactory factory;
DocumentBuilder builder;
 
iCounter = 0;
factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
factory.setIgnoringElementContentWhitespace(true);
factory.setIgnoringComments(true);
 
Node root = builder.parse(new File(HttpPOST.EXIST_FILE));
 
readAreaNodes(con, root);
iCounter += readExistingNodes(con, root, point);
int iCounter = readExistingNodes(con, root, point);
System.out.println("既存ノード数["+ iCounter +"]");
}
static int readAreaNodes(Connection con, Node node) throws IOException, SQLException {
public int readAreaNodes(Connection con, Node node) throws IOException, SQLException {
int iCounter = 0;
 
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
}
return iCounter;
}
static void importAreaNode(Connection con, Node node) throws IOException, SQLException {
public void importAreaNode(Connection con, Node node) throws IOException, SQLException {
String idrefStr = "";
String latStr = "";
String lonStr = "";
 
}
}
}
 
static int readExistingNodes(Connection con, Node node, int point) throws IOException, SQLException {
public int readExistingNodes(Connection con, Node node, int point) throws IOException, SQLException {
int iCounter = 0;
 
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
}
return iCounter;
}
 
static void importExistingArea(Connection con, Node node, int point) throws IOException, SQLException {
public void importExistingNode(Connection con, Node node, int point) throws IOException, SQLException {
String idrefStr = "";
double maxlat = -90.0D;
double maxlon = -180.0D;
double minlat = 90.0D;
double minlon = 180.0D;
String latStr = "";
String lonStr = "";
String brandStr = "";
String nameStr = "";
String brandStr = "";
String fixmeStr = "";
int score = 0;
 
NamedNodeMap nodeMap = node.getAttributes();
if (nodeMap != null) {
for (int j=0; j < nodeMap.getLength(); j++) {
switch (nodeMap.item(j).getNodeName()) {
case "id":
idrefStr = nodeMap.item(j).getNodeValue();
break;
case "lat":
latStr = nodeMap.item(j).getNodeValue();
break;
case "lon":
lonStr = nodeMap.item(j).getNodeValue();
break;
default:
break;
}
}
 
NodeList nodes = node.getChildNodes();
if (nodes.getLength() == 0) {
return;
}
for (int i = 0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("tag")) {
OsmnodeTag tagnode = new OsmnodeTag(node2);
String value = null;
value = tagnode.getValue("brand");
String value = tagnode.getValue("brand");
if (value != null) {
brandStr = value;
}
value = tagnode.getValue("name");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("name:ja");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("name");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("fixme");
if (value != null) {
fixmeStr = value;
}
}
else if (node2.getNodeName().equals("nd")) {
OsmnodeNd ndnode = new OsmnodeNd(node2);
String ref = ndnode.getRef();
Position pos = getNdPosition(con, ref);
if (pos != null) {
minlat = (pos.lat < minlat ? pos.lat : minlat);
minlon = (pos.lon < minlon ? pos.lon : minlon);
maxlat = (pos.lat > maxlat ? pos.lat : maxlat);
maxlon = (pos.lon > maxlon ? pos.lon : maxlon);
}
}
}
if ((maxlat != -90.0D) && (maxlon != -180.0D) && (minlon != 180.0D) && (minlat != 90.0D)) {
double lat = (maxlat + minlat) / 2;
double lon = (maxlon + minlon) / 2;
 
score = 50;
if (((point & POINT_NAME) != 0) && nameStr.equals("")) {
score = 1;
}
if (((point & POINT_BRAND) != 0) && brandStr.equals("")) {
score = 1;
}
if (((point & POINT_FIXME) != 0) && !fixmeStr.equals("")) {
score = 1;
}
 
// idref と nameStr をデータベースに格納する
System.out.println("INSERT INTO "+ TABLE_NAME +" (idref,lat,lon,score,name) VALUES("+ idrefStr +","+ lat +","+ lon+","+ Integer.toString(score) +",'"+ nameStr +"');");
try (PreparedStatement ps5 = con.prepareStatement("INSERT INTO "+ TABLE_NAME +" (idref,lat,lon,score,name) VALUES (?,?,?,?,?)")) {
ps5.setString(1, idrefStr);
ps5.setDouble(2, lat);
ps5.setDouble(3, lon);
ps5.setInt(4, score);
ps5.setString(5, nameStr);
ps5.executeUpdate();
}
catch (HsqlException | SQLIntegrityConstraintViolationException e) {
// integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
// [HsqlException]は、無視する
// integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
// [SQLIntegrityConstraintViolationException]は、無視する
}
}
}
}
 
static void importExistingNode(Connection con, Node node, int point) throws IOException, SQLException {
String idrefStr = "";
String latStr = "";
String lonStr = "";
String brandStr = "";
String nameStr = "";
String fixmeStr = "";
int score = 0;
 
NamedNodeMap nodeMap = node.getAttributes();
if (nodeMap != null) {
for (int j=0; j < nodeMap.getLength(); j++) {
switch (nodeMap.item(j).getNodeName()) {
case "id":
idrefStr = nodeMap.item(j).getNodeValue();
break;
case "lat":
latStr = nodeMap.item(j).getNodeValue();
break;
case "lon":
lonStr = nodeMap.item(j).getNodeValue();
break;
default:
break;
}
}
 
NodeList nodes = node.getChildNodes();
if (nodes.getLength() == 0) {
return;
}
for (int i = 0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("tag")) {
OsmnodeTag tagnode = new OsmnodeTag(node2);
String value = null;
value = tagnode.getValue("brand");
if (value != null) {
brandStr = value;
}
value = tagnode.getValue("name");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("name:ja");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("fixme");
if (value != null) {
fixmeStr = value;
}
}
}
 
score = 50;
if (((point & POINT_NAME) != 0) && nameStr.equals("")) {
}
 
int score = 50;
if (((point & POINT_BRAND) != 0) && brandStr.equals("")) {
score = 1;
}
if (((point & POINT_BRAND) != 0) && brandStr.equals("")) {
if (((point & POINT_NAME) != 0) && brandStr.equals("")) {
score = 1;
}
if (((point & POINT_FIXME) != 0) && !fixmeStr.equals("")) {
score = 1;
// [SQLIntegrityConstraintViolationException]は、無視する
}
}
}
 
public void importExistingArea(Connection con, Node node, int point) throws IOException, SQLException {
String idrefStr = "";
double maxlat = -90.0D;
double maxlon = -180.0D;
double minlat = 90.0D;
double minlon = 180.0D;
String nameStr = "";
String brandStr = "";
String fixmeStr = "";
 
NamedNodeMap nodeMap = node.getAttributes();
if (nodeMap != null) {
for (int j=0; j < nodeMap.getLength(); j++) {
switch (nodeMap.item(j).getNodeName()) {
case "id":
idrefStr = nodeMap.item(j).getNodeValue();
break;
default:
break;
}
}
 
NodeList nodes = node.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node2 = nodes.item(i);
if (node2.getNodeName().equals("tag")) {
OsmnodeTag tagnode = new OsmnodeTag(node2);
String value = tagnode.getValue("brand");
if (value != null) {
brandStr = value;
}
value = tagnode.getValue("name:ja");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("name");
if (value != null) {
nameStr = value;
}
value = tagnode.getValue("fixme");
if (value != null) {
fixmeStr = value;
}
}
else if (node2.getNodeName().equals("nd")) {
OsmnodeNd ndnode = new OsmnodeNd(node2);
String ref = ndnode.getRef();
Position pos = getNdPosition(con, ref);
if (pos != null) {
minlat = (pos.lat < minlat ? pos.lat : minlat);
minlon = (pos.lon < minlon ? pos.lon : minlon);
maxlat = (pos.lat > maxlat ? pos.lat : maxlat);
maxlon = (pos.lon > maxlon ? pos.lon : maxlon);
}
}
}
if ((maxlat != -90.0D) && (maxlon != -180.0D) && (minlon != 180.0D) && (minlat != 90.0D)) {
double lat = (maxlat + minlat) / 2;
double lon = (maxlon + minlon) / 2;
int score = 50;
 
if (((point & POINT_BRAND) != 0) && brandStr.equals("")) {
score = 1;
}
if (((point & POINT_NAME) != 0) && nameStr.equals("")) {
score = 1;
}
if (((point & POINT_FIXME) != 0) && !fixmeStr.equals("")) {
score = 1;
}
 
// idref と nameStr をデータベースに格納する
System.out.println("INSERT INTO "+ TABLE_NAME +" (idref,lat,lon,score,name) VALUES("+ idrefStr +","+ lat +","+ lon+","+ Integer.toString(score) +",'"+ nameStr +"');");
try (PreparedStatement ps5 = con.prepareStatement("INSERT INTO "+ TABLE_NAME +" (idref,lat,lon,score,name) VALUES (?,?,?,?,?)")) {
ps5.setString(1, idrefStr);
ps5.setDouble(2, lat);
ps5.setDouble(3, lon);
ps5.setInt(4, score);
ps5.setString(5, nameStr);
ps5.executeUpdate();
}
catch (HsqlException | SQLIntegrityConstraintViolationException e) {
// integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
// [HsqlException]は、無視する
// integrity constraint violation: unique constraint or index violation; SYS_PK_10069 table: FUEL_EXIST
// [SQLIntegrityConstraintViolationException]は、無視する
}
}
}
}
public static Position getNdPosition(Connection con, String idref) throws SQLException {
PreparedStatement ps8 = con.prepareStatement("SELECT lat,lon FROM AREA_NODE where idref=?");
ps8.setString(1, idref);
View
src/osm/jp/coverage/busstop/DbExistBusstop.java
View
src/osm/jp/coverage/busstop/NagoyaBusstop.java
View
src/osm/jp/coverage/fuel/DbExist.java
View
src/osm/jp/coverage/fuel/Fuel.java
View
src/osm/jp/coverage/test/DbExistTest.java