From 0230e2ce95063ad9d6473b3fe817fd538bbacda7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 8 Nov 2011 22:02:08 +0100 Subject: [PATCH] Intermediate commit --- .../src/net/osmand/ToDoConstants.java | 12 +- .../src/net/osmand/data/MapObject.java | 2 +- .../osmand/data/preparation/IndexCreator.java | 5 +- .../data/preparation/IndexPoiCreator.java | 2 +- .../preparation/IndexVectorMapCreator.java | 135 ++++++++---------- .../src/net/osmand/osm/MapRenderingTypes.java | 34 +++-- 6 files changed, 84 insertions(+), 106 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/ToDoConstants.java b/DataExtractionOSM/src/net/osmand/ToDoConstants.java index 3ae1ffa9e2..589f7aede6 100644 --- a/DataExtractionOSM/src/net/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/net/osmand/ToDoConstants.java @@ -7,23 +7,22 @@ package net.osmand; */ public class ToDoConstants { + // Index + // Map QTree (skip small areas!!!) + // new Address + // slightly changed POI (check it) + // Routing index // == Osmand application (TODO 127) == - // TODO replace icon for default mode (???) // TODO prepare C++ version of routing algorithm - // TODO make transport search faster (cancellable.. ) - - // TODO Test Voice activity // Map Refactoring // Remove notification from OsmAndMapTileView (?) - // === Refactoring issues === // !|| 125 || Introduce service layer rather than singletons and put all related into new package (services). Review architecture. Split some big classes. || // === Common issues === -// || 110 || Use android voice for pronounce command (could be used in future to pronounce street) (Issue 70) || // || 111 || Investigate showing street name while driving (Issue 286) || // || 86 || Allow to add/edit custom tags to POI objects (Issue 44) || // || 113 || Calculate speed cameras/bumps on the road (announce about them) (Issue 418) || @@ -41,6 +40,7 @@ public class ToDoConstants { /////////////////////////// DONE ////////////////////////////// // DONE ANDROID : +// || 110 || Use android voice for pronounce command (could be used in future to pronounce street) (Issue 70) || // DONE SWING diff --git a/DataExtractionOSM/src/net/osmand/data/MapObject.java b/DataExtractionOSM/src/net/osmand/data/MapObject.java index b9b5c1ff5b..13bc8c244c 100644 --- a/DataExtractionOSM/src/net/osmand/data/MapObject.java +++ b/DataExtractionOSM/src/net/osmand/data/MapObject.java @@ -34,7 +34,7 @@ public abstract class MapObject implements Comparable, Serializable { if(this.name == null){ this.name = e.getTag(OSMTagKey.NAME); } - if(this.enName == null){ + if (this.enName == null) { this.enName = e.getTag(OSMTagKey.NAME_EN); if(name == null){ this.name = this.enName; diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java index ad38dc859c..2fdd3773f8 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java @@ -366,11 +366,8 @@ public class IndexCreator { this.indexTransportCreator = new IndexTransportCreator(); this.indexPoiCreator = new IndexPoiCreator(renderingTypes); this.indexAddressCreator = new IndexAddressCreator(logMapDataWarn); - this.indexMapCreator = new IndexVectorMapCreator(logMapDataWarn); + this.indexMapCreator = new IndexVectorMapCreator(logMapDataWarn,mapZooms, renderingTypes, zoomWaySmothness); this.accessor = new OsmDbAccessor(); - - - indexMapCreator.initSettings(mapZooms, renderingTypes, zoomWaySmothness); // init address String[] normalizeDefaultSuffixes = null; diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java index 36cd758769..92f2927d50 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexPoiCreator.java @@ -63,7 +63,7 @@ public class IndexPoiCreator extends AbstractIndexPartCreator { public void iterateEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException { tempAmenityList.clear(); - tempAmenityList = Amenity.parseAmenities(e, tempAmenityList); + tempAmenityList = Amenity.parseAmenities(renderingTypes, e, tempAmenityList); if (!tempAmenityList.isEmpty() && poiPreparedStatement != null) { // load data for way (location etc...) ctx.loadEntityData(e); diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexVectorMapCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexVectorMapCreator.java index 1851970a60..43c39fb281 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexVectorMapCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexVectorMapCreator.java @@ -1,5 +1,7 @@ package net.osmand.data.preparation; +import gnu.trove.list.array.TIntArrayList; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -50,17 +52,20 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { private static final int MAP_LEVELS_POWER = 3; private static final int MAP_LEVELS_MAX = 1 << MAP_LEVELS_POWER; private MapRenderingTypes renderingTypes; + private MapZooms mapZooms; // MEMORY map : save it in memory while that is allowed private Map>[] multiPolygonsWays; private Map multiPolygonsNames = new LinkedHashMap(); + private Map> highwayRestrictions = new LinkedHashMap>(); // local purpose - List typeUse = new ArrayList(8); + TIntArrayList typeUse = new TIntArrayList(8); List restrictionsUse = new ArrayList(8); - private MapZooms mapZooms; + + private PreparedStatement mapBinaryStat; private PreparedStatement mapLowLevelBinaryStat; @@ -72,8 +77,17 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { private final Log logMapDataWarn; - public IndexVectorMapCreator(Log logMapDataWarn) { + public IndexVectorMapCreator(Log logMapDataWarn, MapZooms mapZooms, MapRenderingTypes renderingTypes, int zoomWaySmothness) { this.logMapDataWarn = logMapDataWarn; + this.mapZooms = mapZooms; + this.zoomWaySmothness = zoomWaySmothness; + this.renderingTypes = renderingTypes; + // init map + multiPolygonsWays = new Map[mapZooms.size()]; + for (int i = 0; i < multiPolygonsWays.length; i++) { + multiPolygonsWays[i] = new LinkedHashMap>(); + } + lowLevelWays = -1; } public void indexMapRelationsAndMultiPolygons(Entity e, OsmDbAccessorContext ctx) throws SQLException { @@ -104,7 +118,7 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { return; } - int mtType = findMultiPolygonType(e, 0); + int mtType = renderingTypes.encodeEntityWithType(e, mapZooms.getLevel(0).getMaxZoom(), true, typeUse); if (mtType != 0) { String name = renderingTypes.getEntityName(e); @@ -156,7 +170,7 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { } putMultipolygonType(multiPolygonsWays[0], way.getId(), mtType, inverse); for (int i = 1; i < multiPolygonsWays.length; i++) { - int type = findMultiPolygonType(e, i); + int type = renderingTypes.encodeEntityWithType(e, mapZooms.getLevel(0).getMaxZoom(), true, typeUse); if (type != 0) { putMultipolygonType(multiPolygonsWays[i], way.getId(), type, inverse); } @@ -200,45 +214,6 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { } - private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws SQLException { - if (e instanceof Relation && "restriction".equals(e.getTag(OSMTagKey.TYPE))) { //$NON-NLS-1$ - String val = e.getTag("restriction"); //$NON-NLS-1$ - if (val != null) { - byte type = -1; - if ("no_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_NO_RIGHT_TURN; - } else if ("no_left_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_NO_LEFT_TURN; - } else if ("no_u_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_NO_U_TURN; - } else if ("no_straight_on".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON; - } else if ("only_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_ONLY_RIGHT_TURN; - } else if ("only_left_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_ONLY_LEFT_TURN; - } else if ("only_straight_on".equalsIgnoreCase(val)) { //$NON-NLS-1$ - type = MapRenderingTypes.RESTRICTION_ONLY_STRAIGHT_ON; - } - if (type != -1) { - ctx.loadEntityData(e); - Collection fromL = ((Relation) e).getMemberIds("from"); //$NON-NLS-1$ - Collection toL = ((Relation) e).getMemberIds("to"); //$NON-NLS-1$ - if (!fromL.isEmpty() && !toL.isEmpty()) { - EntityId from = fromL.iterator().next(); - EntityId to = toL.iterator().next(); - if (from.getType() == EntityType.WAY) { - if (!highwayRestrictions.containsKey(from.getId())) { - highwayRestrictions.put(from.getId(), new ArrayList(4)); - } - highwayRestrictions.get(from.getId()).add((to.getId() << 3) | (long) type); - } - } - } - } - } - } - private void putMultipolygonType(Map> multiPolygonsWays, long baseId, int mtType, boolean inverse) { if (mtType == 0) { return; @@ -253,25 +228,6 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { } } - private int findMultiPolygonType(Entity e, int level) { - int t = renderingTypes.encodeEntityWithType(e, mapZooms.getLevel(level).getMaxZoom(), true, typeUse); - int mtType = 0; - if (t != 0) { - if ((t & 3) == MapRenderingTypes.MULTY_POLYGON_TYPE) { - mtType = t; - } else { - for (Integer i : typeUse) { - if ((i & 3) == MapRenderingTypes.MULTY_POLYGON_TYPE) { - mtType = i; - break; - } - } - } - } - return mtType; - } - - private void combineMultiPolygons(Way w, List> completedRings, List> incompletedRings) { long lId = w.getEntityIds().get(w.getEntityIds().size() - 1).getId().longValue(); long fId = w.getEntityIds().get(0).getId().longValue(); @@ -625,19 +581,6 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { } - @SuppressWarnings("unchecked") - public void initSettings(MapZooms mapZooms, MapRenderingTypes renderingTypes, int zoomWaySmothness) { - this.mapZooms = mapZooms; - this.zoomWaySmothness = zoomWaySmothness; - this.renderingTypes = renderingTypes; - // init map - multiPolygonsWays = new Map[mapZooms.size()]; - for (int i = 0; i < multiPolygonsWays.length; i++) { - multiPolygonsWays[i] = new LinkedHashMap>(); - } - lowLevelWays = -1; - - } public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException { if (e instanceof Way || e instanceof Node) { @@ -952,4 +895,44 @@ public class IndexVectorMapCreator extends AbstractIndexPartCreator { public int getZoomWaySmothness() { return zoomWaySmothness; } + + // TODO restrictions should be moved to different creator (Routing Map creator) + private void indexHighwayRestrictions(Entity e, OsmDbAccessorContext ctx) throws SQLException { + if (e instanceof Relation && "restriction".equals(e.getTag(OSMTagKey.TYPE))) { //$NON-NLS-1$ + String val = e.getTag("restriction"); //$NON-NLS-1$ + if (val != null) { + byte type = -1; + if ("no_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_NO_RIGHT_TURN; + } else if ("no_left_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_NO_LEFT_TURN; + } else if ("no_u_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_NO_U_TURN; + } else if ("no_straight_on".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_NO_STRAIGHT_ON; + } else if ("only_right_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_ONLY_RIGHT_TURN; + } else if ("only_left_turn".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_ONLY_LEFT_TURN; + } else if ("only_straight_on".equalsIgnoreCase(val)) { //$NON-NLS-1$ + type = MapRenderingTypes.RESTRICTION_ONLY_STRAIGHT_ON; + } + if (type != -1) { + ctx.loadEntityData(e); + Collection fromL = ((Relation) e).getMemberIds("from"); //$NON-NLS-1$ + Collection toL = ((Relation) e).getMemberIds("to"); //$NON-NLS-1$ + if (!fromL.isEmpty() && !toL.isEmpty()) { + EntityId from = fromL.iterator().next(); + EntityId to = toL.iterator().next(); + if (from.getType() == EntityType.WAY) { + if (!highwayRestrictions.containsKey(from.getId())) { + highwayRestrictions.put(from.getId(), new ArrayList(4)); + } + highwayRestrictions.get(from.getId()).add((to.getId() << 3) | (long) type); + } + } + } + } + } + } } diff --git a/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java b/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java index 2f8171c2cb..4bc4714a25 100644 --- a/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java +++ b/DataExtractionOSM/src/net/osmand/osm/MapRenderingTypes.java @@ -52,14 +52,6 @@ public class MapRenderingTypes { public final static int POLYLINE_TYPE = 2; public final static int POINT_TYPE = 1; - public final static byte RESTRICTION_NO_RIGHT_TURN = 1; - public final static byte RESTRICTION_NO_LEFT_TURN = 2; - public final static byte RESTRICTION_NO_U_TURN = 3; - public final static byte RESTRICTION_NO_STRAIGHT_ON = 4; - public final static byte RESTRICTION_ONLY_RIGHT_TURN = 5; - public final static byte RESTRICTION_ONLY_LEFT_TURN = 6; - public final static byte RESTRICTION_ONLY_STRAIGHT_ON = 7; - private static char TAG_DELIMETER = '/'; //$NON-NLS-1$ private String resourceName = null; @@ -160,17 +152,17 @@ public class MapRenderingTypes { return null; } - public String getEntityName(Entity e) { String name = e.getTag(OSMTagKey.NAME); if (name == null) { - name = getNullName(e); + name = e.getTag(OSMTagKey.NAME_EN); + if(name == null) { + name = getNullName(e); + } } return name; } - - public Map> getAmenityTypeNameToTagVal() { if (amenityTypeNameToTagVal == null) { Map types = getEncodingRuleTypes(); @@ -438,6 +430,7 @@ public class MapRenderingTypes { } + // TODO Move to Routing Attributes and finalize // HIGHWAY special attributes : // o/oneway 1 bit // f/free toll 1 bit @@ -446,10 +439,18 @@ public class MapRenderingTypes { // a/vehicle access 4 bit (height, weight?) - one bit bicycle // p/parking 1 bit // c/cycle oneway 1 bit - // TODO // ci/inside city 1 bit - // ENCODING : ci|c|p|aaaa|sss|rr|f|o - 14 bit + + public final static byte RESTRICTION_NO_RIGHT_TURN = 1; + public final static byte RESTRICTION_NO_LEFT_TURN = 2; + public final static byte RESTRICTION_NO_U_TURN = 3; + public final static byte RESTRICTION_NO_STRAIGHT_ON = 4; + public final static byte RESTRICTION_ONLY_RIGHT_TURN = 5; + public final static byte RESTRICTION_ONLY_LEFT_TURN = 6; + public final static byte RESTRICTION_ONLY_STRAIGHT_ON = 7; + + public static boolean isOneWayWay(int highwayAttributes){ return (highwayAttributes & 1) > 0; } @@ -466,10 +467,7 @@ public class MapRenderingTypes { case 1: return 40; case 2: - // for old format it should return 0; - // TODO it should be uncommented because now it is fixed - // return 60; - return 0; + return 60; case 3: return 80; case 4: