From 616f589e060e37e3196d394b9c299845004f60ea Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 28 Jul 2016 01:09:45 +0200 Subject: [PATCH 1/2] Add option to print basic road info --- .../net/osmand/binary/BinaryInspector.java | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index c2edd50767..f759486d44 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -70,15 +70,15 @@ public class BinaryInspector { // test cases show info if ("test".equals(args[0])) { in.inspector(new String[]{ - "-vpoi", - "-vmap", "-vmapobjects", // "-vmapcoordinates", +// "-vpoi", +// "-vmap", "-vmapobjects", // "-vmapcoordinates", "-vrouting", - "-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" - System.getProperty("maps.dir")+"/Netherlands_noord-holland_europe.obf" +// "-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", + System.getProperty("maps.dir")+"/Map.obf" }); } else { in.inspector(args); @@ -532,14 +532,38 @@ public class BinaryInspector { MapUtils.get31TileNumberX(vInfo.lonright), MapUtils.get31TileNumberY(vInfo.lattop), MapUtils.get31TileNumberY(vInfo.latbottom), vInfo.getZoom(), null), p.getSubregions()); + if (vInfo.osm) { + printToFile("\n" + + "\n"); + } index.loadRouteIndexData(regions, new ResultMatcher() { @Override public boolean publish(RouteDataObject obj) { mapObjectsCounter.value++; + if (vInfo.osm) { + b.setLength(0); + BinaryMapDataObject bobj = new BinaryMapDataObject(); + bobj.setArea(false); + bobj.coordinates = new int[obj.pointsX.length * 2]; + for(int i = 0; i < obj.pointsX.length; i++) { + bobj.coordinates[2*i] = obj.pointsX[i]; + bobj.coordinates[2*i +1] = obj.pointsY[i]; + } + bobj.types = obj.types; + bobj.setId(obj.getId() << 1); + bobj.objectNames = obj.getNames(); + printOsmMapDetails(bobj, b, obj.region); + try { + printToFile(b.toString()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } b.setLength(0); b.append("Road "); b.append(obj.id); b.append(" osmid ").append(obj.getId() >> (SHIFT_ID)); + for (int i = 0; i < obj.getTypes().length; i++) { RouteTypeRule rr = obj.region.quickGetEncodingRule(obj.getTypes()[i]); b.append(" ").append(rr.getTag()).append("='").append(rr.getValue()).append("'"); @@ -559,7 +583,7 @@ public class BinaryInspector { int[] nametypes = obj.getPointNameTypes(i); int[] types = obj.getPointTypes(i); if (types != null || names != null) { - b.append(" [ " + (i + 1) + ". "); + b.append("[" + (i + 1) + ". "); if (names != null) { for (int k = 0; k < names.length; k++) { RouteTypeRule rr = obj.region.quickGetEncodingRule(nametypes[k]); @@ -577,9 +601,10 @@ public class BinaryInspector { float y = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(i)); b.append(y).append(" / ").append(x).append(" "); } + b.append("]"); } - b.append("]"); } + b.append("]"); } if (obj.restrictions != null) { b.append(" restrictions ["); @@ -610,6 +635,9 @@ public class BinaryInspector { } }); println("\tTotal map objects: " + mapObjectsCounter.value); + if (vInfo.osm) { + printToFile("\n"); + } } private void printAddressDetailedInfo(VerboseInfo verbose, BinaryMapIndexReader index, AddressRegion region) throws IOException { @@ -858,7 +886,7 @@ public class BinaryInspector { } else if (vInfo.vmapObjects) { b.setLength(0); if (vInfo.osm) { - printOsmMapDetails(obj, b); + printOsmMapDetails(obj, b, null); try { printToFile(b.toString()); } catch (IOException e) { @@ -965,13 +993,13 @@ public class BinaryInspector { private static int OSM_ID = 1; - private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b) { + private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b, RouteRegion reg) { boolean multipolygon = obj.getPolygonInnerCoordinates() != null && obj.getPolygonInnerCoordinates().length > 0; boolean point = obj.getPointsLength() == 1; StringBuilder tags = new StringBuilder(); int[] types = obj.getTypes(); for (int j = 0; j < types.length; j++) { - TagValuePair pair = obj.getMapIndex().decodeType(types[j]); + TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(types[j])): obj.getMapIndex().decodeType(types[j]); if (pair == null) { throw new NullPointerException("Type " + types[j] + "was not found"); } @@ -979,7 +1007,9 @@ public class BinaryInspector { } if (obj.getAdditionalTypes() != null && obj.getAdditionalTypes().length > 0) { for (int j = 0; j < obj.getAdditionalTypes().length; j++) { - TagValuePair pair = obj.getMapIndex().decodeType(obj.getAdditionalTypes()[j]); + int addtype = obj.getAdditionalTypes()[j]; + TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(addtype)): + obj.getMapIndex().decodeType(addtype); if (pair == null) { throw new NullPointerException("Type " + obj.getAdditionalTypes()[j] + "was not found"); } @@ -990,7 +1020,7 @@ public class BinaryInspector { if (names != null && !names.isEmpty()) { int[] keys = names.keys(); for (int j = 0; j < keys.length; j++) { - TagValuePair pair = obj.getMapIndex().decodeType(keys[j]); + TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(keys[j])): obj.getMapIndex().decodeType(keys[j]); if (pair == null) { throw new NullPointerException("Type " + keys[j] + "was not found"); } @@ -1048,6 +1078,10 @@ public class BinaryInspector { } } + private TagValuePair convert(RouteTypeRule routeTypeRule) { + return new TagValuePair(routeTypeRule.getTag(), routeTypeRule.getValue(), 0); + } + private long printWay(TLongArrayList ids, StringBuilder b, StringBuilder tags) { int id = OSM_ID++; b.append("\n"); From 38a431bda931f22b9216c7929bdb598dae889a8c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 28 Jul 2016 01:28:22 +0200 Subject: [PATCH 2/2] Add option to print basic road info --- .../net/osmand/binary/BinaryInspector.java | 111 ++++++++++++++---- .../src/net/osmand/osm/MapRenderingTypes.java | 20 ++++ 2 files changed, 108 insertions(+), 23 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index f759486d44..3f66fb2680 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -49,6 +49,7 @@ import net.osmand.data.Building; import net.osmand.data.City; import net.osmand.data.MapObject; import net.osmand.data.Street; +import net.osmand.osm.MapRenderingTypes; import net.osmand.osm.PoiCategory; import net.osmand.util.MapUtils; @@ -542,17 +543,7 @@ public class BinaryInspector { mapObjectsCounter.value++; if (vInfo.osm) { b.setLength(0); - BinaryMapDataObject bobj = new BinaryMapDataObject(); - bobj.setArea(false); - bobj.coordinates = new int[obj.pointsX.length * 2]; - for(int i = 0; i < obj.pointsX.length; i++) { - bobj.coordinates[2*i] = obj.pointsX[i]; - bobj.coordinates[2*i +1] = obj.pointsY[i]; - } - bobj.types = obj.types; - bobj.setId(obj.getId() << 1); - bobj.objectNames = obj.getNames(); - printOsmMapDetails(bobj, b, obj.region); + printOsmRouteDetails(obj, b); try { printToFile(b.toString()); } catch (IOException e) { @@ -612,7 +603,9 @@ public class BinaryInspector { if (i > 0) { b.append(", "); } - b.append(obj.getRestrictionId(i)).append(" (").append(obj.getRestrictionType(i)).append(") "); + b.append(obj.getRestrictionId(i)).append(" (").append( + MapRenderingTypes.getRestrictionValue( + obj.getRestrictionType(i))).append(") "); } b.append("] "); @@ -886,7 +879,7 @@ public class BinaryInspector { } else if (vInfo.vmapObjects) { b.setLength(0); if (vInfo.osm) { - printOsmMapDetails(obj, b, null); + printOsmMapDetails(obj, b); try { printToFile(b.toString()); } catch (IOException e) { @@ -993,13 +986,90 @@ public class BinaryInspector { private static int OSM_ID = 1; - private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b, RouteRegion reg) { + private void printOsmRouteDetails(RouteDataObject obj, StringBuilder b) { + StringBuilder tags = new StringBuilder(); + int[] types = obj.getTypes(); + for (int j = 0; j < types.length; j++) { + RouteTypeRule rt = obj.region.quickGetEncodingRule(types[j]); + if (rt == null) { + throw new NullPointerException("Type " + types[j] + "was not found"); + } + tags.append("\t\n"); + } + TIntObjectHashMap names = obj.getNames(); + if (names != null && !names.isEmpty()) { + int[] keys = names.keys(); + for (int j = 0; j < keys.length; j++) { + RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]); + if (rt == null) { + throw new NullPointerException("Type " + keys[j] + "was not found"); + } + String name = quoteName(names.get(keys[j])); + tags.append("\t\n"); + } + } + + tags.append("\t\n"); + tags.append("\t\n"); + + TLongArrayList ids = new TLongArrayList(); + for (int i = 0; i < obj.getPointsLength(); i++) { + float lon = (float) MapUtils.get31LongitudeX(obj.getPoint31XTile(i)); + float lat = (float) MapUtils.get31LatitudeY(obj.getPoint31YTile(i)); + int id = OSM_ID++; + b.append("\t\n"); + if (obj.getPointNames(i) != null) { + String[] vs = obj.getPointNames(i); + int[] keys = obj.getPointNameTypes(i); + for (int j = 0; j < keys.length; j++) { + RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]); + String name = quoteName(vs[j]); + tags.append("\t\t\n"); + } + } + if (obj.getPointTypes(i) != null) { + int[] keys = obj.getPointTypes(i); + for (int j = 0; j < keys.length; j++) { + RouteTypeRule rt = obj.region.quickGetEncodingRule(keys[j]); + tags.append("\t\t\n"); + } + } + b.append("\t\n"); + ids.add(id); + } + long idway = printWay(ids, b, tags); + if(obj.getRestrictionLength() > 0) { + for(int i = 0; i < obj.getRestrictionLength(); i ++) { + long ld = obj.getRestrictionId(i); + String tp = MapRenderingTypes.getRestrictionValue(obj.getRestrictionType(i)); + int id = OSM_ID++; + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + b.append("\t\n"); + } + } + } + + private String quoteName(String name) { + name = name.replace("'", "'"); + name = name.replace("&", "&"); + return name; + } + + private void printOsmMapDetails(BinaryMapDataObject obj, StringBuilder b) { boolean multipolygon = obj.getPolygonInnerCoordinates() != null && obj.getPolygonInnerCoordinates().length > 0; boolean point = obj.getPointsLength() == 1; StringBuilder tags = new StringBuilder(); int[] types = obj.getTypes(); for (int j = 0; j < types.length; j++) { - TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(types[j])): obj.getMapIndex().decodeType(types[j]); + TagValuePair pair = obj.getMapIndex().decodeType(types[j]); if (pair == null) { throw new NullPointerException("Type " + types[j] + "was not found"); } @@ -1008,8 +1078,7 @@ public class BinaryInspector { if (obj.getAdditionalTypes() != null && obj.getAdditionalTypes().length > 0) { for (int j = 0; j < obj.getAdditionalTypes().length; j++) { int addtype = obj.getAdditionalTypes()[j]; - TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(addtype)): - obj.getMapIndex().decodeType(addtype); + TagValuePair pair = obj.getMapIndex().decodeType(addtype); if (pair == null) { throw new NullPointerException("Type " + obj.getAdditionalTypes()[j] + "was not found"); } @@ -1020,13 +1089,12 @@ public class BinaryInspector { if (names != null && !names.isEmpty()) { int[] keys = names.keys(); for (int j = 0; j < keys.length; j++) { - TagValuePair pair = reg != null ? convert(reg.quickGetEncodingRule(keys[j])): obj.getMapIndex().decodeType(keys[j]); + TagValuePair pair = obj.getMapIndex().decodeType(keys[j]); if (pair == null) { throw new NullPointerException("Type " + keys[j] + "was not found"); } String name = names.get(keys[j]); - name = name.replace("'", "'"); - name = name.replace("&", "&"); + name = quoteName(name); tags.append("\t\n"); } } @@ -1078,9 +1146,6 @@ public class BinaryInspector { } } - private TagValuePair convert(RouteTypeRule routeTypeRule) { - return new TagValuePair(routeTypeRule.getTag(), routeTypeRule.getValue(), 0); - } private long printWay(TLongArrayList ids, StringBuilder b, StringBuilder tags) { int id = OSM_ID++; diff --git a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java index 35841c3920..7010b10938 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapRenderingTypes.java @@ -588,6 +588,26 @@ public abstract class MapRenderingTypes { } + public static String getRestrictionValue(int i) { + switch (i) { + case RESTRICTION_NO_RIGHT_TURN: + return "NO_RIGHT_TURN".toLowerCase(); + case RESTRICTION_NO_LEFT_TURN: + return "NO_LEFT_TURN".toLowerCase(); + case RESTRICTION_NO_U_TURN: + return "NO_U_TURN".toLowerCase(); + case RESTRICTION_NO_STRAIGHT_ON: + return "NO_STRAIGHT_ON".toLowerCase(); + case RESTRICTION_ONLY_RIGHT_TURN: + return "ONLY_RIGHT_TURN".toLowerCase(); + case RESTRICTION_ONLY_LEFT_TURN: + return "ONLY_LEFT_TURN".toLowerCase(); + case RESTRICTION_ONLY_STRAIGHT_ON: + return "ONLY_STRAIGHT_ON".toLowerCase(); + } + return "unkonwn"; + + } }