Search in sources :

Example 1 with MapRulType

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

the class IndexVectorMapCreator method decodeNames.

private Map<MapRulType, String> decodeNames(String name, Map<MapRulType, String> tempNames) {
    int i = name.indexOf(SPECIAL_CHAR);
    while (i != -1) {
        int n = name.indexOf(SPECIAL_CHAR, i + 2);
        int ch = (short) name.charAt(i + 1);
        MapRulType rt = renderingTypes.getTypeByInternalId(ch);
        if (n == -1) {
            tempNames.put(rt, name.substring(i + 2));
        } else {
            tempNames.put(rt, name.substring(i + 2, n));
        }
        i = n;
    }
    return tempNames;
}
Also used : MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType)

Example 2 with MapRulType

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

the class IndexVectorMapCreator method readLowLevelCandidates.

public List<LowLevelWayCandidate> readLowLevelCandidates(ResultSet fs, List<LowLevelWayCandidate> l, TIntArrayList temp, TIntArrayList tempAdd, TLongHashSet visitedWays) throws SQLException {
    l.clear();
    while (fs.next()) {
        if (!visitedWays.contains(fs.getLong(1))) {
            parseAndSort(temp, fs.getBytes(5));
            parseAndSort(tempAdd, fs.getBytes(6));
            if (temp.equals(typeUse) && tempAdd.equals(addtypeUse)) {
                LowLevelWayCandidate llwc = new LowLevelWayCandidate();
                llwc.wayId = fs.getLong(1);
                llwc.names = decodeNames(fs.getString(4), new HashMap<MapRulType, String>());
                llwc.nodes = fs.getBytes(3);
                llwc.otherNodeId = fs.getLong(2);
                for (MapRulType mr : namesUse.keySet()) {
                    if (Algorithms.objectEquals(namesUse.get(mr), llwc.names.get(mr))) {
                        llwc.namesCount++;
                    }
                }
                l.add(llwc);
            }
        }
    }
    return l;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType)

Example 3 with MapRulType

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

the class BasemapProcessor method processEntity.

public void processEntity(Entity e) {
    if (e instanceof Way) {
        if ("reverse_coastline".equals(((Way) e).getModifiableTags().get("natural"))) {
            ((Way) e).putTag("natural", "coastline");
            Collections.reverse(((Way) e).getNodes());
            ((Way) e).getNodeIds().reverse();
        }
    }
    long refId = -Math.abs(e.getId());
    for (int level = 0; level < mapZooms.getLevels().size(); level++) {
        boolean mostDetailed = level == 0;
        MapZoomPair zoomPair = mapZooms.getLevel(level);
        int zoomToEncode = mostDetailed ? Math.max(MOST_DETAILED_APPROXIMATION, zoomPair.getMinZoom() + 1) : zoomPair.getMaxZoom();
        if (mostDetailed && zoomPair.getMaxZoom() < 10) {
            throw new IllegalStateException("Zoom pair is not detailed " + zoomPair);
        }
        renderingTypes.encodeEntityWithType(e, zoomToEncode, typeUse, addtypeUse, namesUse, tempNameUse);
        if (typeUse.isEmpty()) {
            continue;
        }
        if (e instanceof Relation) {
            Relation r = (Relation) e;
            Iterator<RelationMember> it = r.getMembers().iterator();
            List<Node> outer = null;
            List<List<Node>> inner = new ArrayList<List<Node>>();
            while (it.hasNext()) {
                RelationMember n = it.next();
                if (n.getRole().equals("outer")) {
                    if (outer != null) {
                        throw new IllegalStateException("2 outer lines for relation = " + e.getId());
                    }
                    outer = ((Way) n.getEntity()).getNodes();
                } else if (n.getRole().equals("inner")) {
                    inner.add(((Way) n.getEntity()).getNodes());
                }
            }
            if (OsmMapUtils.polygonAreaPixels(outer, zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                continue;
            }
            addObject(refId, level, zoomPair, zoomToEncode, outer, inner);
        } else if (e instanceof Way) {
            if (((Way) e).getNodes().size() < 2) {
                continue;
            }
            double dist = OsmMapUtils.getDistance(((Way) e).getFirstNode(), ((Way) e).getLastNode());
            boolean polygon = dist < 100;
            if ("coastline".equals(e.getTag("natural"))) {
                if (polygon && !mostDetailed) {
                    if (OsmMapUtils.polygonAreaPixels(((Way) e).getNodes(), zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                }
                splitContinuousWay(((Way) e).getNodes(), typeUse.toArray(), !addtypeUse.isEmpty() ? addtypeUse.toArray() : null, zoomPair, zoomToEncode, quadTrees[level], refId);
            } else {
                List<Node> ns = ((Way) e).getNodes();
                if (!polygon) {
                    QuadRect qr = ((Way) e).getLatLonBBox();
                    if (qr == null) {
                        continue;
                    }
                    double mult = 1 / MapUtils.getPowZoom(Math.max(31 - (zoomToEncode + 8), 0));
                    int rx = MapUtils.get31TileNumberX(qr.right);
                    int lx = MapUtils.get31TileNumberX(qr.left);
                    int by = MapUtils.get31TileNumberY(qr.bottom);
                    int ty = MapUtils.get31TileNumberY(qr.top);
                    if (mult * (rx - lx) < PIXELS_THRESHOLD_AREA && mult * (by - ty) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                } else {
                    if (OsmMapUtils.polygonAreaPixels(ns, zoomToEncode) < PIXELS_THRESHOLD_AREA) {
                        continue;
                    }
                }
                addObject(refId, level, zoomPair, zoomToEncode, ns, null);
            }
        } else {
            int z = getViewZoom(zoomPair.getMinZoom(), zoomToEncode);
            int tilex = (int) MapUtils.getTileNumberX(z, ((Node) e).getLongitude());
            int tiley = (int) MapUtils.getTileNumberY(z, ((Node) e).getLatitude());
            addRawData(Collections.singletonList((Node) e), null, typeUse.toArray(), !addtypeUse.isEmpty() ? addtypeUse.toArray() : null, zoomPair, quadTrees[level], z, tilex, tiley, namesUse.isEmpty() ? null : new LinkedHashMap<MapRulType, String>(namesUse), refId);
        }
    }
}
Also used : Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) QuadRect(net.osmand.data.QuadRect) Way(net.osmand.osm.edit.Way) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) MapZoomPair(net.osmand.binary.MapZooms.MapZoomPair) Relation(net.osmand.osm.edit.Relation) RelationMember(net.osmand.osm.edit.Relation.RelationMember) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 4 with MapRulType

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

the class TagsTransformer method handleRelationPropogatedTags.

public void handleRelationPropogatedTags(Relation e, MapRenderingTypesEncoder renderingTypes, OsmDbAccessorContext ctx, EntityConvertApplyType at) throws SQLException {
    Map<MapRulType, Map<MapRulType, String>> propogated = renderingTypes.getRelationPropogatedTags((Relation) e, at);
    if (propogated != null && propogated.size() > 0) {
        if (ctx != null) {
            ctx.loadEntityRelation((Relation) e);
        }
        for (RelationMember ids : ((Relation) e).getMembers()) {
            if (!propogatedTags.containsKey(ids.getEntityId())) {
                propogatedTags.put(ids.getEntityId(), new LinkedHashMap<String, String>());
            }
            Map<String, String> map = propogatedTags.get(ids.getEntityId());
            Iterator<Entry<MapRulType, Map<MapRulType, String>>> itMain = propogated.entrySet().iterator();
            while (itMain.hasNext()) {
                Entry<MapRulType, Map<MapRulType, String>> ev = itMain.next();
                Map<MapRulType, String> pr = ev.getValue();
                MapRulType propagateRule = ev.getKey();
                if (propagateRule.isRelationGroup()) {
                    Iterator<Entry<MapRulType, String>> it = pr.entrySet().iterator();
                    int modifier = 1;
                    String s = propagateRule.getTag() + "__" + propagateRule.getValue() + "_";
                    while (map.containsKey(s + modifier)) {
                        modifier++;
                    }
                    map.put(s + modifier, s);
                    while (it.hasNext()) {
                        Entry<MapRulType, String> es = it.next();
                        String key = es.getKey().getTag();
                        map.put(key + "_" + modifier, es.getValue());
                    }
                } else {
                    Iterator<Entry<MapRulType, String>> it = pr.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<MapRulType, String> es = it.next();
                        String key = es.getKey().getTag();
                        if (es.getKey().isText() && map.containsKey(key)) {
                            String res = sortAndAttachUniqueValue(map.get(key), es.getValue());
                            map.put(key, res);
                        } else {
                            map.put(key, es.getValue());
                        }
                    }
                }
            }
        }
    }
}
Also used : MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) Relation(net.osmand.osm.edit.Relation) Entry(java.util.Map.Entry) RelationMember(net.osmand.osm.edit.Relation.RelationMember) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with MapRulType

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

the class IndexVectorMapCreator method writeBinaryMapIndex.

public void writeBinaryMapIndex(BinaryMapIndexWriter writer, String regionName) throws IOException, SQLException {
    closePreparedStatements(mapBinaryStat, mapLowLevelBinaryStat);
    mapConnection.commit();
    try {
        writer.startWriteMapIndex(regionName);
        // write map encoding rules
        writer.writeMapEncodingRules(renderingTypes.getEncodingRuleTypes());
        PreparedStatement selectData = mapConnection.prepareStatement("SELECT area, coordinates, innerPolygons, types, additionalTypes, name FROM binary_map_objects WHERE id = ?");
        // write map levels and map index
        TLongObjectHashMap<BinaryFileReference> treeHeader = new TLongObjectHashMap<BinaryFileReference>();
        for (int i = 0; i < mapZooms.size(); i++) {
            RTree rtree = mapTree[i];
            long rootIndex = rtree.getFileHdr().getRootIndex();
            rtree.Node root = rtree.getReadNode(rootIndex);
            Rect rootBounds = calcBounds(root);
            if (rootBounds != null) {
                writer.startWriteMapLevelIndex(mapZooms.getLevel(i).getMinZoom(), mapZooms.getLevel(i).getMaxZoom(), rootBounds.getMinX(), rootBounds.getMaxX(), rootBounds.getMinY(), rootBounds.getMaxY());
                writeBinaryMapTree(root, rootBounds, rtree, writer, treeHeader);
                writeBinaryMapBlock(root, rootBounds, rtree, writer, selectData, treeHeader, new LinkedHashMap<String, Integer>(), new LinkedHashMap<MapRulType, String>(), mapZooms.getLevel(i));
                writer.endWriteMapLevelIndex();
            }
        }
        selectData.close();
        writer.endWriteMapIndex();
        writer.flush();
    } catch (RTreeException e) {
        throw new IllegalStateException(e);
    }
}
Also used : Rect(rtree.Rect) RTreeException(rtree.RTreeException) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) PreparedStatement(java.sql.PreparedStatement) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) RTree(rtree.RTree)

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