Search in sources :

Example 1 with MapPointName

use of net.osmand.osm.MapRoutingTypes.MapPointName in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method addWayToIndex.

private void addWayToIndex(long id, List<Node> nodes, PreparedStatement insertStat, RTree rTree, TIntArrayList outTypes, TLongObjectHashMap<TIntArrayList> pointTypes, TLongObjectHashMap<TIntObjectHashMap<String>> pointNamesRaw, Map<MapRoutingTypes.MapRouteType, String> names) throws SQLException {
    boolean init = false;
    int minX = Integer.MAX_VALUE;
    int maxX = 0;
    int minY = Integer.MAX_VALUE;
    int maxY = 0;
    ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
    ByteArrayOutputStream bpointIds = new ByteArrayOutputStream();
    ByteArrayOutputStream bpointTypes = new ByteArrayOutputStream();
    ByteArrayOutputStream btypes = new ByteArrayOutputStream();
    List<MapPointName> pointNamesEmp = new ArrayList<MapPointName>();
    try {
        for (int j = 0; j < outTypes.size(); j++) {
            Algorithms.writeSmallInt(btypes, outTypes.get(j));
        }
        int pointIndex = 0;
        for (Node n : nodes) {
            if (n != null) {
                // write id
                Algorithms.writeLongInt(bpointIds, n.getId());
                // write point type
                TIntArrayList types = pointTypes.get(n.getId());
                if (types != null) {
                    for (int j = 0; j < types.size(); j++) {
                        Algorithms.writeSmallInt(bpointTypes, types.get(j));
                    }
                }
                TIntObjectHashMap<String> namesP = pointNamesRaw.get(n.getId());
                if (namesP != null) {
                    TIntObjectIterator<String> it = namesP.iterator();
                    while (it.hasNext()) {
                        it.advance();
                        MapPointName obj = new MapPointName(it.key(), pointIndex, it.value());
                        pointNamesEmp.add(obj);
                    }
                }
                Algorithms.writeSmallInt(bpointTypes, 0);
                // write coordinates
                int y = MapUtils.get31TileNumberY(n.getLatitude());
                int x = MapUtils.get31TileNumberX(n.getLongitude());
                minX = Math.min(minX, x);
                maxX = Math.max(maxX, x);
                minY = Math.min(minY, y);
                maxY = Math.max(maxY, y);
                init = true;
                Algorithms.writeInt(bcoordinates, x);
                Algorithms.writeInt(bcoordinates, y);
                pointIndex++;
            }
        }
    } catch (IOException est) {
        throw new IllegalStateException(est);
    }
    if (init) {
        // conn.prepareStatement("insert into route_objects(id, types, pointTypes, pointIds, pointCoordinates, name) values(?, ?, ?, ?, ?, ?, ?)");
        insertStat.setLong(1, id);
        insertStat.setBytes(2, btypes.toByteArray());
        insertStat.setBytes(3, bpointTypes.toByteArray());
        insertStat.setBytes(4, bpointIds.toByteArray());
        insertStat.setBytes(5, bcoordinates.toByteArray());
        insertStat.setString(6, encodeNames(names));
        insertStat.setString(7, encodeListNames(pointNamesEmp));
        addBatch(insertStat, false);
        try {
            rTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
        } catch (RTreeInsertException e1) {
            throw new IllegalArgumentException(e1);
        } catch (IllegalValueException e1) {
            throw new IllegalArgumentException(e1);
        }
    }
}
Also used : Rect(rtree.Rect) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) IllegalValueException(rtree.IllegalValueException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TIntArrayList(gnu.trove.list.array.TIntArrayList) RTreeInsertException(rtree.RTreeInsertException) MapPointName(net.osmand.osm.MapRoutingTypes.MapPointName) LeafElement(rtree.LeafElement)

Example 2 with MapPointName

use of net.osmand.osm.MapRoutingTypes.MapPointName 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

MapPointName (net.osmand.osm.MapRoutingTypes.MapPointName)2 ByteString (com.google.protobuf.ByteString)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 RouteData (net.osmand.binary.OsmandOdb.RouteData)1 MapRouteType (net.osmand.osm.MapRoutingTypes.MapRouteType)1 Node (net.osmand.osm.edit.Node)1 IllegalValueException (rtree.IllegalValueException)1 LeafElement (rtree.LeafElement)1 RTreeInsertException (rtree.RTreeInsertException)1 Rect (rtree.Rect)1