Search in sources :

Example 16 with TransportStop

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

the class BinaryMapTransportReaderAdapter method getTransportRoute.

public net.osmand.data.TransportRoute getTransportRoute(int filePointer, TIntObjectHashMap<String> stringTable, boolean onlyDescription) throws IOException {
    codedIS.seek(filePointer);
    int routeLength = codedIS.readRawVarint32();
    int old = codedIS.pushLimit(routeLength);
    net.osmand.data.TransportRoute dataObject = new net.osmand.data.TransportRoute();
    boolean end = false;
    long rid = 0;
    int rx = 0;
    int ry = 0;
    while (!end) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                end = true;
                break;
            case OsmandOdb.TransportRoute.DISTANCE_FIELD_NUMBER:
                dataObject.setDistance(codedIS.readUInt32());
                break;
            case OsmandOdb.TransportRoute.ID_FIELD_NUMBER:
                dataObject.setId(codedIS.readUInt64());
                break;
            case OsmandOdb.TransportRoute.REF_FIELD_NUMBER:
                dataObject.setRef(codedIS.readString());
                break;
            case OsmandOdb.TransportRoute.TYPE_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setType(regStr(stringTable));
                break;
            case OsmandOdb.TransportRoute.NAME_EN_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setEnName(regStr(stringTable));
                break;
            case OsmandOdb.TransportRoute.NAME_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setName(regStr(stringTable));
                break;
            case OsmandOdb.TransportRoute.OPERATOR_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setOperator(regStr(stringTable));
                break;
            case OsmandOdb.TransportRoute.COLOR_FIELD_NUMBER:
                dataObject.setColor(regStr(stringTable));
                break;
            case OsmandOdb.TransportRoute.GEOMETRY_FIELD_NUMBER:
                int sizeL = codedIS.readRawVarint32();
                int pold = codedIS.pushLimit(sizeL);
                int px = 0;
                int py = 0;
                Way w = new Way(-1);
                while (codedIS.getBytesUntilLimit() > 0) {
                    int ddx = (codedIS.readSInt32() << BinaryMapIndexReader.SHIFT_COORDINATES);
                    int ddy = (codedIS.readSInt32() << BinaryMapIndexReader.SHIFT_COORDINATES);
                    if (ddx == 0 && ddy == 0) {
                        if (w.getNodes().size() > 0) {
                            dataObject.addWay(w);
                        }
                        w = new Way(-1);
                    } else {
                        int x = ddx + px;
                        int y = ddy + py;
                        w.addNode(new Node(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x), -1));
                        px = x;
                        py = y;
                    }
                }
                if (w.getNodes().size() > 0) {
                    dataObject.addWay(w);
                }
                codedIS.popLimit(pold);
                break;
            // break;
            case OsmandOdb.TransportRoute.DIRECTSTOPS_FIELD_NUMBER:
                if (onlyDescription) {
                    end = true;
                    codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
                    break;
                }
                int length = codedIS.readRawVarint32();
                int olds = codedIS.pushLimit(length);
                TransportStop stop = readTransportRouteStop(rx, ry, rid, stringTable, filePointer);
                dataObject.getForwardStops().add(stop);
                rid = stop.getId();
                rx = (int) MapUtils.getTileNumberX(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, stop.getLocation().getLongitude());
                ry = (int) MapUtils.getTileNumberY(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, stop.getLocation().getLatitude());
                codedIS.popLimit(olds);
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
    codedIS.popLimit(old);
    return dataObject;
}
Also used : Node(net.osmand.osm.edit.Node) TransportStop(net.osmand.data.TransportStop) Way(net.osmand.osm.edit.Way)

Example 17 with TransportStop

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

the class BinaryMapTransportReaderAdapter method readTransportStop.

