Search in sources :

Example 1 with RouteData

use of net.osmand.binary.OsmandOdb.RouteData in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method writeBinaryMapBlock.

public static void writeBinaryMapBlock(rtree.Node parent, Rect parentBounds, RTree r, BinaryMapIndexWriter writer, RouteWriteContext wc, boolean basemap) throws IOException, RTreeException, SQLException {
    Element[] e = parent.getAllElements();
    RouteDataBlock.Builder dataBlock = null;
    BinaryFileReference ref = wc.treeHeader.get(parent.getNodeIndex());
    wc.wayMapIds.clear();
    wc.wayMapIdsCache.clear();
    wc.pointMapIds.clear();
    for (int i = 0; i < parent.getTotalElements(); i++) {
        if (e[i].getElementType() == rtree.Node.LEAF_NODE) {
            long id = e[i].getPtr();
            // IndexRouteCreator.SELECT_STAT;
            // "SELECT types, pointTypes, pointIds, pointCoordinates, name FROM route_objects WHERE id = ?"
            boolean retrieveObject = wc.retrieveObject(id);
            if (retrieveObject) {
                if (dataBlock == null) {
                    dataBlock = RouteDataBlock.newBuilder();
                    wc.stringTable.clear();
                    wc.wayMapIds.clear();
                    wc.wayMapIdsCache.clear();
                    wc.pointMapIds.clear();
                }
                int cid = wc.registerWayMapId(id);
                TLongArrayList restrictions = wc.highwayRestrictions.get(id);
                if (!basemap && restrictions != null) {
                    for (int li = 0; li < restrictions.size(); li++) {
                        Builder restriction = RestrictionData.newBuilder();
                        restriction.setFrom(cid);
                        int toId = wc.registerWayMapId(restrictions.get(li) >> 3);
                        restriction.setTo(toId);
                        restriction.setType((int) (restrictions.get(li) & 0x7));
                        dataBlock.addRestrictions(restriction.build());
                    }
                }
                RouteData routeData = writer.writeRouteData(cid, parentBounds.getMinX(), parentBounds.getMinY(), wc.wayTypes, wc.points.toArray(new RoutePointToWrite[wc.points.size()]), wc.wayNames, wc.stringTable, wc.pointNames, dataBlock, true, false);
                if (routeData != null) {
                    dataBlock.addDataObjects(routeData);
                }
            } else {
                if (wc.logMapDataWarn != null) {
                    // $NON-NLS-1$
                    wc.logMapDataWarn.error("Something goes wrong with id = " + id);
                } else {
                    System.err.println("Something goes wrong with id = " + id);
                }
            }
        }
    }
    if (dataBlock != null) {
        IdTable.Builder idTable = IdTable.newBuilder();
        long prev = 0;
        for (int i = 0; i < wc.wayMapIds.size(); i++) {
            idTable.addRouteId(wc.wayMapIds.getQuick(i) - prev);
            prev = wc.wayMapIds.getQuick(i);
        }
        // if (WRITE_POINT_ID) {
        // prev = 0;
        // for (int i = 0; i < pointMapIds.size(); i++) {
        // prev = pointMapIds.getQuick(i);
        // }
        // }
        dataBlock.setIdTable(idTable.build());
        writer.writeRouteDataBlock(dataBlock, wc.stringTable, ref);
    }
    for (int i = 0; i < parent.getTotalElements(); i++) {
        if (e[i].getElementType() != rtree.Node.LEAF_NODE) {
            long ptr = e[i].getPtr();
            rtree.Node ns = r.getReadNode(ptr);
            writeBinaryMapBlock(ns, e[i].getRect(), r, writer, wc, basemap);
        }
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) Element(rtree.Element) LeafElement(rtree.LeafElement) Builder(net.osmand.binary.OsmandOdb.RestrictionData.Builder) RouteDataBlock(net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock) IdTable(net.osmand.binary.OsmandOdb.IdTable) RoutePointToWrite(net.osmand.data.preparation.BinaryMapIndexWriter.RoutePointToWrite) RouteData(net.osmand.binary.OsmandOdb.RouteData)

Example 2 with RouteData

use of net.osmand.binary.OsmandOdb.RouteData in project OsmAnd-tools by osmandapp.

the class BinaryMapIndexWriter method writeRouteData.

public RouteData writeRouteData(int diffId, int pleft, int ptop, int[] types, RoutePointToWrite[] points, Map<MapRouteType, String> names, Map<String, Integer> stringTable, List<MapPointName> pointNames, RouteDataBlock.Builder dataBlock, boolean allowCoordinateSimplification, boolean writePointId) throws IOException {
    RouteData.Builder builder = RouteData.newBuilder();
    builder.setRouteId(diffId);
    ROUTE_ID_SIZE += CodedOutputStream.computeInt64Size(RouteData.ROUTEID_FIELD_NUMBER, diffId);
    // types
    mapDataBuf.clear();
    for (int i = 0; i < types.length; i++) {
        writeRawVarint32(mapDataBuf, types[i]);
    }
    builder.setTypes(ByteString.copyFrom(mapDataBuf.toArray()));
    ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RouteData.TYPES_FIELD_NUMBER) + CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
    // coordinates and point types
    int pcalcx = pleft >> ROUTE_SHIFT_COORDINATES;
    int pcalcy = ptop >> ROUTE_SHIFT_COORDINATES;
    mapDataBuf.clear();
    typesDataBuf.clear();
    for (int k = 0; k < points.length; k++) {
        ROUTE_COORDINATES_COUNT++;
        int tx = (points[k].x >> ROUTE_SHIFT_COORDINATES) - pcalcx;
        int ty = (points[k].y >> ROUTE_SHIFT_COORDINATES) - pcalcy;
        writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(tx));
        writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(ty));
        pcalcx = pcalcx + tx;
        pcalcy = pcalcy + ty;
        if (points[k].types.size() > 0) {
            typesAddDataBuf.clear();
            for (int ij = 0; ij < points[k].types.size(); ij++) {
                writeRawVarint32(typesAddDataBuf, points[k].types.get(ij));
            }
            writeRawVarint32(typesDataBuf, k);
            writeRawVarint32(typesDataBuf, typesAddDataBuf.size());
            typesDataBuf.add(typesAddDataBuf.toArray());
        }
    }
    builder.setPoints(ByteString.copyFrom(mapDataBuf.toArray()));
    ROUTE_COORDINATES_SIZE += CodedOutputStream.computeTagSize(RouteData.POINTS_FIELD_NUMBER) + CodedOutputStream.computeRawVarint32Size(mapDataBuf.size()) + mapDataBuf.size();
    builder.setPointTypes(ByteString.copyFrom(typesDataBuf.toArray()));
    ROUTE_TYPES_SIZE += CodedOutputStream.computeTagSize(RouteData.POINTTYPES_FIELD_NUMBER) + CodedOutputStream.computeRawVarint32Size(typesDataBuf.size()) + typesDataBuf.size();
    if (pointNames.size() > 0) {
        mapDataBuf.clear();
        for (MapPointName p : pointNames) {
            writeRawVarint32(mapDataBuf, p.pointIndex);
            writeRawVarint32(mapDataBuf, p.nameTypeTargetId);
            Integer ls = stringTable.get(p.name);
            if (ls == null) {
                ls = stringTable.size();
                stringTable.put(p.name, ls);
            }
            writeRawVarint32(mapDataBuf, ls);
        }
        ROUTE_STRING_DATA_SIZE += mapDataBuf.size();
        builder.setPointNames(ByteString.copyFrom(mapDataBuf.toArray()));
    }
    if (names.size() > 0) {
        mapDataBuf.clear();
        for (Entry<MapRouteType, String> s : names.entrySet()) {
            writeRawVarint32(mapDataBuf, s.getKey().getTargetId());
            Integer ls = stringTable.get(s.getValue());
            if (ls == null) {
                ls = stringTable.size();
                stringTable.put(s.getValue(), ls);
            }
            writeRawVarint32(mapDataBuf, ls);
        }
        ROUTE_STRING_DATA_SIZE += mapDataBuf.size();
        builder.setStringNames(ByteString.copyFrom(mapDataBuf.toArray()));
    }
    return builder.build();
}
Also used : MapPointName(net.osmand.osm.MapRoutingTypes.MapPointName) RouteData(net.osmand.binary.OsmandOdb.RouteData) ByteString(com.google.protobuf.ByteString) MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType)

Aggregations

RouteData (net.osmand.binary.OsmandOdb.RouteData)2 ByteString (com.google.protobuf.ByteString)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 IdTable (net.osmand.binary.OsmandOdb.IdTable)1 RouteDataBlock (net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteDataBlock)1 Builder (net.osmand.binary.OsmandOdb.RestrictionData.Builder)1 RoutePointToWrite (net.osmand.data.preparation.BinaryMapIndexWriter.RoutePointToWrite)1 MapPointName (net.osmand.osm.MapRoutingTypes.MapPointName)1 MapRouteType (net.osmand.osm.MapRoutingTypes.MapRouteType)1 Element (rtree.Element)1 LeafElement (rtree.LeafElement)1