Search in sources :

Example 1 with IdTable

use of net.osmand.binary.OsmandOdb.IdTable 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)

Aggregations

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 RouteData (net.osmand.binary.OsmandOdb.RouteData)1 RoutePointToWrite (net.osmand.data.preparation.BinaryMapIndexWriter.RoutePointToWrite)1 Element (rtree.Element)1 LeafElement (rtree.LeafElement)1