private TransportStop readTransportStop(int shift, int cleft, int cright, int ctop, int cbottom, SearchRequest<TransportStop> req) throws IOException {
    int tag = WireFormat.getTagFieldNumber(codedIS.readTag());
    if (OsmandOdb.TransportStop.DX_FIELD_NUMBER != tag) {
        throw new IllegalArgumentException();
    }
    int x = codedIS.readSInt32() + cleft;
    tag = WireFormat.getTagFieldNumber(codedIS.readTag());
    if (OsmandOdb.TransportStop.DY_FIELD_NUMBER != tag) {
        throw new IllegalArgumentException();
    }
    int y = codedIS.readSInt32() + ctop;
    if (req.right < x || req.left > x || req.top > y || req.bottom < y) {
        codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
        return null;
    }
    req.numberOfAcceptedObjects++;
    req.cacheTypes.clear();
    TransportStop dataObject = new TransportStop();
    dataObject.setLocation(MapUtils.getLatitudeFromTile(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, y), MapUtils.getLongitudeFromTile(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, x));
    dataObject.setFileOffset(shift);
    while (true) {
        int t = codedIS.readTag();
        tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                dataObject.setReferencesToRoutes(req.cacheTypes.toArray());
                if (dataObject.getName("en").length() == 0) {
                    dataObject.setEnName(Junidecode.unidecode(dataObject.getName()));
                }
                return dataObject;
            case OsmandOdb.TransportStop.ROUTES_FIELD_NUMBER:
                req.cacheTypes.add(shift - codedIS.readUInt32());
                break;
            case OsmandOdb.TransportStop.NAME_EN_FIELD_NUMBER:
                if (req.stringTable != null) {
                    // $NON-NLS-1$
                    dataObject.setEnName(regStr(req.stringTable));
                } else {
                    skipUnknownField(t);
                }
                break;
            case OsmandOdb.TransportStop.NAME_FIELD_NUMBER:
                if (req.stringTable != null) {
                    // $NON-NLS-1$
                    dataObject.setName(regStr(req.stringTable));
                } else {
                    skipUnknownField(t);
                }
                break;
            case OsmandOdb.TransportStop.ID_FIELD_NUMBER:
                dataObject.setId(codedIS.readSInt64());
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : TransportStop(net.osmand.data.TransportStop)

Example 18 with TransportStop

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

the class BinaryMapTransportReaderAdapter method readTransportRouteStop.

private TransportStop readTransportRouteStop(int dx, int dy, long did, TIntObjectHashMap<String> stringTable, int filePointer) throws IOException {
    TransportStop dataObject = new TransportStop();
    dataObject.setFileOffset(codedIS.getTotalBytesRead());
    // dataObject.setReferencesToRoutes(new int[] {filePointer});
    boolean end = false;
    while (!end) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        switch(tag) {
            case 0:
                end = true;
                break;
            case OsmandOdb.TransportRouteStop.NAME_EN_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setEnName(regStr(stringTable));
                break;
            case OsmandOdb.TransportRouteStop.NAME_FIELD_NUMBER:
                // $NON-NLS-1$
                dataObject.setName(regStr(stringTable));
                break;
            case OsmandOdb.TransportRouteStop.ID_FIELD_NUMBER:
                did += codedIS.readSInt64();
                break;
            case OsmandOdb.TransportRouteStop.DX_FIELD_NUMBER:
                dx += codedIS.readSInt32();
                break;
            case OsmandOdb.TransportRouteStop.DY_FIELD_NUMBER:
                dy += codedIS.readSInt32();
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
    dataObject.setId(did);
    dataObject.setLocation(MapUtils.getLatitudeFromTile(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, dy), MapUtils.getLongitudeFromTile(BinaryMapIndexReader.TRANSPORT_STOP_ZOOM, dx));
    return dataObject;
}
Also used : TransportStop(net.osmand.data.TransportStop)

Example 19 with TransportStop

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

the class BinaryMapTransportReaderAdapter method searchTransportTreeBounds.

protected void searchTransportTreeBounds(int pleft, int pright, int ptop, int pbottom, SearchRequest<TransportStop> req) throws IOException {
    int init = 0;
    int lastIndexResult = -1;
    int cright = 0;
    int cleft = 0;
    int ctop = 0;
    int cbottom = 0;
    req.numberOfReadSubtrees++;
    while (true) {
        if (req.isCancelled()) {
            return;
        }
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        if (init == 0xf) {
            // coordinates are init
            init = 0;
            if (cright < req.left || cleft > req.right || ctop > req.bottom || cbottom < req.top) {
                return;
            } else {
                req.numberOfAcceptedSubtrees++;
            }
        }
        switch(tag) {
            case 0:
                return;
            case OsmandOdb.TransportStopsTree.BOTTOM_FIELD_NUMBER:
                cbottom = codedIS.readSInt32() + pbottom;
                init |= 1;
                break;
            case OsmandOdb.TransportStopsTree.LEFT_FIELD_NUMBER:
                cleft = codedIS.readSInt32() + pleft;
                init |= 2;
                break;
            case OsmandOdb.TransportStopsTree.RIGHT_FIELD_NUMBER:
                cright = codedIS.readSInt32() + pright;
                init |= 4;
                break;
            case OsmandOdb.TransportStopsTree.TOP_FIELD_NUMBER:
                ctop = codedIS.readSInt32() + ptop;
                init |= 8;
                break;
            case OsmandOdb.TransportStopsTree.LEAFS_FIELD_NUMBER:
                int stopOffset = codedIS.getTotalBytesRead();
                int length = codedIS.readRawVarint32();
                int oldLimit = codedIS.pushLimit(length);
                if (lastIndexResult == -1) {
                    lastIndexResult = req.getSearchResults().size();
                }
                req.numberOfVisitedObjects++;
                TransportStop transportStop = readTransportStop(stopOffset, cleft, cright, ctop, cbottom, req);
                if (transportStop != null) {
                    req.publish(transportStop);
                }
                codedIS.popLimit(oldLimit);
                break;
            case OsmandOdb.TransportStopsTree.SUBTREES_FIELD_NUMBER:
                // left, ... already initialized
                length = readInt();
                int filePointer = codedIS.getTotalBytesRead();
                if (req.limit == -1 || req.limit >= req.getSearchResults().size()) {
                    oldLimit = codedIS.pushLimit(length);
                    searchTransportTreeBounds(cleft, cright, ctop, cbottom, req);
                    codedIS.popLimit(oldLimit);
                }
                codedIS.seek(filePointer + length);
                if (lastIndexResult >= 0) {
                    throw new IllegalStateException();
                }
                break;
            case OsmandOdb.TransportStopsTree.BASEID_FIELD_NUMBER:
                long baseId = codedIS.readUInt64();
                if (lastIndexResult != -1) {
                    for (int i = lastIndexResult; i < req.getSearchResults().size(); i++) {
                        TransportStop rs = req.getSearchResults().get(i);
                        rs.setId(rs.getId() + baseId);
                    }
                }
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : TransportStop(net.osmand.data.TransportStop)

Example 20 with TransportStop

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

the class TransportStopController method processTransportStop.

public List<TransportStopRoute> processTransportStop() {
    ArrayList<TransportStopRoute> routes = new ArrayList<>();
    List<TransportIndexRepository> reps = getMapActivity().getMyApplication().getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude());
    boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames();
    for (TransportIndexRepository t : reps) {
        if (t.acceptTransportStop(transportStop)) {
            boolean empty = transportStop.getReferencesToRoutes() == null || transportStop.getReferencesToRoutes().length == 0;
            if (!empty) {
                addRoutes(routes, useEnglishNames, t, transportStop, transportStop, 0);
            }
            ArrayList<TransportStop> ls = new ArrayList<>();
            QuadRect ll = MapUtils.calculateLatLonBbox(transportStop.getLocation().getLatitude(), transportStop.getLocation().getLongitude(), SHOW_STOPS_RADIUS_METERS);
            t.searchTransportStops(ll.top, ll.left, ll.bottom, ll.right, -1, ls, null);
            for (TransportStop tstop : ls) {
                if (tstop.getId().longValue() != transportStop.getId().longValue() || empty) {
                    addRoutes(routes, useEnglishNames, t, tstop, transportStop, (int) MapUtils.getDistance(tstop.getLocation(), transportStop.getLocation()));
                }
            }
        }
    }
    Collections.sort(routes, new Comparator<TransportStopRoute>() {

        @Override
        public int compare(TransportStopRoute o1, TransportStopRoute o2) {
            if (o1.distance != o2.distance) {
                return Algorithms.compare(o1.distance, o2.distance);
            }
            int i1 = Algorithms.extractFirstIntegerNumber(o1.desc);
            int i2 = Algorithms.extractFirstIntegerNumber(o2.desc);
            if (i1 != i2) {
                return Algorithms.compare(i1, i2);
            }
            return o1.desc.compareTo(o2.desc);
        }
    });
    return routes;
}
Also used : TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) ArrayList(java.util.ArrayList) TransportIndexRepository(net.osmand.plus.resources.TransportIndexRepository) TransportStop(net.osmand.data.TransportStop) QuadRect(net.osmand.data.QuadRect)

Aggregations

TransportStop (net.osmand.data.TransportStop)22 ArrayList (java.util.ArrayList)8 QuadRect (net.osmand.data.QuadRect)5 Way (net.osmand.osm.edit.Way)5 LinkedHashMap (java.util.LinkedHashMap)4 Paint (android.graphics.Paint)3 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 Node (net.osmand.osm.edit.Node)3 TransportStopRoute (net.osmand.plus.transport.TransportStopRoute)3 TransportIndex (net.osmand.binary.BinaryMapTransportReaderAdapter.TransportIndex)2 RotatedTileBox (net.osmand.data.RotatedTileBox)2 TransportRoute (net.osmand.data.TransportRoute)2 Relation (net.osmand.osm.edit.Relation)2 RelationMember (net.osmand.osm.edit.Relation.RelationMember)2 Rect (rtree.Rect)2 Bitmap (android.graphics.Bitmap)1 Path (android.graphics.Path)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 DisplayMetrics (android.util.DisplayMetrics)1 View (android.view.View)1