Transport route
This commit is contained in:
parent
9fe736957d
commit
87f49ed3d9
1 changed files with 15 additions and 20 deletions
|
@ -13,14 +13,10 @@ import java.util.Map;
|
||||||
import java.util.PriorityQueue;
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
import gnu.trove.iterator.TIntIterator;
|
import gnu.trove.iterator.TIntIterator;
|
||||||
import gnu.trove.iterator.TIntObjectIterator;
|
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
import gnu.trove.map.TIntObjectMap;
|
|
||||||
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.NativeLibrary;
|
import net.osmand.NativeLibrary;
|
||||||
import net.osmand.binary.BinaryIndexPart;
|
|
||||||
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.data.IncompleteTransportRoute;
|
import net.osmand.data.IncompleteTransportRoute;
|
||||||
|
@ -32,7 +28,6 @@ import net.osmand.data.TransportStop;
|
||||||
import net.osmand.data.TransportStopExit;
|
import net.osmand.data.TransportStopExit;
|
||||||
import net.osmand.osm.edit.Node;
|
import net.osmand.osm.edit.Node;
|
||||||
import net.osmand.osm.edit.Way;
|
import net.osmand.osm.edit.Way;
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
public class TransportRoutePlanner {
|
public class TransportRoutePlanner {
|
||||||
|
@ -822,10 +817,11 @@ public class TransportRoutePlanner {
|
||||||
}
|
}
|
||||||
if (rrs != null && !multifileStop.isDeleted()) {
|
if (rrs != null && !multifileStop.isDeleted()) {
|
||||||
for (int rr : rrs) {
|
for (int rr : rrs) {
|
||||||
// here we should assign only complete routes:
|
|
||||||
TransportRoute route = localFileRoutes.get(rr);
|
TransportRoute route = localFileRoutes.get(rr);
|
||||||
if (route == null) {
|
if (route == null) {
|
||||||
System.err.println(String.format("Something went wrong by loading combined route %d for stop %s", route.getId(), stop));
|
System.err.println(
|
||||||
|
String.format("Something went wrong by loading combined route %d for stop %s",
|
||||||
|
rr, stop));
|
||||||
} else {
|
} else {
|
||||||
TransportRoute combinedRoute = getCombinedRoute(route, r.getFile().getName());
|
TransportRoute combinedRoute = getCombinedRoute(route, r.getFile().getName());
|
||||||
if (combinedRoute == null) {
|
if (combinedRoute == null) {
|
||||||
|
@ -946,25 +942,24 @@ public class TransportRoutePlanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransportRoute combineRoute(TransportRoute route, String fileName) throws IOException {
|
private TransportRoute combineRoute(TransportRoute route, String fileName) throws IOException {
|
||||||
//1.Get all available route parts;
|
// 1. Get all available route parts;
|
||||||
List<TransportRoute> result = new ArrayList<>(findIncompleteRouteParts(route));
|
List<TransportRoute> result = new ArrayList<>(findIncompleteRouteParts(route));
|
||||||
List<Way> allWays = getAllWays(result); //TODO check ways for right order? Artifacts during drawing.
|
List<Way> allWays = getAllWays(result); //TODO check ways for right order? Artifacts during drawing.
|
||||||
|
|
||||||
//2. Get massive of segments:
|
// 2. Get array of segments:
|
||||||
List<List<TransportStop>> segments = parseRoutePartsToSegments(result);
|
List<List<TransportStop>> segments = parseRoutePartsToSegments(result);
|
||||||
//TODO check for api? reversed works only from 24th
|
Collections.sort(segments, compareSegsBySize);
|
||||||
Collections.sort(segments, compareSegsBySize.reversed());
|
|
||||||
|
|
||||||
//3. Merge segments and remove excess missingStops (when they are closer then MISSING_STOP_SEARCH_RADIUS):
|
// 3. Merge segments and remove excess missingStops (when they are closer then MISSING_STOP_SEARCH_RADIUS):
|
||||||
//4. Check for missingStops. If they present in the middle/there more then one segment - we have a hole in the map data
|
// 4. Check for missingStops. If they present in the middle/there more then one segment - we have a hole in the map data
|
||||||
List<List<TransportStop>> mergedSegments = combineSegments(segments);
|
List<List<TransportStop>> mergedSegments = combineSegments(segments);
|
||||||
|
|
||||||
|
|
||||||
//5. Create combined TransportRoute and return it
|
// 5. Create combined TransportRoute and return it
|
||||||
if (mergedSegments.size() > 1) {
|
if (mergedSegments.size() > 1 || mergedSegments.size() == 0) {
|
||||||
//TODO sort incomplete routes (and remove missingStops) and merge into one?
|
// TODO sort incomplete routes (and remove missingStops) and merge into one?
|
||||||
return null;
|
return route;
|
||||||
} else {
|
} else {
|
||||||
return new TransportRoute(route, mergedSegments.get(0), allWays);
|
return new TransportRoute(route, mergedSegments.get(0), allWays);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -978,8 +973,8 @@ public class TransportRoutePlanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
Comparator<List<TransportStop>> compareSegsBySize = new Comparator<List<TransportStop>>() {
|
Comparator<List<TransportStop>> compareSegsBySize = new Comparator<List<TransportStop>>() {
|
||||||
public int compare(List<TransportStop> s1, List<TransportStop> s2) {
|
public int compare(List<TransportStop> s1, List<TransportStop> s2) {
|
||||||
return ((Integer)s1.size()).compareTo((Integer)s2.size());
|
return -Integer.compare(s1.size(), s2.size());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue