From 9c025e291343b88846629508a12dc9b160754fe2 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 22 Dec 2016 01:34:22 +0100 Subject: [PATCH] Update srtm data --- .../net/osmand/binary/BinaryInspector.java | 9 +- .../src/net/osmand/router/GeneralRouter.java | 3 +- .../osmand/router/RouteResultPreparation.java | 3 +- .../net/osmand/router/RouteSegmentResult.java | 82 +++++++++++++++++++ .../src/net/osmand/util/Algorithms.java | 11 +++ 5 files changed, 102 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index ef9ccd4a7d..754f1be034 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -74,14 +74,15 @@ public class BinaryInspector { in.inspector(new String[] { // "-vpoi", // "-vmap", "-vmapobjects", // "-vmapcoordinates", -// "-vrouting", - "-vtransport", + "-vrouting", +// "-vtransport", // "-vaddress", "-vcities","-vstreetgroups", // "-vstreets", "-vbuildings", "-vintersections", // "-lang=ru", -// "-bbox=4.8486,52.3084,4.8747,52.2970", -// "-osm="+System.getProperty("maps.dir")+"/map.obf.osm", +// "-bbox=30.4981,50.4424,30.5195,50.4351", +// "-osm="+System.getProperty("maps.dir")+"/map.obf.osm", System.getProperty("maps.dir")+"/Map.obf" +// System.getProperty("maps.dir")+"/Ukraine_kiev-city_europe.obf" }); } else { in.inspector(args); diff --git a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java index 2203b89d62..a497b57c9d 100644 --- a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java @@ -62,7 +62,8 @@ public class GeneralRouter implements VehicleRouter { OBSTACLES("obstacle_time"), ROUTING_OBSTACLES("obstacle"), ONEWAY("oneway"), - PENALTY_TRANSITION("penalty_transition"); + PENALTY_TRANSITION("penalty_transition"), + OBSTACLE_SRTM_ALT_SPEED("obstacle_srtm_alt_speed"); public final String nm; RouteDataObjectAttribute(String name) { nm = name; diff --git a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java index 57d34b167b..82a6110dee 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java +++ b/OsmAnd-java/src/net/osmand/router/RouteResultPreparation.java @@ -360,6 +360,7 @@ public class RouteResultPreparation { } additional.append("start_bearing = \"").append(res.getBearingBegin()).append("\" "); additional.append("end_bearing = \"").append(res.getBearingEnd()).append("\" "); + additional.append("height = \"").append(Arrays.toString(res.getHeightValues())).append("\" "); additional.append("description = \"").append(res.getDescription()).append("\" "); println(MessageFormat.format("\t", (res.getObject().getId() >> (BinaryInspector.SHIFT_ID )) + "", res.getObject().getId() + "", @@ -378,7 +379,7 @@ public class RouteResultPreparation { int[] pointNameTypes = res.getObject().getPointNameTypes(k); if (tp != null || pointNameTypes != null) { StringBuilder bld = new StringBuilder(); - bld.append(" 0) { + double dd = MapUtils.getDistance(plat, plon, lat, lon); + int height = HEIGHT_UNDEFINED; + if(k == object.getPointsLength() - 1) { + height = endHeight; + } else { + int[] tps = object.getPointTypes(k); + if (tps != null) { + for (int id : tps) { + RouteTypeRule rt = object.region.quickGetEncodingRule(id); + if (rt.getTag().equals("osmand_ele_asc")) { + height = (int) (prevHeight + Float.parseFloat(rt.getValue())); + break; + } else if (rt.getTag().equals("osmand_ele_desc")) { + height = (int) (prevHeight - Float.parseFloat(rt.getValue())); + break; + } + } + } + } + pf[2*k] = (float) dd; + pf[2*k+1] = height; + if(height != HEIGHT_UNDEFINED) { + // interpolate undefined + double totalDistance = dd; + int startUndefined = k; + while(startUndefined - 1 >= 0 && pf[2*(startUndefined - 1)+1] == HEIGHT_UNDEFINED) { + startUndefined --; + totalDistance += pf[2*(startUndefined)]; + } + if(totalDistance > 0) { + double angle = (height - prevHeight) / totalDistance; + for(int j = startUndefined; j < k; j++) { + pf[2*j+1] = (float) ((pf[2*j] * angle) + pf[2*j-1]); + } + } + prevHeight = height; + } + + } else { + pf[0] = 0; + pf[1] = startHeight; + } + plat = lat; + plon = lon; + } + boolean reverse = startPointIndex > endPointIndex; + int st = Math.min(startPointIndex, endPointIndex); + int end = Math.max(startPointIndex, endPointIndex); + + float[] res = new float[(end - st + 1) * 2]; + for (int k = 0; k < res.length / 2; k++) { + if (k == 0) { + res[2 * k] = 0; + } else { + res[2 * k] = pf[reverse ? (2 * (end - k)) : (2 * (k + st))]; + } + res[2 * k + 1] = pf[reverse ? (2 * (end - k) + 1) : (2 * (k + st) + 1)]; + } + return res; + } + @SuppressWarnings("unchecked") private void updateCapacity() { diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 1ae2a1d07f..97dd1bdd16 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -70,6 +70,17 @@ public class Algorithms { } return def; } + + public static int parseIntSilently(String input, int def) { + if (input != null && input.length() > 0) { + try { + return Integer.parseInt(input); + } catch (NumberFormatException e) { + return def; + } + } + return def; + } public static String getFileNameWithoutExtension(File f) {