Search in sources :

Example 71 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class RuleFileReaderTest method testWildcard2.

/**
 * You can now have a wild card at the top level, here we have & between
 * two of them.
 */
@Test
public void testWildcard2() {
    RuleSet rs = makeRuleSet("highway=* & z=* {set a=square} [0x1]\n");
    assertNotNull("rule found", rs);
    Element el = new Way(1);
    el.addTag("highway", "secondary");
    GType type = getFirstType(rs, el);
    assertNull("type not found with no z tag", type);
    // now add z
    el.addTag("z", "1");
    type = getFirstType(rs, el);
    assertNotNull("found match", type);
    assertEquals("correct type", 1, type.getType());
    assertEquals("tag set", "square", el.getTag("a"));
}
Also used : TestUtils.makeRuleSet(func.lib.TestUtils.makeRuleSet) GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Test(org.junit.Test)

Example 72 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class RuleSetTest method resolveList.

private List<GType> resolveList(RuleSet rs, Way el) {
    final List<GType> list = new ArrayList<GType>();
    rs.resolveType(el, new TypeResult() {

        public void add(Element el, GType type) {
            list.add(type);
        }
    });
    return list;
}
Also used : GType(uk.me.parabola.mkgmap.reader.osm.GType) Element(uk.me.parabola.mkgmap.reader.osm.Element) ArrayList(java.util.ArrayList) TypeResult(uk.me.parabola.mkgmap.reader.osm.TypeResult)

Example 73 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class StyledConverter method end.

public void end() {
    pointMap.clear();
    style.reportStats();
    driveOnLeft = calcDrivingSide();
    setHighwayCounts();
    findUnconnectedRoads();
    rotateClosedWaysToFirstNode();
    filterCoordPOI();
    WrongAngleFixer wrongAngleFixer = new WrongAngleFixer(bbox);
    wrongAngleFixer.optimizeWays(roads, lines, modifiedRoads, deletedRoads, restrictions);
    // make sure that copies of modified roads have equal points
    for (ConvertedWay line : lines) {
        if (!line.isValid())
            continue;
        Way way = line.getWay();
        if (deletedRoads.contains(way.getId())) {
            line.getPoints().clear();
            continue;
        }
        if (!line.isOverlay())
            continue;
        ConvertedWay modWay = modifiedRoads.get(way.getId());
        if (modWay != null) {
            List<Coord> points = line.getPoints();
            points.clear();
            points.addAll(modWay.getPoints());
            if (modWay.isReversed() != line.isReversed())
                Collections.reverse(points);
        }
    }
    for (Long wayId : deletedRoads) {
        if (wayRelMap.containsKey(wayId)) {
            // may happen e.g. when very short way is leading to nowhere
            log.warn("Way that is used in valid restriction relation was removed, id:", wayId);
        }
    }
    deletedRoads = null;
    modifiedRoads = null;
    mergeRoads();
    resetHighwayCounts();
    setHighwayCounts();
    for (ConvertedWay cw : lines) {
        if (cw.isValid())
            addLine(cw.getWay(), cw.getGType());
    }
    lines = null;
    if (roadLog.isInfoEnabled()) {
        roadLog.info("Flags: oneway,no-emergency, no-delivery, no-throughroute, no-truck, no-bike, no-foot, carpool, no-taxi, no-bus, no-car");
        roadLog.info(String.format("%19s %4s %11s %6s %6s %6s %s", "Road-OSM-Id", "Type", "Flags", "Class", "Speed", "Points", "Labels"));
    }
    // add the roads after the other lines
    for (ConvertedWay cw : roads) {
        if (cw.isValid())
            addRoad(cw);
    }
    housenumberGenerator.generate(lineAdder, nextNodeId);
    housenumberGenerator = null;
    if (routable)
        createRouteRestrictionsFromPOI();
    poiRestrictions = null;
    if (routable) {
        for (RestrictionRelation rr : restrictions) {
            rr.addRestriction(collector, nodeIdMap);
        }
    }
    roads = null;
    if (routable) {
        for (Relation relation : throughRouteRelations) {
            Node node = null;
            Way w1 = null;
            Way w2 = null;
            for (Map.Entry<String, Element> member : relation.getElements()) {
                if (member.getValue() instanceof Node) {
                    if (node == null)
                        node = (Node) member.getValue();
                    else
                        log.warn("Through route relation", relation.toBrowseURL(), "has more than 1 node");
                } else if (member.getValue() instanceof Way) {
                    Way w = (Way) member.getValue();
                    if (w1 == null)
                        w1 = w;
                    else if (w2 == null)
                        w2 = w;
                    else
                        log.warn("Through route relation", relation.toBrowseURL(), "has more than 2 ways");
                }
            }
            CoordNode coordNode = null;
            if (node == null)
                log.warn("Through route relation", relation.toBrowseURL(), "is missing the junction node");
            else {
                Coord junctionPoint = node.getLocation();
                if (bbox != null && !bbox.contains(junctionPoint)) {
                    // junction is outside of the tile - ignore it
                    continue;
                }
                coordNode = nodeIdMap.get(junctionPoint);
                if (coordNode == null)
                    log.warn("Through route relation", relation.toBrowseURL(), "junction node at", junctionPoint.toOSMURL(), "is not a routing node");
            }
            if (w1 == null || w2 == null)
                log.warn("Through route relation", relation.toBrowseURL(), "should reference 2 ways that meet at the junction node");
            if (coordNode != null && w1 != null && w2 != null)
                collector.addThroughRoute(coordNode.getId(), w1.getId(), w2.getId());
        }
    }
    // return memory to GC
    nodeIdMap = null;
    throughRouteRelations.clear();
    restrictions.clear();
}
Also used : Node(uk.me.parabola.mkgmap.reader.osm.Node) CoordNode(uk.me.parabola.imgfmt.app.CoordNode) MapElement(uk.me.parabola.mkgmap.general.MapElement) Element(uk.me.parabola.mkgmap.reader.osm.Element) Way(uk.me.parabola.mkgmap.reader.osm.Way) Coord(uk.me.parabola.imgfmt.app.Coord) RestrictionRelation(uk.me.parabola.mkgmap.reader.osm.RestrictionRelation) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) RestrictionRelation(uk.me.parabola.mkgmap.reader.osm.RestrictionRelation) CoordNode(uk.me.parabola.imgfmt.app.CoordNode) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultiHashMap(uk.me.parabola.util.MultiHashMap)

