fix for incomplete roads reading

This commit is contained in:
MadWasp79 2020-06-30 12:03:51 +03:00
parent 793e7f6560
commit 9db069dd05
4 changed files with 34 additions and 23 deletions

View file

@ -111,7 +111,7 @@ public class BinaryMapIndexReader {
/*private*/ List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>(); /*private*/ List<TransportIndex> transportIndexes = new ArrayList<TransportIndex>();
/*private*/ List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>(); /*private*/ List<RouteRegion> routingIndexes = new ArrayList<RouteRegion>();
/*private*/ List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>(); /*private*/ List<BinaryIndexPart> indexes = new ArrayList<BinaryIndexPart>();
TLongObjectHashMap<IncompleteTransportRoute> incompleteTransportRoutes = null; Map<TransportIndex, TLongObjectHashMap<IncompleteTransportRoute>> incompleteTransportRoutes = null;
protected CodedInputStream codedIS; protected CodedInputStream codedIS;
@ -2655,15 +2655,17 @@ public class BinaryMapIndexReader {
} }
} }
public TLongObjectHashMap<IncompleteTransportRoute> getIncompleteTransportRoutes() throws InvalidProtocolBufferException, IOException { public Map<TransportIndex, TLongObjectHashMap<IncompleteTransportRoute>> getIncompleteTransportRoutes() throws InvalidProtocolBufferException, IOException {
if (incompleteTransportRoutes == null) { if (incompleteTransportRoutes == null) {
incompleteTransportRoutes = new TLongObjectHashMap<>(); incompleteTransportRoutes = new HashMap<TransportIndex, TLongObjectHashMap<IncompleteTransportRoute>>();
for (TransportIndex ti : transportIndexes) { for (TransportIndex ti : transportIndexes) {
if (ti.incompleteRoutesLength > 0) { if (ti.incompleteRoutesLength > 0) {
TLongObjectHashMap<IncompleteTransportRoute> indexIncompleteRoutes = new TLongObjectHashMap<IncompleteTransportRoute>();
codedIS.seek(ti.incompleteRoutesOffset); codedIS.seek(ti.incompleteRoutesOffset);
int oldLimit = codedIS.pushLimit(ti.incompleteRoutesLength); int oldLimit = codedIS.pushLimit(ti.incompleteRoutesLength);
transportAdapter.readIncompleteRoutesList(incompleteTransportRoutes); transportAdapter.readIncompleteRoutesList(indexIncompleteRoutes, ti.filePointer);
codedIS.popLimit(oldLimit); codedIS.popLimit(oldLimit);
incompleteTransportRoutes.put(ti, indexIncompleteRoutes);
} }
} }
} }

View file

@ -11,6 +11,7 @@ import com.google.protobuf.WireFormat;
import gnu.trove.map.hash.TIntObjectHashMap; import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap; import gnu.trove.map.hash.TLongObjectHashMap;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.IncompleteTransportRoute;
import net.osmand.data.TransportSchedule; import net.osmand.data.TransportSchedule;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.data.TransportStopExit; import net.osmand.data.TransportStopExit;
@ -71,7 +72,6 @@ public class BinaryMapTransportReaderAdapter {
return bottom; return bottom;
} }
IndexStringTable stringTable = null; IndexStringTable stringTable = null;
} }
@ -251,8 +251,9 @@ public class BinaryMapTransportReaderAdapter {
return ((char) i)+""; return ((char) i)+"";
} }
public void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes) throws IOException { public void readIncompleteRoutesList(TLongObjectHashMap<net.osmand.data.IncompleteTransportRoute> incompleteRoutes, int transportIndexStart) throws IOException {
boolean end = false; boolean end = false;
int offset = codedIS.getTotalBytesRead();
while (!end) { while (!end) {
int t = codedIS.readTag(); int t = codedIS.readTag();
int tag = WireFormat.getTagFieldNumber(t); int tag = WireFormat.getTagFieldNumber(t);
@ -263,7 +264,7 @@ public class BinaryMapTransportReaderAdapter {
case OsmandOdb.IncompleteTransportRoutes.ROUTES_FIELD_NUMBER: case OsmandOdb.IncompleteTransportRoutes.ROUTES_FIELD_NUMBER:
int l = codedIS.readRawVarint32(); int l = codedIS.readRawVarint32();
int olds = codedIS.pushLimit(l); int olds = codedIS.pushLimit(l);
net.osmand.data.IncompleteTransportRoute ir = readIncompleteRoute(); net.osmand.data.IncompleteTransportRoute ir = readIncompleteRoute(offset, transportIndexStart);
net.osmand.data.IncompleteTransportRoute itr = incompleteRoutes.get(ir.getRouteId()); net.osmand.data.IncompleteTransportRoute itr = incompleteRoutes.get(ir.getRouteId());
if(itr != null) { if(itr != null) {
itr.setNextLinkedRoute(ir); itr.setNextLinkedRoute(ir);
@ -281,7 +282,7 @@ public class BinaryMapTransportReaderAdapter {
} }
public net.osmand.data.IncompleteTransportRoute readIncompleteRoute() throws IOException { public net.osmand.data.IncompleteTransportRoute readIncompleteRoute(int readOffset, int transportIndexStart) throws IOException {
net.osmand.data.IncompleteTransportRoute dataObject = new net.osmand.data.IncompleteTransportRoute(); net.osmand.data.IncompleteTransportRoute dataObject = new net.osmand.data.IncompleteTransportRoute();
boolean end = false; boolean end = false;
while(!end){ while(!end){
@ -295,7 +296,12 @@ public class BinaryMapTransportReaderAdapter {
dataObject.setRouteId(codedIS.readUInt64()); dataObject.setRouteId(codedIS.readUInt64());
break; break;
case OsmandOdb.IncompleteTransportRoute.ROUTEREF_FIELD_NUMBER : case OsmandOdb.IncompleteTransportRoute.ROUTEREF_FIELD_NUMBER :
dataObject.setRouteOffset(codedIS.readRawVarint32()); int delta = codedIS.readRawVarint32();
if (delta > transportIndexStart) {
dataObject.setRouteOffset(delta);
} else {
dataObject.setRouteOffset(readOffset - delta);
}
break; break;
case OsmandOdb.IncompleteTransportRoute.OPERATOR_FIELD_NUMBER : case OsmandOdb.IncompleteTransportRoute.OPERATOR_FIELD_NUMBER :
skipUnknownField(t); skipUnknownField(t);
@ -318,7 +324,6 @@ public class BinaryMapTransportReaderAdapter {
break; break;
} }
} }
return dataObject; return dataObject;
} }

View file

@ -865,7 +865,6 @@ public class TransportRoutePlanner {
lst.add(segment); lst.add(segment);
} }
} else { } else {
// MapUtils.getDistance(s.getLocation(), route.getForwardStops().get(158).getLocation());
System.err.println(String.format("Routing error: missing stop '%s' in route '%s' id: %d", System.err.println(String.format("Routing error: missing stop '%s' in route '%s' id: %d",
s.toString(), route.getRef(), route.getId() / 2)); s.toString(), route.getRef(), route.getId() / 2));
} }

View file

@ -8,6 +8,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import gnu.trove.iterator.TIntObjectIterator; import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
@ -15,6 +16,7 @@ import gnu.trove.map.hash.TIntObjectHashMap;
import gnu.trove.map.hash.TLongObjectHashMap; import gnu.trove.map.hash.TLongObjectHashMap;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest; import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex;
import net.osmand.data.IncompleteTransportRoute; import net.osmand.data.IncompleteTransportRoute;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.TransportRoute; import net.osmand.data.TransportRoute;
@ -43,7 +45,6 @@ public class TransportStopsRouteReader {
List<TransportStop> stops = r.searchTransportIndex(sr); List<TransportStop> stops = r.searchTransportIndex(sr);
TIntObjectHashMap<TransportRoute> routesToLoad = mergeTransportStops(r, loadedTransportStops, stops); TIntObjectHashMap<TransportRoute> routesToLoad = mergeTransportStops(r, loadedTransportStops, stops);
loadRoutes(r, routesToLoad); loadRoutes(r, routesToLoad);
for (TransportStop stop : stops) { for (TransportStop stop : stops) {
// skip missing stops // skip missing stops
if (stop.isMissingStop()) { if (stop.isMissingStop()) {
@ -388,7 +389,9 @@ public class TransportStopsRouteReader {
List<TransportRoute> allRoutes = null; List<TransportRoute> allRoutes = null;
for (BinaryMapIndexReader bmir : routesFilesCache.keySet()) { for (BinaryMapIndexReader bmir : routesFilesCache.keySet()) {
// here we could limit routeMap indexes by only certain bbox around start / end (check comment on field) // here we could limit routeMap indexes by only certain bbox around start / end (check comment on field)
IncompleteTransportRoute ptr = bmir.getIncompleteTransportRoutes().get(baseRoute.getId()); if (!bmir.getIncompleteTransportRoutes().isEmpty()) {
for (Entry<TransportIndex, TLongObjectHashMap<IncompleteTransportRoute>> entry : bmir.getIncompleteTransportRoutes().entrySet()) {
IncompleteTransportRoute ptr = entry.getValue().get(baseRoute.getId());
if (ptr != null) { if (ptr != null) {
TIntArrayList lst = new TIntArrayList(); TIntArrayList lst = new TIntArrayList();
while (ptr != null) { while (ptr != null) {
@ -403,6 +406,8 @@ public class TransportStopsRouteReader {
} }
} }
} }
}
}
return allRoutes; return allRoutes;
} }