Search in sources :

Example 1 with MapRouteType

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

the class IndexRouteCreator method attachWays.

private void attachWays(GeneralizedWay gw, boolean first) {
    GeneralizedCluster cluster = null;
    while (true) {
        int ind = first ? 0 : gw.size() - 1;
        cluster = getCluster(gw, ind, cluster);
        GeneralizedWay prev = selectBestWay(cluster, gw, ind);
        if (prev == null) {
            break;
        }
        for (int i = 0; i < prev.size(); i++) {
            cluster = getCluster(prev, i, cluster);
            cluster.replaceWayFromLocation(prev, i, gw);
        }
        mergeAddTypes(prev, gw);
        for (MapRouteType rt : new ArrayList<MapRouteType>(gw.names.keySet())) {
            mergeName(rt, prev, gw);
        }
        for (MapRouteType rt : new ArrayList<MapRouteType>(prev.names.keySet())) {
            if (!gw.names.containsKey(rt)) {
                mergeName(rt, prev, gw);
            }
        }
        TIntArrayList ax = first ? prev.px : gw.px;
        TIntArrayList ay = first ? prev.py : gw.py;
        TIntArrayList bx = !first ? prev.px : gw.px;
        TIntArrayList by = !first ? prev.py : gw.py;
        if (first) {
            if (gw.getLocation(0) == prev.getLocation(0)) {
                ax.reverse();
                ay.reverse();
            }
        } else {
            if (gw.getLocation(ind) == prev.getLocation(prev.size() - 1)) {
                bx.reverse();
                by.reverse();
            }
        }
        bx.removeAt(0);
        by.removeAt(0);
        ax.addAll(bx);
        ay.addAll(by);
        gw.px = ax;
        gw.py = ay;
    }
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList) MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType)

Example 2 with MapRouteType

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

the class BinaryMapIndexWriter method writeRouteEncodingRules.

public void writeRouteEncodingRules(List<MapRouteType> types) throws IOException {
    checkPeekState(ROUTE_INDEX_INIT);
    ArrayList<MapRouteType> out = new ArrayList<MapRouteType>(types);
    // 2. sort by frequency and assign ids
    Collections.sort(out, new Comparator<MapRouteType>() {

        @Override
        public int compare(MapRouteType o1, MapRouteType o2) {
            return o2.getFreq() - o1.getFreq();
        }
    });
    for (int i = 0; i < out.size(); i++) {
        RouteEncodingRule.Builder builder = OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule.newBuilder();
        MapRouteType rule = out.get(i);
        rule.setTargetId(i + 1);
        builder.setTag(rule.getTag());
        if (rule.getValue() != null) {
            builder.setValue(rule.getValue());
        } else {
            builder.setValue("");
        }
        RouteEncodingRule rulet = builder.build();
        codedOutStream.writeMessage(OsmandOdb.OsmAndRoutingIndex.RULES_FIELD_NUMBER, rulet);
    }
}
Also used : TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TByteArrayList(gnu.trove.list.array.TByteArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RouteEncodingRule(net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule) MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType)

Example 3 with MapRouteType

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

the class IndexRouteCreator method processingLowLevelWays.

public void processingLowLevelWays(IProgress progress) {
    if (!generateLowLevel) {
        return;
    }
    pointTypes.clear();
    pointNames.clear();
    Collection<GeneralizedCluster> clusters = new ArrayList<IndexRouteCreator.GeneralizedCluster>(generalClusters.valueCollection());
    // 1. roundabouts
    processRoundabouts(clusters);
    // 2. way combination based
    for (GeneralizedCluster cluster : clusters) {
        ArrayList<GeneralizedWay> copy = new ArrayList<GeneralizedWay>(cluster.ways);
        for (GeneralizedWay gw : copy) {
            // already deleted
            if (!cluster.ways.contains(gw)) {
                continue;
            }
            attachWays(gw, true);
            attachWays(gw, false);
        }
    }
    // 3. Douglas peuker simplifications
    douglasPeukerSimplificationStep(clusters);
    // 5. write to db
    TLongHashSet ids = new TLongHashSet();
    for (GeneralizedCluster cluster : clusters) {
        for (GeneralizedWay gw : cluster.ways) {
            if (ids.contains(gw.id)) {
                continue;
            }
            ids.add(gw.id);
            names.clear();
            Iterator<Entry<MapRouteType, String>> its = gw.names.entrySet().iterator();
            while (its.hasNext()) {
                Entry<MapRouteType, String> e = its.next();
                if (e.getValue() != null && !e.getValue().equals(CONFLICT_NAME)) {
                    names.put(e.getKey(), e.getValue());
                }
            }
            ArrayList<Node> nodes = new ArrayList<Node>();
            if (gw.size() == 0) {
                System.err.println(gw.id + " empty ? ");
                continue;
            }
            long prev = 0;
            for (int i = 0; i < gw.size(); i++) {
                long loc = gw.getLocation(i);
                if (loc != prev) {
                    Node c = convertBaseToNode(loc);
                    prev = loc;
                    nodes.add(c);
                }
            }
            outTypes.clear();
            outTypes.add(gw.mainType);
            outTypes.addAll(gw.addtypes);
            try {
                addWayToIndex(gw.id, nodes, basemapRouteInsertStat, baserouteTree, outTypes, pointTypes, pointNames, names);
            } catch (SQLException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType) Entry(java.util.Map.Entry) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 4 with MapRouteType

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

the class IndexRouteCreator method getBaseOrderForType.

private int getBaseOrderForType(int intType) {
    if (intType == -1) {
        return Integer.MAX_VALUE;
    }
    MapRouteType rt = routeTypes.getTypeByInternalId(intType);
    int i = 0;
    for (; i < baseOrderValues.length; i++) {
        if (rt.getValue().startsWith(baseOrderValues[i])) {
            return i;
        }
    }
    return i;
}
Also used : MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType)

Example 5 with MapRouteType

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

MapRouteType (net.osmand.osm.MapRoutingTypes.MapRouteType)5 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)3 ArrayList (java.util.ArrayList)3 ByteString (com.google.protobuf.ByteString)1 TByteArrayList (gnu.trove.list.array.TByteArrayList)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 SQLException (java.sql.SQLException)1 Entry (java.util.Map.Entry)1 RouteEncodingRule (net.osmand.binary.OsmandOdb.OsmAndRoutingIndex.RouteEncodingRule)1 RouteData (net.osmand.binary.OsmandOdb.RouteData)1 MapPointName (net.osmand.osm.MapRoutingTypes.MapPointName)1 Node (net.osmand.osm.edit.Node)1