Example 74 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionRule method resolveType.

public int resolveType(int cacheId, Element el, TypeResult result) {
    Element element = el;
    if (expression != null) {
        numEval++;
        if (!expression.eval(cacheId, element))
            return cacheId;
        numTrue++;
        // There is another reason we need to copy: since there will be
        if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
            element = element.copy();
        }
    }
    // an action will be performed, so we may have to invalidate the cache
    boolean invalidate_cache = false;
    for (Action a : actions) {
        if (a.perform(element)) {
            invalidate_cache = true;
        }
    }
    if (invalidate_cache)
        cacheId++;
    if (type != null && finalizeRule != null) {
        if (el == element && type.isContinueSearch())
            // if there is a continue statement changes performed in
            // the finalize block must not be persistent
            element = element.copy();
        // there is a type so first execute the finalize rules
        if (type.getDefaultName() != null)
            element.addTag("mkgmap:default_name", type.getDefaultName());
        cacheId = finalizeRule.resolveType(cacheId, element, finalizeTypeResult);
    }
    result.add(element, type);
    return cacheId;
}
Also used : Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element)

Example 75 with Element

use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.

the class ActionRule method resolveType.

public void resolveType(Element el, TypeResult result) {
    Element element = el;
    if (expression != null) {
        numEval++;
        if (!expression.eval(element))
            return;
        numTrue++;
        // There is another reason we need to copy: since there will be
        if (type != null && !type.isPropogateActions() && !(element instanceof Relation)) {
            element = element.copy();
        }
    }
    for (Action a : actions) a.perform(element);
    if (type != null && finalizeRule != null) {
        if (el == element && type.isContinueSearch())
            // if there is a continue statement changes performed in
            // the finalize block must not be persistent
            element = element.copy();
        // there is a type so first execute the finalize rules
        if (type.getDefaultName() != null)
            element.addTag("mkgmap:default_name", type.getDefaultName());
        finalizeRule.resolveType(element, finalizeTypeResult);
    }
    result.add(element, type);
}
Also used : Relation(uk.me.parabola.mkgmap.reader.osm.Relation) Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element)

Aggregations

Element (uk.me.parabola.mkgmap.reader.osm.Element)94 Test (org.junit.Test)75 Way (uk.me.parabola.mkgmap.reader.osm.Way)48 GType (uk.me.parabola.mkgmap.reader.osm.GType)25 TestUtils.makeRuleSet (func.lib.TestUtils.makeRuleSet)23 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)15 Rule (uk.me.parabola.mkgmap.reader.osm.Rule)8 ArrayList (java.util.ArrayList)7 Node (uk.me.parabola.mkgmap.reader.osm.Node)7 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)7 Coord (uk.me.parabola.imgfmt.app.Coord)5 StringStyleFileLoader (func.lib.StringStyleFileLoader)4 Map (java.util.Map)4 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)4 TypeResult (uk.me.parabola.mkgmap.reader.osm.TypeResult)4 HashMap (java.util.HashMap)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Area (uk.me.parabola.imgfmt.app.Area)2