use of net.osmand.data.TransportStop in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method writeRouteStops.
private void writeRouteStops(TransportRoute r, List<TransportStop> stops) throws SQLException {
int i = 0;
for (TransportStop s : stops) {
if (!visitedStops.contains(s.getId())) {
transStopsStat.setLong(1, s.getId());
transStopsStat.setDouble(2, s.getLocation().getLatitude());
transStopsStat.setDouble(3, s.getLocation().getLongitude());
transStopsStat.setString(4, s.getName());
transStopsStat.setString(5, s.getEnName(false));
int x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
int y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
addBatch(transStopsStat);
try {
transportStopsTree.insert(new LeafElement(new Rect(x, y, x, y), s.getId()));
} catch (RTreeInsertException e) {
throw new IllegalArgumentException(e);
} catch (IllegalValueException e) {
throw new IllegalArgumentException(e);
}
visitedStops.add(s.getId());
}
transRouteStopsStat.setLong(1, r.getId());
transRouteStopsStat.setLong(2, s.getId());
transRouteStopsStat.setInt(3, i++);
addBatch(transRouteStopsStat);
}
}
use of net.osmand.data.TransportStop in project OsmAnd-tools by osmandapp.
the class IndexTransportCreator method processTransportRelationV1.
private boolean processTransportRelationV1(Relation rel, TransportRoute directRoute, TransportRoute backwardRoute) {
final Map<TransportStop, Integer> forwardStops = new LinkedHashMap<TransportStop, Integer>();
final Map<TransportStop, Integer> backwardStops = new LinkedHashMap<TransportStop, Integer>();
int currentStop = 0;
int forwardStop = 0;
int backwardStop = 0;
for (RelationMember e : rel.getMembers()) {
if (e.getRole().contains("stop") || e.getRole().contains("platform")) {
// $NON-NLS-1$
if (e.getEntity() instanceof Node) {
TransportStop stop = EntityParser.parseTransportStop(e.getEntity());
Relation stopArea = stopAreas.get(EntityId.valueOf(e.getEntity()));
if (stopArea != null) {
stop.copyNames(stopArea.getTag(OSMTagKey.NAME), stopArea.getTag(OSMTagKey.NAME_EN), stopArea.getNameTags(), true);
}
// $NON-NLS-1$
boolean forward = e.getRole().contains("forward");
// $NON-NLS-1$
boolean backward = e.getRole().contains("backward");
currentStop++;
if (forward || !backward) {
forwardStop++;
}
if (backward) {
backwardStop++;
}
boolean common = !forward && !backward;
int index = -1;
int i = e.getRole().length() - 1;
int accum = 1;
while (i >= 0 && Character.isDigit(e.getRole().charAt(i))) {
if (index < 0) {
index = 0;
}
index = accum * Character.getNumericValue(e.getRole().charAt(i)) + index;
accum *= 10;
i--;
}
if (index < 0) {
index = forward ? forwardStop : (backward ? backwardStop : currentStop);
}
if (forward || common) {
forwardStops.put(stop, index);
directRoute.getForwardStops().add(stop);
}
if (backward || common) {
if (common) {
// put with negative index
backwardStops.put(stop, -index);
} else {
backwardStops.put(stop, index);
}
backwardRoute.getForwardStops().add(stop);
}
}
} else if (e.getEntity() instanceof Way) {
int dir = e.getRole().equals("backward") ? -1 : (e.getRole().equals("forward") ? 1 : 0);
if (dir >= 0) {
directRoute.addWay((Way) e.getEntity());
}
if (dir <= 0) {
backwardRoute.addWay((Way) e.getEntity());
}
}
}
if (forwardStops.isEmpty() && backwardStops.isEmpty()) {
return false;
}
Collections.sort(directRoute.getForwardStops(), new Comparator<TransportStop>() {
@Override
public int compare(TransportStop o1, TransportStop o2) {
return forwardStops.get(o1) - forwardStops.get(o2);
}
});
// all common stops are with negative index (reeval them)
for (TransportStop s : new ArrayList<TransportStop>(backwardStops.keySet())) {
if (backwardStops.get(s) < 0) {
backwardStops.put(s, backwardStops.size() + backwardStops.get(s) - 1);
}
}
Collections.sort(backwardRoute.getForwardStops(), new Comparator<TransportStop>() {
@Override
public int compare(TransportStop o1, TransportStop o2) {
return backwardStops.get(o1) - backwardStops.get(o2);
}
});
return true;
}
use of net.osmand.data.TransportStop in project OsmAnd-tools by osmandapp.
the class BinaryMapIndexWriter method writeTransportRoute.
public void writeTransportRoute(long idRoute, String routeName, String routeEnName, String ref, String operator, String type, int dist, String color, List<TransportStop> directStops, List<byte[]> directRoute, Map<String, Integer> stringTable, Map<Long, Long> transportRoutesRegistry) throws IOException {
checkPeekState(TRANSPORT_ROUTES);
TransportRoute.Builder tRoute = OsmandOdb.TransportRoute.newBuilder();
tRoute.setRef(ref);
tRoute.setOperator(registerString(stringTable, operator));
tRoute.setType(registerString(stringTable, type));
tRoute.setId(idRoute);
tRoute.setName(registerString(stringTable, routeName));
tRoute.setDistance(dist);
tRoute.setColor(registerString(stringTable, color));
if (routeEnName != null) {
tRoute.setNameEn(registerString(stringTable, routeEnName));
}
List<TransportStop> stops = directStops;
long id = 0;
int x24 = 0;
int y24 = 0;
for (TransportStop st : stops) {
TransportRouteStop.Builder tStop = OsmandOdb.TransportRouteStop.newBuilder();
tStop.setId(st.getId() - id);
id = st.getId();
int x = (int) MapUtils.getTileNumberX(24, st.getLocation().getLongitude());
int y = (int) MapUtils.getTileNumberY(24, st.getLocation().getLatitude());
tStop.setDx(x - x24);
tStop.setDy(y - y24);
x24 = x;
y24 = y;
tStop.setName(registerString(stringTable, st.getName()));
if (st.getEnName(false) != null) {
tStop.setNameEn(registerString(stringTable, st.getEnName(false)));
}
tRoute.addDirectStops(tStop.build());
}
if (directRoute != null) {
writeTransportRouteCoordinates(directRoute);
tRoute.setGeometry(ByteString.copyFrom(mapDataBuf.toArray()));
}
codedOutStream.writeTag(OsmandOdb.TransportRoutes.ROUTES_FIELD_NUMBER, FieldType.MESSAGE.getWireType());
if (transportRoutesRegistry != null) {
transportRoutesRegistry.put(idRoute, getFilePointer());
}
codedOutStream.writeMessageNoTag(tRoute.build());
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class BinaryInspector method printTransportDetailInfo.
private void printTransportDetailInfo(VerboseInfo verbose, BinaryMapIndexReader index, TransportIndex p) throws IOException {
SearchRequest<TransportStop> sr = BinaryMapIndexReader.buildSearchTransportRequest(MapUtils.get31TileNumberX(verbose.lonleft), MapUtils.get31TileNumberX(verbose.lonright), MapUtils.get31TileNumberY(verbose.lattop), MapUtils.get31TileNumberY(verbose.latbottom), -1, null);
List<TransportStop> stops = index.searchTransportIndex(sr);
Map<Long, TransportRoute> rs = new LinkedHashMap<>();
List<String> lrs = new ArrayList<>();
println("\nStops:");
for (TransportStop s : stops) {
lrs.clear();
for (int pnt : s.getReferencesToRoutes()) {
TransportRoute route;
if (!lrs.contains(pnt)) {
TIntObjectHashMap<TransportRoute> pts = index.getTransportRoutes(new int[] { pnt });
route = pts.valueCollection().iterator().next();
rs.put((long) pnt, route);
} else {
route = rs.get(pnt);
}
if (route != null) {
// lrs.add(route.getRef() + " " + route.getName(verbose.lang));
lrs.add(route.getRef() + " " + route.getType());
}
}
println(" " + s.getName(verbose.lang) + ": " + lrs + " " + s.getLocation());
}
println("\nRoutes:");
for (TransportRoute s : rs.values()) {
List<String> stopsString = new ArrayList<>();
for (TransportStop st : s.getForwardStops()) {
stopsString.add(st.getName(verbose.lang));
}
println(" " + s.getRef() + " " + s.getType() + " " + s.getName(verbose.lang) + ": " + stopsString);
}
}
use of net.osmand.data.TransportStop in project Osmand by osmandapp.
the class BinaryMapIndexReader method testTransportSearch.
private static void testTransportSearch(BinaryMapIndexReader reader) throws IOException {
// test transport
for (TransportIndex i : reader.transportIndexes) {
println("Transport bounds : " + i.left + " " + i.right + " " + i.top + " " + i.bottom);
}
for (TransportStop s : reader.searchTransportIndex(buildSearchTransportRequest(sleft, sright, stop, sbottom, -1, null))) {
println(s.getName());
TIntObjectHashMap<TransportRoute> routes = reader.getTransportRoutes(s.getReferencesToRoutes());
for (net.osmand.data.TransportRoute route : routes.valueCollection()) {
println(" " + route.getRef() + " " + route.getName() + " " + route.getDistance() + " " + route.getAvgBothDistance());
StringBuilder b = new StringBuilder();
for (Way w : route.getForwardWays()) {
b.append(w.getNodes()).append(" ");
}
println(" forward ways: " + b.toString());
}
}
}
Aggregations