rework database routine
This commit is contained in:
parent
72195d3b4c
commit
f702100e8a
1 changed files with 42 additions and 66 deletions
|
@ -17,6 +17,7 @@ import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import btools.expressions.BExpressionContextNode;
|
import btools.expressions.BExpressionContextNode;
|
||||||
|
@ -40,22 +41,16 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
|
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
// PreparedStatement psNoise = null;
|
|
||||||
// PreparedStatement psRiver = null;
|
|
||||||
// PreparedStatement psForest = null;
|
|
||||||
PreparedStatement psAllTags = null;
|
PreparedStatement psAllTags = null;
|
||||||
|
|
||||||
ResultSet rsBrouter = null;
|
ResultSet rsBrouter = null;
|
||||||
|
|
||||||
int cntHighways = 0;
|
int cntHighways = 0;
|
||||||
int cntWayModified = 0;
|
int cntWayModified = 0;
|
||||||
int cntNewNoise = 0;
|
|
||||||
int cntNewRiver = 0;
|
|
||||||
int cntNewForest = 0;
|
|
||||||
int cntNewTown = 0;
|
|
||||||
int cntNewTraffic = 0;
|
|
||||||
|
|
||||||
String jdbcurl;
|
String jdbcurl;
|
||||||
|
Map<String, String> databaseField2Tag;
|
||||||
|
Map<String, Integer> databaseFieldsFound;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.println("*** OsmCutter: cut an osm map in node-tiles + a way file");
|
System.out.println("*** OsmCutter: cut an osm map in node-tiles + a way file");
|
||||||
|
@ -79,9 +74,6 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
private BExpressionContextWay _expctxWay;
|
private BExpressionContextWay _expctxWay;
|
||||||
private BExpressionContextNode _expctxNode;
|
private BExpressionContextNode _expctxNode;
|
||||||
|
|
||||||
// private BExpressionContextWay _expctxWayStat;
|
|
||||||
// private BExpressionContextNode _expctxNodeStat;
|
|
||||||
|
|
||||||
public void process(File lookupFile, File outTileDir, File wayFile, File relFile, File resFile, File profileFile, File mapFile) throws Exception {
|
public void process(File lookupFile, File outTileDir, File wayFile, File relFile, File resFile, File profileFile, File mapFile) throws Exception {
|
||||||
if (!lookupFile.exists()) {
|
if (!lookupFile.exists()) {
|
||||||
throw new IllegalArgumentException("lookup-file: " + lookupFile + " does not exist");
|
throw new IllegalArgumentException("lookup-file: " + lookupFile + " does not exist");
|
||||||
|
@ -94,10 +86,6 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
meta.readMetaData(lookupFile);
|
meta.readMetaData(lookupFile);
|
||||||
_expctxWay.parseFile(profileFile, "global");
|
_expctxWay.parseFile(profileFile, "global");
|
||||||
|
|
||||||
|
|
||||||
// _expctxWayStat = new BExpressionContextWay( null );
|
|
||||||
// _expctxNodeStat = new BExpressionContextNode( null );
|
|
||||||
|
|
||||||
this.outTileDir = outTileDir;
|
this.outTileDir = outTileDir;
|
||||||
if (!outTileDir.isDirectory())
|
if (!outTileDir.isDirectory())
|
||||||
throw new RuntimeException("out tile directory " + outTileDir + " does not exist");
|
throw new RuntimeException("out tile directory " + outTileDir + " does not exist");
|
||||||
|
@ -195,6 +183,7 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
|
|
||||||
if (jdbcurl == null) return;
|
if (jdbcurl == null) return;
|
||||||
|
|
||||||
|
try {
|
||||||
// is the database allready connected?
|
// is the database allready connected?
|
||||||
if (conn == null) {
|
if (conn == null) {
|
||||||
|
|
||||||
|
@ -202,29 +191,30 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
|
|
||||||
System.out.println("OsmCutter start connection to the database........" + jdbcurl);
|
System.out.println("OsmCutter start connection to the database........" + jdbcurl);
|
||||||
|
|
||||||
try {
|
|
||||||
conn = DriverManager.getConnection(jdbcurl);
|
conn = DriverManager.getConnection(jdbcurl);
|
||||||
psAllTags = conn.prepareStatement(sql_all_tags);
|
psAllTags = conn.prepareStatement(sql_all_tags);
|
||||||
|
|
||||||
|
databaseField2Tag = new HashMap<>();
|
||||||
|
databaseField2Tag.put("noise_class", "estimated_noise_class");
|
||||||
|
databaseField2Tag.put("river_class", "estimated_river_class");
|
||||||
|
databaseField2Tag.put("forest_class", "estimated_forest_class");
|
||||||
|
databaseField2Tag.put("town_class", "estimated_town_class");
|
||||||
|
databaseField2Tag.put("traffic_class", "estimated_traffic_class");
|
||||||
|
|
||||||
|
databaseFieldsFound = new HashMap<>();
|
||||||
|
for (String key : databaseField2Tag.keySet()) {
|
||||||
|
databaseFieldsFound.put(key, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
System.out.println("OsmCutter connect to the database ok........");
|
System.out.println("OsmCutter connect to the database ok........");
|
||||||
|
|
||||||
} catch (SQLException g) {
|
|
||||||
System.out.format("Osm Cutter SQL State: %s\n%s\n", g.getSQLState(), g.getMessage());
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
} catch (Exception f) {
|
|
||||||
f.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, String> e : map.entrySet()) {
|
for (Map.Entry<String, String> e : map.entrySet()) {
|
||||||
if (e.getKey().equals("highway")) {
|
if (e.getKey().equals("highway")) {
|
||||||
cntHighways = cntHighways + 1;
|
cntHighways = cntHighways + 1;
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
psAllTags.setLong(1, osm_id);
|
psAllTags.setLong(1, osm_id);
|
||||||
|
|
||||||
// process the results
|
// process the results
|
||||||
|
@ -233,33 +223,23 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
if (rsBrouter.next()) {
|
if (rsBrouter.next()) {
|
||||||
|
|
||||||
cntWayModified = cntWayModified + 1;
|
cntWayModified = cntWayModified + 1;
|
||||||
if (rsBrouter.getString("noise_class") != null) {
|
for (String key : databaseField2Tag.keySet()) {
|
||||||
map.put("estimated_noise_class", rsBrouter.getString("noise_class"));
|
if (rsBrouter.getString(key) != null) {
|
||||||
cntNewNoise = cntNewNoise + 1;
|
map.put(databaseField2Tag.get(key), rsBrouter.getString(key));
|
||||||
|
databaseFieldsFound.put(key, databaseFieldsFound.get(key) + 1);
|
||||||
}
|
}
|
||||||
if (rsBrouter.getString("river_class") != null) {
|
|
||||||
map.put("estimated_river_class", rsBrouter.getString("river_class"));
|
|
||||||
cntNewRiver = cntNewRiver + 1;
|
|
||||||
}
|
}
|
||||||
if (rsBrouter.getString("forest_class") != null) {
|
|
||||||
map.put("estimated_forest_class", rsBrouter.getString("forest_class"));
|
|
||||||
cntNewForest = cntNewForest + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsBrouter.getString("town_class") != null) {
|
|
||||||
map.put("estimated_town_class", rsBrouter.getString("town_class"));
|
|
||||||
cntNewTown = cntNewTown + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rsBrouter.getString("traffic_class") != null) {
|
|
||||||
map.put("estimated_traffic_class", rsBrouter.getString("traffic_class"));
|
|
||||||
cntNewTraffic = cntNewTraffic + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if ((cntHighways % 100000) == 0) {
|
if ((cntHighways % 100000) == 0) {
|
||||||
System.out.print("HW processed=" + cntHighways + " HW modifs=" + cntWayModified + " NoiseTags=" + cntNewNoise);
|
String out = "HW processed=" + cntHighways + " HW modifs=" + cntWayModified;
|
||||||
System.out.println(" RiverTags=" + cntNewRiver + " ForestTags=" + cntNewForest + " TownTags=" + cntNewTown + " TrafficTags=" + cntNewTraffic);
|
for (String key : databaseFieldsFound.keySet()) {
|
||||||
|
out += " " + key + "=" + databaseFieldsFound.get(key);
|
||||||
|
}
|
||||||
|
System.out.println(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException g) {
|
} catch (SQLException g) {
|
||||||
|
@ -269,10 +249,6 @@ public class OsmCutter extends MapCreatorBase {
|
||||||
f.printStackTrace();
|
f.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue