Search in sources :

Example 6 with MapRulType

use of net.osmand.osm.MapRenderingTypes.MapRulType in project OsmAnd-tools by osmandapp.

the class IndexVectorMapCreator method processingLowLevelWays.

public void processingLowLevelWays(IProgress progress) throws SQLException {
    mapLowLevelBinaryStat.executeBatch();
    mapLowLevelBinaryStat.close();
    pStatements.remove(mapLowLevelBinaryStat);
    mapLowLevelBinaryStat = null;
    mapConnection.commit();
    PreparedStatement startStat = mapConnection.prepareStatement("SELECT id, end_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE start_node = ? AND level = ?");
    PreparedStatement endStat = mapConnection.prepareStatement("SELECT id, start_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE end_node = ? AND level = ?");
    Statement selectStatement = mapConnection.createStatement();
    ResultSet rs = selectStatement.executeQuery("SELECT id, start_node, end_node, nodes, name, type, addType, level FROM low_level_map_objects");
    TLongHashSet visitedWays = new TLongHashSet();
    ArrayList<Float> list = new ArrayList<Float>(100);
    TIntArrayList temp = new TIntArrayList();
    TIntArrayList tempAdd = new TIntArrayList();
    while (rs.next()) {
        if (lowLevelWays != -1) {
            progress.progress(1);
        }
        long id = rs.getLong(1);
        if (visitedWays.contains(id)) {
            continue;
        }
        visitedWays.add(id);
        int level = rs.getInt(8);
        int zoom = mapZooms.getLevel(level).getMaxZoom();
        int minZoom = mapZooms.getLevel(level).getMinZoom();
        long startNode = rs.getLong(2);
        long endNode = rs.getLong(3);
        namesUse.clear();
        decodeNames(rs.getString(5), namesUse);
        parseAndSort(typeUse, rs.getBytes(6));
        parseAndSort(addtypeUse, rs.getBytes(7));
        loadNodes(rs.getBytes(4), list);
        ArrayList<Float> wayNodes = new ArrayList<Float>(list);
        // combine startPoint with EndPoint
        List<LowLevelWayCandidate> candidates = new ArrayList<LowLevelWayCandidate>();
        Comparator<LowLevelWayCandidate> cmpCandidates = new Comparator<LowLevelWayCandidate>() {

            @Override
            public int compare(LowLevelWayCandidate o1, LowLevelWayCandidate o2) {
                return -Integer.compare(o1.namesCount, o2.namesCount);
            }
        };
        boolean combined = true;
        if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
            // disable combine
            combined = false;
        }
        while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
            combined = false;
            endStat.setLong(1, startNode);
            endStat.setShort(2, (short) level);
            ResultSet fs = endStat.executeQuery();
            readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
            fs.close();
            LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
            if (cand != null) {
                combined = true;
                startNode = cand.otherNodeId;
                visitedWays.add(cand.wayId);
                loadNodes(cand.nodes, list);
                ArrayList<Float> li = new ArrayList<Float>(list);
                // remove first lat/lon point
                wayNodes.remove(0);
                wayNodes.remove(0);
                li.addAll(wayNodes);
                wayNodes = li;
                for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
                    if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
                        namesUse.remove(rt);
                    }
                }
            }
        }
        // combined end point
        combined = true;
        if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
            // disable combine
            combined = false;
        }
        while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
            combined = false;
            startStat.setLong(1, endNode);
            startStat.setShort(2, (short) level);
            ResultSet fs = startStat.executeQuery();
            readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
            fs.close();
            LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
            if (cand != null) {
                combined = true;
                endNode = cand.otherNodeId;
                visitedWays.add(cand.wayId);
                loadNodes(cand.nodes, list);
                for (int i = 2; i < list.size(); i++) {
                    wayNodes.add(list.get(i));
                }
                for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
                    if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
                        namesUse.remove(rt);
                    }
                }
            }
        }
        List<Node> wNodes = new ArrayList<Node>();
        int wNsize = wayNodes.size();
        for (int i = 0; i < wNsize; i += 2) {
            wNodes.add(new Node(wayNodes.get(i), wayNodes.get(i + 1), i == 0 ? startNode : endNode));
        }
        boolean skip = false;
        boolean cycle = startNode == endNode;
        if (cycle) {
            skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 3, 4);
        } else {
            // coastline
            if (!typeUse.contains(renderingTypes.getCoastlineRuleType().getInternalId())) {
                skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 2, 8);
            }
        }
        if (!skip) {
            List<Node> res = new ArrayList<Node>();
            OsmMapUtils.simplifyDouglasPeucker(wNodes, zoom - 1 + 8 + zoomWaySmoothness, 3, res, false);
            if (res.size() > 0) {
                insertBinaryMapRenderObjectIndex(mapTree[level], res, null, namesUse, id, false, typeUse, addtypeUse, false);
            }
        }
    // end cycle
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TIntArrayList(gnu.trove.list.array.TIntArrayList) Comparator(java.util.Comparator) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) TLongHashSet(gnu.trove.set.hash.TLongHashSet) ResultSet(java.sql.ResultSet)

Example 7 with MapRulType

use of net.osmand.osm.MapRenderingTypes.MapRulType in project OsmAnd-tools by osmandapp.

the class BinaryMapIndexWriter method writeMapEncodingRules.

public void writeMapEncodingRules(Map<String, MapRulType> types) throws IOException {
    checkPeekState(MAP_INDEX_INIT);
    ArrayList<MapRulType> out = new ArrayList<MapRulType>();
    int highestTargetId = types.size();
    // 1. prepare map rule type to write
    for (MapRulType t : types.values()) {
        if (t.getFreq() == 0 || !t.isMap()) {
            t.setTargetId(highestTargetId++);
        } else {
            out.add(t);
        }
    }
    // 2. sort by frequency and assign ids
    Collections.sort(out, new Comparator<MapRulType>() {

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

Aggregations

MapRulType (net.osmand.osm.MapRenderingTypes.MapRulType)7 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 ArrayList (java.util.ArrayList)3 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)2 PreparedStatement (java.sql.PreparedStatement)2 LinkedHashMap (java.util.LinkedHashMap)2 Node (net.osmand.osm.edit.Node)2 Relation (net.osmand.osm.edit.Relation)2 RelationMember (net.osmand.osm.edit.Relation.RelationMember)2 TByteArrayList (gnu.trove.list.array.TByteArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1