diff --git a/DataExtractionOSM/src/com/osmand/ToDoConstants.java b/DataExtractionOSM/src/com/osmand/ToDoConstants.java index f49c6fc563..a2816e80a8 100644 --- a/DataExtractionOSM/src/com/osmand/ToDoConstants.java +++ b/DataExtractionOSM/src/com/osmand/ToDoConstants.java @@ -21,10 +21,14 @@ public class ToDoConstants { // 50. Invent opening hours editor in order to edit POI hours better on device // GOT by Olga + // TODO sort hamlets by distance // 60. Audio guidance for routing // 61. Provide route information for YOURS (calclate turns/angle/expected time). // Fix some missing turns in CloudMade (for secondary roads wo name). Add them (if dist to prev/next turn > 150m) [dacha] - + // 33. Build transport locations. Create transport index (transport-stops) (investigate) + // DONE: Load transport routes in swing. + // IDEA TO HAVE : + // 43. Enable poi filter by name // 58. Upload/Download zip-index from site & unzip them on phone @@ -32,9 +36,6 @@ public class ToDoConstants { // That setting should rule all activities that use internet. It should ask whenever internet is used // (would you like to use internet for that operation - if using internet is not checked). // Internet using now for : edit POI osm, show osm bugs layer, download tiles. - // 33. Build transport locations. Create transport index (transport-stops) (investigate) - // DONE: Load transport routes in swing. - // IDEA TO HAVE : // 40. Support simple vector road rendering (require new index file) (?) // 63. Support simple offline routing(require new index file) (?) diff --git a/DataExtractionOSM/src/com/osmand/data/MapObject.java b/DataExtractionOSM/src/com/osmand/data/MapObject.java index 1ab1e8c70d..cf082d7297 100644 --- a/DataExtractionOSM/src/com/osmand/data/MapObject.java +++ b/DataExtractionOSM/src/com/osmand/data/MapObject.java @@ -5,6 +5,8 @@ import java.text.Collator; import com.osmand.osm.Entity; import com.osmand.osm.LatLon; import com.osmand.osm.MapUtils; +import com.osmand.osm.Entity.EntityId; +import com.osmand.osm.Entity.EntityType; import com.osmand.osm.OSMSettings.OSMTagKey; public abstract class MapObject implements Comparable { @@ -13,6 +15,7 @@ public abstract class MapObject implements Comparable { protected String enName = null; protected LatLon location = null; protected Long id = null; + protected EntityType type = null; public MapObject(){} @@ -23,6 +26,7 @@ public abstract class MapObject implements Comparable { public void setEntity(Entity e){ this.id = e.getId(); + this.type = EntityType.valueOf(e); if(this.name == null){ this.name = e.getTag(OSMTagKey.NAME); } @@ -34,6 +38,14 @@ public abstract class MapObject implements Comparable { } } + public EntityId getEntityId(){ + EntityType t = type; + if(t == null){ + t = EntityType.NODE; + } + return new EntityId(t, id); + } + public void setId(Long id) { this.id = id; } diff --git a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java index fb4f3bff6c..34beedf856 100644 --- a/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java +++ b/DataExtractionOSM/src/com/osmand/data/preparation/DataExtraction.java @@ -46,6 +46,8 @@ import com.osmand.osm.Node; import com.osmand.osm.OSMSettings; import com.osmand.osm.Relation; import com.osmand.osm.Way; +import com.osmand.osm.Entity.EntityId; +import com.osmand.osm.Entity.EntityType; import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.io.IOsmStorageFilter; import com.osmand.osm.io.OsmBaseStorage; @@ -120,11 +122,18 @@ public class DataExtraction { ArrayList amenities = new ArrayList(); ArrayList ways = new ArrayList(); ArrayList transport = new ArrayList(); - Map postalCodes = new LinkedHashMap(); + Map postalCodes = new LinkedHashMap(); - int currentCount = 0; + private Connection conn; - private PreparedStatement prep; + + private boolean preloadRelationAndWaysIntoDB = false; + int currentCountNode = 0; + private PreparedStatement prepNode; + int currentRelationsCount = 0; + private PreparedStatement prepRelations; + int currentWaysCount = 0; + private PreparedStatement prepWays; public DataExtractionOsmFilter() { @@ -146,7 +155,7 @@ public class DataExtraction { return transport; } - public Map getPostalCodes() { + public Map getPostalCodes() { return postalCodes; } @@ -171,45 +180,97 @@ public class DataExtraction { stat.executeUpdate("drop table if exists node;"); stat.executeUpdate("create table node (id long, latitude double, longitude double);"); stat.executeUpdate("create index IdIndex ON node (id);"); + stat.executeUpdate("drop table if exists ways;"); + stat.executeUpdate("create table ways (id long, node long);"); + stat.executeUpdate("create index IdWIndex ON ways (id);"); + stat.executeUpdate("drop table if exists relations;"); + stat.executeUpdate("create table relations (id long, member long, type byte, role text);"); + stat.executeUpdate("create index IdRIndex ON relations (id);"); stat.close(); - prep = conn.prepareStatement("insert into node values (?, ?, ?);"); + prepNode = conn.prepareStatement("insert into node values (?, ?, ?);"); + prepWays = conn.prepareStatement("insert into ways values (?, ?);"); + prepRelations = conn.prepareStatement("insert into relations values (?, ?, ?, ?);"); + preloadRelationAndWaysIntoDB = indexTransport; conn.setAutoCommit(false); } public void correlateData(OsmBaseStorage storage, IProgress progress) throws SQLException { - if (currentCount > 0) { - prep.executeBatch(); + if (currentCountNode > 0) { + prepNode.executeBatch(); } - prep.close(); + prepNode.close(); + if (currentWaysCount > 0) { + prepWays.executeBatch(); + } + prepWays.close(); + if (currentRelationsCount > 0) { + prepRelations.executeBatch(); + } + prepRelations.close(); conn.setAutoCommit(true); - final PreparedStatement pselect = conn.prepareStatement("select * from node where id = ?"); - Map map = new LinkedHashMap(); + + final PreparedStatement pselectNode = conn.prepareStatement("select * from node where id = ?"); + final PreparedStatement pselectWay = conn.prepareStatement("select * from ways where id = ?"); + final PreparedStatement pselectRelation = conn.prepareStatement("select * from relations where id = ?"); + + Map map = new LinkedHashMap(); progress.startTask("Correlating data...", storage.getRegisteredEntities().size()); - Collection values = new ArrayList(storage.getRegisteredEntities().values()); - for (Entity e : values) { + ArrayList values = new ArrayList(storage.getRegisteredEntities().values()); + for (int ind = 0; ind < values.size(); ind++) { + Entity e = values.get(ind); progress.progress(1); - if (e instanceof Way || e instanceof Relation) { - map.clear(); - Collection ids = e instanceof Way ? ((Way) e).getNodeIds() : ((Relation) e).getMemberIds(); - for (Long i : ids) { - if (!storage.getRegisteredEntities().containsKey(i)) { - pselect.setLong(1, i); - if (pselect.execute()) { - ResultSet rs = pselect.getResultSet(); + if (e instanceof Node) { + continue; + } + map.clear(); + Collection ids = e instanceof Way ? ((Way) e).getEntityIds() : ((Relation) e).getMemberIds(); + for (EntityId i : ids) { + if (!storage.getRegisteredEntities().containsKey(i)) { + if (i.getType() == EntityType.NODE) { + pselectNode.setLong(1, i.getId()); + if (pselectNode.execute()) { + ResultSet rs = pselectNode.getResultSet(); if (rs.next()) { storage.getRegisteredEntities().put(i, new Node(rs.getDouble(2), rs.getDouble(3), rs.getLong(1))); } rs.close(); } - } - if(storage.getRegisteredEntities().containsKey(i)){ - map.put(i, storage.getRegisteredEntities().get(i)); + } else if (i.getType() == EntityType.WAY) { + pselectWay.setLong(1, i.getId()); + if (pselectWay.execute()) { + ResultSet rs = pselectWay.getResultSet(); + Way way = new Way(i.getId()); + storage.getRegisteredEntities().put(i, way); + while (rs.next()) { + way.addNode(rs.getLong(2)); + } + // add way to load referred nodes + values.add(way); + rs.close(); + } + } else if (i.getType() == EntityType.RELATION) { + pselectRelation.setLong(1, i.getId()); + if (pselectRelation.execute()) { + ResultSet rs = pselectNode.getResultSet(); + Relation rel = new Relation(i.getId()); + storage.getRegisteredEntities().put(i, rel); + while (rs.next()) { + rel.addMember(rs.getLong(1), EntityType.values()[rs.getByte(2)], rs.getString(3)); + } + // do not load relation members recursively ? It is not needed for transport, address, poi before + rs.close(); + } } } - e.initializeLinks(map); + if (storage.getRegisteredEntities().containsKey(i)) { + map.put(i, storage.getRegisteredEntities().get(i)); + } } + e.initializeLinks(map); } + + pselectNode.close(); } public void close() { @@ -250,7 +311,7 @@ public class DataExtraction { if(e instanceof Relation){ if(e.getTag(OSMTagKey.POSTAL_CODE) != null){ String tag = e.getTag(OSMTagKey.POSTAL_CODE); - for(Long l : ((Relation)e).getMemberIds()){ + for(EntityId l : ((Relation)e).getMemberIds()){ postalCodes.put(l, tag); } } @@ -262,25 +323,48 @@ public class DataExtraction { transport.add((Relation) e); processed = true; } - if(e instanceof Way){ - processed = true; - } } // put all nodes into temporary db to get only required nodes after loading all data try { if (e instanceof Node) { - currentCount++; - prep.setLong(1, e.getId()); - prep.setDouble(2, ((Node) e).getLatitude()); - prep.setDouble(3, ((Node) e).getLongitude()); - prep.addBatch(); - if (currentCount >= BATCH_SIZE) { - prep.executeBatch(); - currentCount = 0; + currentCountNode++; + prepNode.setLong(1, e.getId()); + prepNode.setDouble(2, ((Node) e).getLatitude()); + prepNode.setDouble(3, ((Node) e).getLongitude()); + prepNode.addBatch(); + if (currentCountNode >= BATCH_SIZE) { + prepNode.executeBatch(); + currentCountNode = 0; + } + } else if(preloadRelationAndWaysIntoDB) { + if (e instanceof Way) { + for(Long i : ((Way)e).getNodeIds()){ + currentWaysCount ++; + prepWays.setLong(1, e.getId()); + prepWays.setLong(2, i); + prepWays.addBatch(); + } + if (currentWaysCount >= BATCH_SIZE) { + prepWays.executeBatch(); + currentWaysCount = 0; + } + } else { + for(Entry i : ((Relation)e).getMembersMap().entrySet()){ + currentRelationsCount ++; + prepRelations.setLong(1, e.getId()); + prepRelations.setLong(2, i.getKey().getId()); + prepRelations.setLong(3, i.getKey().getType().ordinal()); + prepRelations.setString(4, i.getValue()); + prepWays.addBatch(); + } + if (currentRelationsCount >= BATCH_SIZE) { + prepRelations.executeBatch(); + currentRelationsCount = 0; + } } } } catch (SQLException ex) { - log.error("Could not save node", ex); + log.error("Could not save in db", ex); } return processed || loadAllObjects; } @@ -289,8 +373,6 @@ public class DataExtraction { public Region readCountry(String path, IProgress progress, IOsmStorageFilter addFilter) throws IOException, SAXException, SQLException{ - - File f = new File(path); InputStream stream = new FileInputStream(f); InputStream streamFile = stream; @@ -319,13 +401,13 @@ public class DataExtraction { final ArrayList amenities = filter.getAmenities(); final ArrayList ways = filter.getWays(); final ArrayList transport = filter.getTransport(); - Map postalCodes = filter.getPostalCodes(); + Map postalCodes = filter.getPostalCodes(); storage.getFilters().add(filter); // 0. Loading osm file + try { // 0.1 init database to store temporary data filter.initDatabase(); - // 0.2 parsing osm itself progress.setGeneralProgress("[40 of 100]"); storage.parseOSM(stream, progress, streamFile, parseEntityInfo); @@ -428,7 +510,7 @@ public class DataExtraction { } - private void readingBuildings(IProgress progress, final ArrayList buildings, Region country, Map postalCodes) { + private void readingBuildings(IProgress progress, final ArrayList buildings, Region country, Map postalCodes) { // found buildings (index addresses) progress.startTask("Indexing buildings...", buildings.size()); for(Entity b : buildings){ @@ -448,8 +530,9 @@ public class DataExtraction { } if (city != null) { Building building = city.registerBuilding(b); - if(postalCodes.containsKey(building.getId()) ){ - building.setPostcode(postalCodes.get(building.getId())); + EntityId i = building.getEntityId(); + if(postalCodes.containsKey(i) ){ + building.setPostcode(postalCodes.get(i)); } } } diff --git a/DataExtractionOSM/src/com/osmand/osm/Entity.java b/DataExtractionOSM/src/com/osmand/osm/Entity.java index 394c53fbd3..b4412f2f29 100644 --- a/DataExtractionOSM/src/com/osmand/osm/Entity.java +++ b/DataExtractionOSM/src/com/osmand/osm/Entity.java @@ -8,6 +8,73 @@ import java.util.Map; import com.osmand.osm.OSMSettings.OSMTagKey; public abstract class Entity { + public enum EntityType { + NODE, + WAY, + RELATION; + + public static EntityType valueOf(Entity e){ + if(e instanceof Node){ + return NODE; + } else if(e instanceof Way){ + return WAY; + } else if(e instanceof Relation){ + return RELATION; + } + return null; + } + } + + public static class EntityId { + private final EntityType type; + private final Long id; + + public EntityId(EntityType type, Long id){ + this.type = type; + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } + + public EntityType getType() { + return type; + } + + public Long getId() { + return id; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + EntityId other = (EntityId) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } + + } + // lazy initializing private Map tags = null; private final long id; @@ -57,7 +124,7 @@ public abstract class Entity { return tags.keySet(); } - public abstract void initializeLinks(Map entities); + public abstract void initializeLinks(Map entities); /** diff --git a/DataExtractionOSM/src/com/osmand/osm/Node.java b/DataExtractionOSM/src/com/osmand/osm/Node.java index b580f6d4c9..908b277463 100644 --- a/DataExtractionOSM/src/com/osmand/osm/Node.java +++ b/DataExtractionOSM/src/com/osmand/osm/Node.java @@ -37,7 +37,7 @@ public class Node extends Entity { } @Override - public void initializeLinks(Map entities) { + public void initializeLinks(Map entities) { // nothing to initialize } diff --git a/DataExtractionOSM/src/com/osmand/osm/Relation.java b/DataExtractionOSM/src/com/osmand/osm/Relation.java index ccf69c92cc..15fbac7569 100644 --- a/DataExtractionOSM/src/com/osmand/osm/Relation.java +++ b/DataExtractionOSM/src/com/osmand/osm/Relation.java @@ -8,25 +8,26 @@ import java.util.List; import java.util.Map; public class Relation extends Entity { - + // lazyLoading - Map members = null; + Map members = null; Map memberEntities = null; + public Relation(long id) { super(id); } - public void addMember(Long id, String role){ + public void addMember(Long id, EntityType type, String role){ if(members == null){ - members = new LinkedHashMap(); + members = new LinkedHashMap(); } - members.put(id, role); + members.put(new EntityId(type, id), role); } - public String removeMember(Long id){ + public String removeMember(EntityType e, Long id){ if(members == null){ return null; } @@ -41,26 +42,26 @@ public class Relation extends Entity { return members.get(id); } - public Collection getMemberIds() { + public Collection getMemberIds() { return getMemberIds(null); } - public Map getMembersMap() { + public Map getMembersMap() { if(members == null){ return Collections.emptyMap(); } return Collections.unmodifiableMap(members); } - public Collection getMemberIds(String role) { + public Collection getMemberIds(String role) { if (members == null) { return Collections.emptyList(); } if (role == null) { return members.keySet(); } - List l = new ArrayList(); - for (Long m : members.keySet()) { + List l = new ArrayList(); + for (EntityId m : members.keySet()) { if (role.equals(members.get(m))) { l.add(m); } @@ -89,14 +90,14 @@ public class Relation extends Entity { } @Override - public void initializeLinks(Map entities){ + public void initializeLinks(Map entities){ if (members != null) { if(memberEntities == null){ memberEntities = new LinkedHashMap(); } else { memberEntities.clear(); } - for(Long l : members.keySet()){ + for(EntityId l : members.keySet()){ if(l != null && entities.get(l) != null){ memberEntities.put(entities.get(l), members.get(l)); } diff --git a/DataExtractionOSM/src/com/osmand/osm/Way.java b/DataExtractionOSM/src/com/osmand/osm/Way.java index 181040db97..fe6c5952f8 100644 --- a/DataExtractionOSM/src/com/osmand/osm/Way.java +++ b/DataExtractionOSM/src/com/osmand/osm/Way.java @@ -47,6 +47,17 @@ public class Way extends Entity { return nodeIds; } + public List getEntityIds(){ + if(nodeIds == null){ + return Collections.emptyList(); + } + List ls = new ArrayList(); + for(Long l : nodeIds){ + ls.add(new EntityId(EntityType.NODE, l)); + } + return ls; + } + public List getNodes() { if(nodes == null){ return Collections.emptyList(); @@ -55,7 +66,7 @@ public class Way extends Entity { } @Override - public void initializeLinks(Map entities) { + public void initializeLinks(Map entities) { if (nodeIds != null) { if(nodes == null){ nodes = new ArrayList(); @@ -63,11 +74,7 @@ public class Way extends Entity { nodes.clear(); } for (int i = 0; i < nodeIds.size(); i++) { - if(entities.get(nodeIds.get(i)) instanceof Node){ - nodes.add((Node) entities.get(nodeIds.get(i))); - } else { - nodes.add(null); - } + nodes.add((Node) entities.get(new EntityId(EntityType.NODE,nodeIds.get(i)))); } } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java index d5658c2973..0b267c2044 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmBaseStorage.java @@ -23,6 +23,8 @@ import com.osmand.osm.EntityInfo; import com.osmand.osm.Node; import com.osmand.osm.Relation; import com.osmand.osm.Way; +import com.osmand.osm.Entity.EntityId; +import com.osmand.osm.Entity.EntityType; public class OsmBaseStorage extends DefaultHandler { @@ -56,8 +58,8 @@ public class OsmBaseStorage extends DefaultHandler { protected boolean parseStarted; - protected Map entities = new LinkedHashMap(); - protected Map entityInfo = new LinkedHashMap(); + protected Map entities = new LinkedHashMap(); + protected Map entityInfo = new LinkedHashMap(); // this is used to show feedback to user protected int progressEntity = 0; @@ -216,7 +218,8 @@ public class OsmBaseStorage extends DefaultHandler { } else if (ELEM_MEMBER.equals(name)) { Long id = parseId(attributes, ATTR_REF, -1); if(id != -1 && currentParsedEntity instanceof Relation){ - ((Relation)currentParsedEntity).addMember(id, attributes.getValue(ATTR_ROLE)); + EntityType type = EntityType.valueOf(attributes.getValue(ATTR_TYPE).toUpperCase()); + ((Relation)currentParsedEntity).addMember(id, type, attributes.getValue(ATTR_ROLE)); } } else { @@ -228,12 +231,21 @@ public class OsmBaseStorage extends DefaultHandler { @Override public void endElement(String uri, String localName, String name) throws SAXException { name = saxParser.isNamespaceAware() ? localName : name; - if (ELEM_NODE.equals(name) || ELEM_WAY.equals(name) || ELEM_RELATION.equals(name)) { + EntityType type = null; + if (ELEM_NODE.equals(name)){ + type = EntityType.NODE; + } else if (ELEM_WAY.equals(name)){ + type = EntityType.WAY; + } else if (ELEM_RELATION.equals(name)){ + type = EntityType.RELATION; + } + if (type != null) { if(currentParsedEntity != null){ if(acceptEntityToLoad(currentParsedEntity)){ - Entity oldEntity = entities.put(currentParsedEntity.getId(), currentParsedEntity); + EntityId entityId = new EntityId(type, currentParsedEntity.getId()); + Entity oldEntity = entities.put(entityId, currentParsedEntity); if(parseEntityInfo && currentParsedEntityInfo != null){ - entityInfo.put(currentParsedEntity.getId(), currentParsedEntityInfo); + entityInfo.put(entityId, currentParsedEntityInfo); } if(!supressWarnings && oldEntity!= null){ throw new UnsupportedOperationException("Entity with id=" + oldEntity.getId() +" is duplicated in osm map"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -263,11 +275,11 @@ public class OsmBaseStorage extends DefaultHandler { } } - public Map getRegisteredEntityInfo() { + public Map getRegisteredEntityInfo() { return entityInfo; } - public Map getRegisteredEntities() { + public Map getRegisteredEntities() { return entities; } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmBoundsFilter.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmBoundsFilter.java index c91ffd8c6f..ef4a16d473 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmBoundsFilter.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmBoundsFilter.java @@ -4,6 +4,7 @@ import com.osmand.osm.Entity; import com.osmand.osm.Node; import com.osmand.osm.Relation; import com.osmand.osm.Way; +import com.osmand.osm.Entity.EntityId; public class OsmBoundsFilter implements IOsmStorageFilter { @@ -41,7 +42,7 @@ public class OsmBoundsFilter implements IOsmStorageFilter { return false; } if(entity instanceof Relation){ - for(Long l : ((Relation) entity).getMemberIds()){ + for(EntityId l : ((Relation) entity).getMemberIds()){ if(storage.getRegisteredEntities().containsKey(l)){ return true; } diff --git a/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java b/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java index 142f84bd04..e847732759 100644 --- a/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java +++ b/DataExtractionOSM/src/com/osmand/osm/io/OsmStorageWriter.java @@ -41,6 +41,7 @@ import com.osmand.osm.EntityInfo; import com.osmand.osm.Node; import com.osmand.osm.Relation; import com.osmand.osm.Way; +import com.osmand.osm.Entity.EntityId; import com.sun.org.apache.xerces.internal.impl.PropertyManager; import com.sun.xml.internal.stream.writers.XMLStreamWriterImpl; @@ -54,9 +55,9 @@ public class OsmStorageWriter { } - public void saveStorage(OutputStream output, OsmBaseStorage storage, Collection interestedObjects, boolean includeLinks) throws XMLStreamException, IOException { - Map entities = storage.getRegisteredEntities(); - Map entityInfo = storage.getRegisteredEntityInfo(); + public void saveStorage(OutputStream output, OsmBaseStorage storage, Collection interestedObjects, boolean includeLinks) throws XMLStreamException, IOException { + Map entities = storage.getRegisteredEntities(); + Map entityInfo = storage.getRegisteredEntityInfo(); PropertyManager propertyManager = new PropertyManager(PropertyManager.CONTEXT_WRITER); // transformer.setOutputProperty(OutputKeys.INDENT, "yes"); // String indent = "{http://xml.apache.org/xslt}indent-amount"; @@ -69,16 +70,16 @@ public class OsmStorageWriter { if(interestedObjects == null){ interestedObjects = entities.keySet(); } - Stack toResolve = new Stack(); + Stack toResolve = new Stack(); toResolve.addAll(interestedObjects); while(!toResolve.isEmpty()){ - Long l = toResolve.pop(); + EntityId l = toResolve.pop(); if(entities.get(l) instanceof Node){ nodes.add((Node) entities.get(l)); } else if(entities.get(l) instanceof Way){ ways.add((Way) entities.get(l)); if(includeLinks){ - toResolve.addAll(((Way)entities.get(l)).getNodeIds()); + toResolve.addAll(((Way)entities.get(l)).getEntityIds()); } } else if(entities.get(l) instanceof Relation){ relations.add((Relation) entities.get(l)); @@ -120,15 +121,15 @@ public class OsmStorageWriter { writeStartElement(streamWriter, ELEM_RELATION, INDENT); streamWriter.writeAttribute(ATTR_ID, r.getId()+""); writeEntityAttributes(streamWriter, r, entityInfo.get(r.getId())); - for(Entry e : r.getMembersMap().entrySet()){ + for(Entry e : r.getMembersMap().entrySet()){ writeStartElement(streamWriter, ELEM_MEMBER, INDENT2); - streamWriter.writeAttribute(ATTR_REF, e.getKey()+""); + streamWriter.writeAttribute(ATTR_REF, e.getKey().getId()+""); String s = e.getValue(); if(s == null){ s = ""; } streamWriter.writeAttribute(ATTR_ROLE, s); - streamWriter.writeAttribute(ATTR_TYPE, getEntityType(entities, e.getKey())); + streamWriter.writeAttribute(ATTR_TYPE, e.getKey().getType().toString().toLowerCase()); writeEndElement(streamWriter, INDENT2); } writeTags(streamWriter, r); @@ -170,18 +171,6 @@ public class OsmStorageWriter { } } - private String getEntityType(Map entities , Long id){ - Entity e = entities.get(id); - if(e instanceof Way){ - return "way"; - } else if(e instanceof Relation){ - return "relation"; - } - return "node"; - } - - - public boolean couldBeWrited(MapObject e){ if(!Algoritms.isEmpty(e.getName()) && e.getLocation() != null){ return true; diff --git a/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java b/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java index 7bcec8839b..0dff899d3b 100644 --- a/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java +++ b/DataExtractionOSM/src/com/osmand/osm/util/MinskTransReader.java @@ -39,6 +39,8 @@ import com.osmand.osm.MapUtils; import com.osmand.osm.Node; import com.osmand.osm.Relation; import com.osmand.osm.Way; +import com.osmand.osm.Entity.EntityId; +import com.osmand.osm.Entity.EntityType; import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.io.IOsmStorageFilter; import com.osmand.osm.io.OsmBaseStorage; @@ -351,7 +353,7 @@ public class MinskTransReader { relation.putTag("type", "route"); relation.putTag("generated", "yes"); checkedRoutes.put(s, relation); - storage.getRegisteredEntities().put(relation.getId(), relation); + storage.getRegisteredEntities().put(new EntityId(EntityType.RELATION, relation.getId()), relation); System.out.println("[ADD] Registered new route " + s); } Relation relation = checkedRoutes.get(s); @@ -372,19 +374,19 @@ public class MinskTransReader { throw new IllegalArgumentException("Something wrong check " + st.stopId); } node.putTag("generated", "yes"); - storage.getRegisteredEntities().put(node.getId(), node); + storage.getRegisteredEntities().put(new EntityId(EntityType.NODE, node.getId()), node); System.out.println("[ADD] Added new bus_stop : " + node.getId() + " " + st.name + " minsktrans_stop_id " + st.stopId); correlated.put(stop, node); } if (i == 0 || i == r.routeStops.size() - 1) { if (direct) { - relation.addMember(correlated.get(stop).getId(), "stop"); + relation.addMember(correlated.get(stop).getId(), EntityType.NODE, "stop"); } } else { if (direct) { - relation.addMember(correlated.get(stop).getId(), "forward:stop"); + relation.addMember(correlated.get(stop).getId(), EntityType.NODE, "forward:stop"); } else { - relation.addMember(correlated.get(stop).getId(), "backward:stop"); + relation.addMember(correlated.get(stop).getId(), EntityType.NODE, "backward:stop"); } }