diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/DatabasePseudoTagProvider.java b/brouter-map-creator/src/main/java/btools/mapcreator/DatabasePseudoTagProvider.java index d43091b..0e9ba4f 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/DatabasePseudoTagProvider.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/DatabasePseudoTagProvider.java @@ -90,7 +90,69 @@ public class DatabasePseudoTagProvider { } } - public DatabasePseudoTagProvider(String filename) { + public DatabasePseudoTagProvider(String filename, String jdbcurl) { + if (filename != null) doFileImport(filename); + if (jdbcurl != null) doDatabaseImport(jdbcurl); + } + + private void doDatabaseImport(String jdbcurl) { + + try (Connection conn = DriverManager.getConnection(jdbcurl)) { + + System.out.println("DatabasePseudoTagProvider reading from database: " + jdbcurl); + conn.setAutoCommit(false); + + + Map, Map> mapUnifier = new HashMap<>(); + CompactLongMap> data = new CompactLongMap<>(); + + String sql_all_tags = "SELECT * from all_tags"; + try(PreparedStatement psAllTags = conn.prepareStatement(sql_all_tags)) { + + psAllTags.setFetchSize(100); + + // process the results + ResultSet rs = psAllTags.executeQuery(); + + long dbRows = 0L; + while (rs.next()) { + long osm_id = rs.getLong("losmid"); + Map row = new HashMap<>(5); + addDBTag(row, rs, "noise_class"); + addDBTag(row, rs, "river_class"); + addDBTag(row, rs, "forest_class"); + addDBTag(row, rs, "town_class"); + addDBTag(row, rs, "traffic_class"); + + // apply the instance-unifier for the row-map + Map knownRow = mapUnifier.get(row); + if (knownRow != null) { + row = knownRow; + } else { + mapUnifier.put(row, row); + } + data.put(osm_id, row); + dbRows++; + if (dbRows % 1000000L == 0L) { + System.out.println(".. from database: rows =" + dbRows); + } + } + System.out.println("freezing result map.."); + dbData = new FrozenLongMap<>(data); + System.out.println("read from database: rows =" + dbData.size() + " unique rows=" + mapUnifier.size()); + } + + } catch (SQLException g) { + System.err.format("DatabasePseudoTagProvider execute sql .. SQL State: %s\n%s\n", g.getSQLState(), g.getMessage()); + System.exit(1); + } catch (Exception f) { + f.printStackTrace(); + System.exit(1); + } + + } + + private void doFileImport(String filename) { try (BufferedReader br = new BufferedReader(new InputStreamReader( filename.endsWith(".gz") ? new GZIPInputStream(new FileInputStream(filename)) : new FileInputStream(filename)))) { @@ -158,12 +220,22 @@ public class DatabasePseudoTagProvider { return l; } - private static void addTag(Map row, String s, String name) { + private static void addTag(Map row, String s, String name) { if (!s.isEmpty()) { row.put(name, s); } } + private static void addDBTag(Map row, ResultSet rs, String name) { + String v = null; + try { + v = rs.getString(name); + } catch (Exception e) {} + if (v != null) { + row.put("estimated_" + name, v); + } + } + public void addTags(long osm_id, Map map) { if (map == null || !map.containsKey("highway")) { @@ -194,6 +266,6 @@ public class DatabasePseudoTagProvider { pseudoTagsFound.put(key, cnt + 1L); } } - - + + } diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java b/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java index 26de826..60f58e0 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/OsmCutter.java @@ -113,7 +113,11 @@ public class OsmCutter extends MapCreatorBase { } public void setDbTagFilename(String filename) { - dbPseudoTagProvider = new DatabasePseudoTagProvider(filename); + dbPseudoTagProvider = new DatabasePseudoTagProvider(filename, null); + } + + public void setDbTagDatabase(String jdbcurl) { + dbPseudoTagProvider = new DatabasePseudoTagProvider(null, jdbcurl); } @Override diff --git a/brouter-map-creator/src/main/java/btools/mapcreator/OsmFastCutter.java b/brouter-map-creator/src/main/java/btools/mapcreator/OsmFastCutter.java index cf843ca..fe67ee3 100644 --- a/brouter-map-creator/src/main/java/btools/mapcreator/OsmFastCutter.java +++ b/brouter-map-creator/src/main/java/btools/mapcreator/OsmFastCutter.java @@ -13,7 +13,7 @@ public class OsmFastCutter extends MapCreatorBase { public static void main(String[] args) throws Exception { System.out.println("*** OsmFastCutter: cut an osm map in node-tiles + way-tiles"); if (args.length != 11 && args.length != 12 && args.length != 13) { - String common = "java OsmFastCutter [db-tag-filename]"; + String common = "java OsmFastCutter [db-tag-filename | db-tag-jdbcurl]"; System.out.println("usage: bzip2 -dc | " + common); System.out.println("or : " + common + " "); @@ -37,10 +37,16 @@ public class OsmFastCutter extends MapCreatorBase { ); } - public static void doCut(File lookupFile, File nodeDir, File wayDir, File node55Dir, File way55Dir, File borderFile, File relFile, File resFile, File profileAll, File profileReport, File profileCheck, File mapFile, String dbTagFilename) throws Exception { + public static void doCut(File lookupFile, File nodeDir, File wayDir, File node55Dir, File way55Dir, File borderFile, File relFile, File resFile, File profileAll, File profileReport, File profileCheck, File mapFile, String dbTagInfo) throws Exception { // **** run OsmCutter **** OsmCutter cutter = new OsmCutter(); - if (dbTagFilename != null) cutter.setDbTagFilename(dbTagFilename); + if (dbTagInfo != null) { + if (dbTagInfo.toLowerCase().startsWith("jdbc")) { + cutter.setDbTagDatabase(dbTagInfo); + } else { + cutter.setDbTagFilename(dbTagInfo); + } + } // ... inject WayCutter cutter.wayCutter = new WayCutter(); diff --git a/brouter-util/src/main/java/btools/util/StackSampler.java b/brouter-util/src/main/java/btools/util/StackSampler.java index 53c5db6..ed35b81 100644 --- a/brouter-util/src/main/java/btools/util/StackSampler.java +++ b/brouter-util/src/main/java/btools/util/StackSampler.java @@ -47,6 +47,7 @@ public class StackSampler extends Thread { } } + @SuppressWarnings({"deprecation", "RedundantSuppression"}) // Android public void dumpThreads() { try { int wait1 = rand.nextInt(interval); diff --git a/build.gradle b/build.gradle index 6fd211e..3a04e6c 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:8.10.1' + classpath 'com.android.tools.build:gradle:8.11.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/buildSrc/src/main/groovy/brouter.library-conventions.gradle b/buildSrc/src/main/groovy/brouter.library-conventions.gradle index 3fd5d46..3c48b70 100644 --- a/buildSrc/src/main/groovy/brouter.library-conventions.gradle +++ b/buildSrc/src/main/groovy/brouter.library-conventions.gradle @@ -16,6 +16,8 @@ publishing { } } publications { - gpr(MavenPublication) + gpr(MavenPublication) { + from components.java + } } } diff --git a/misc/profiles2/trekking.brf b/misc/profiles2/trekking.brf index bc10708..570a883 100644 --- a/misc/profiles2/trekking.brf +++ b/misc/profiles2/trekking.brf @@ -247,10 +247,10 @@ assign costfactor if ( and highway= not route=ferry ) then 10000 # - # exclude motorways and proposed roads + # exclude motorways and proposed, abandoned under construction roads # - else if ( highway=motorway|motorway_link ) then 10000 - else if ( highway=proposed|abandoned ) then 10000 + else if ( highway=motorway|motorway_link ) then 10000 + else if ( highway=proposed|abandoned|construction ) then 10000 # # all other exclusions below (access, steps, ferries,..)