Search in sources :

Example 1 with TransportRoute

use of net.osmand.data.TransportRoute in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method iterateMainEntity.

public void iterateMainEntity(Entity e, OsmDbAccessorContext ctx) throws SQLException {
    if (e instanceof Relation && e.getTag(OSMTagKey.ROUTE) != null) {
        ctx.loadEntityRelation((Relation) e);
        List<TransportRoute> troutes = new ArrayList<>();
        indexTransportRoute((Relation) e, troutes);
        for (TransportRoute route : troutes) {
            insertTransportIntoIndex(route);
        }
    }
}
Also used : Relation(net.osmand.osm.edit.Relation) TransportRoute(net.osmand.data.TransportRoute) ArrayList(java.util.ArrayList)

Example 2 with TransportRoute

use of net.osmand.data.TransportRoute in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method indexTransportRoute.

private void indexTransportRoute(Relation rel, List<TransportRoute> troutes) {
    String ref = rel.getTag(OSMTagKey.REF);
    String route = rel.getTag(OSMTagKey.ROUTE);
    String operator = rel.getTag(OSMTagKey.OPERATOR);
    String color = rel.getTag(OSMTagKey.COLOUR);
    Relation master = masterRoutes.get(rel.getId());
    if (master != null) {
        if (ref == null) {
            ref = master.getTag(OSMTagKey.REF);
        }
        if (route == null) {
            route = master.getTag(OSMTagKey.ROUTE);
        }
        if (operator == null) {
            operator = master.getTag(OSMTagKey.OPERATOR);
        }
        if (color == null) {
            color = master.getTag(OSMTagKey.COLOUR);
        }
    }
    if (route == null || ref == null) {
        return;
    }
    if (!acceptedRoutes.contains(route)) {
        return;
    }
    if (color != null) {
        String tmp = MapRenderingTypesEncoder.formatColorToPalette(color, false).replaceAll("_", "");
        color = "subwayText" + tmp.substring(0, 1).toUpperCase() + tmp.substring(1) + "Color";
    }
    TransportRoute directRoute = EntityParser.parserRoute(rel, ref);
    directRoute.setOperator(operator);
    directRoute.setColor(color);
    directRoute.setType(route);
    directRoute.setRef(ref);
    directRoute.setId(directRoute.getId() << 1);
    if (processTransportRelationV2(rel, directRoute)) {
        // try new transport relations first
        troutes.add(directRoute);
    } else {
        TransportRoute backwardRoute = EntityParser.parserRoute(rel, ref);
        backwardRoute.setOperator(operator);
        backwardRoute.setColor(color);
        backwardRoute.setType(route);
        backwardRoute.setRef(ref);
        backwardRoute.setName(reverseName(ref, backwardRoute.getName()));
        if (!Algorithms.isEmpty(backwardRoute.getEnName(false))) {
            backwardRoute.setEnName(reverseName(ref, backwardRoute.getEnName(false)));
        }
        if (processTransportRelationV1(rel, directRoute, backwardRoute)) {
            // old relation style otherwise
            backwardRoute.setId((backwardRoute.getId() << 1) + 1);
            troutes.add(directRoute);
            troutes.add(backwardRoute);
        }
    }
}
Also used : Relation(net.osmand.osm.edit.Relation) TransportRoute(net.osmand.data.TransportRoute)

Example 3 with TransportRoute

use of net.osmand.data.TransportRoute in project Osmand by osmandapp.

the class BinaryMapIndexReader method getTransportRoutes.

/**
 * Transport public methods
 */
public TIntObjectHashMap<TransportRoute> getTransportRoutes(int[] filePointers) throws IOException {
    TIntObjectHashMap<TransportRoute> result = new TIntObjectHashMap<TransportRoute>();
    Map<TransportIndex, TIntArrayList> groupPoints = new HashMap<TransportIndex, TIntArrayList>();
    for (int filePointer : filePointers) {
        TransportIndex ind = getTransportIndex(filePointer);
        if (ind != null) {
            if (!groupPoints.containsKey(ind)) {
                groupPoints.put(ind, new TIntArrayList());
            }
            groupPoints.get(ind).add(filePointer);
        }
    }
    Iterator<Entry<TransportIndex, TIntArrayList>> it = groupPoints.entrySet().iterator();
    if (it.hasNext()) {
        Entry<TransportIndex, TIntArrayList> e = it.next();
        TransportIndex ind = e.getKey();
        TIntArrayList pointers = e.getValue();
        pointers.sort();
        TIntObjectHashMap<String> stringTable = new TIntObjectHashMap<String>();
        for (int i = 0; i < pointers.size(); i++) {
            int filePointer = pointers.get(i);
            TransportRoute transportRoute = transportAdapter.getTransportRoute(filePointer, stringTable, false);
            result.put(filePointer, transportRoute);
        }
        transportAdapter.initializeStringTable(ind, stringTable);
        for (TransportRoute r : result.values(new TransportRoute[result.size()])) {
            transportAdapter.initializeNames(false, r, stringTable);
        }
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) HashMap(java.util.HashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) Entry(java.util.Map.Entry) TransportRoute(net.osmand.data.TransportRoute) TIntObjectHashMap(gnu.trove.map.hash.TIntObjectHashMap) TransportIndex(net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)

Example 4 with TransportRoute

use of net.osmand.data.TransportRoute in project Osmand by osmandapp.

the class TransportStopController method addRoutes.

private void addRoutes(List<TransportStopRoute> routes, boolean useEnglishNames, TransportIndexRepository t, TransportStop s, TransportStop refStop, int dist) {
    Collection<TransportRoute> rts = t.getRouteForStop(s);
    if (rts != null) {
        for (TransportRoute rs : rts) {
            TransportStopType type = TransportStopType.findType(rs.getType());
            if (topType == null && type != null && type.isTopType()) {
                topType = type;
            }
            if (!containsRef(routes, rs)) {
                TransportStopRoute r = new TransportStopRoute();
                r.type = type;
                r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
                r.route = rs;
                r.refStop = refStop;
                r.stop = s;
                r.distance = dist;
                routes.add(r);
            }
        }
    }
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) TransportStopType(net.osmand.plus.transport.TransportStopType) TransportRoute(net.osmand.data.TransportRoute)

Example 5 with TransportRoute

use of net.osmand.data.TransportRoute in project Osmand by osmandapp.

the class AmenityMenuController method addRoutes.

private void addRoutes(boolean useEnglishNames, TransportIndexRepository t, TransportStop s, int dist, boolean isSubwayEntrance) {
    Collection<TransportRoute> rts = t.getRouteForStop(s);
    if (rts != null) {
        for (TransportRoute rs : rts) {
            if (!containsRef(rs)) {
                TransportStopType type = TransportStopType.findType(rs.getType());
                if (isSubwayEntrance && type != TransportStopType.SUBWAY && dist > 150) {
                    continue;
                }
                TransportStopRoute r = new TransportStopRoute();
                r.type = type;
                r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName();
                r.route = rs;
                r.stop = s;
                r.distance = dist;
                this.routes.add(r);
            }
        }
    }
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) TransportStopType(net.osmand.plus.transport.TransportStopType) TransportRoute(net.osmand.data.TransportRoute)

Aggregations

TransportRoute (net.osmand.data.TransportRoute)8 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 ArrayList (java.util.ArrayList)2 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)2 TransportStop (net.osmand.data.TransportStop)2 Relation (net.osmand.osm.edit.Relation)2 TransportStopRoute (net.osmand.plus.transport.TransportStopRoute)2 TransportStopType (net.osmand.plus.transport.TransportStopType)2 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Entry (java.util.Map.Entry)1 Way (net.osmand.osm.edit.Way)1