Search in sources :

Example 1 with Rule

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

the class RuleSet method setFinalizeRule.

public void setFinalizeRule(Rule finalizeRule) {
    if (rules == null) {
        // that we have rules to which the finalize rules can be applied
        throw new IllegalStateException("First call prepare() before setting the finalize rules");
    }
    for (Rule rule : rules) rule.setFinalizeRule(finalizeRule);
    compiled = false;
    this.finalizeRule = finalizeRule;
}
Also used : Rule(uk.me.parabola.mkgmap.reader.osm.Rule)

Example 2 with Rule

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

the class StyledConverter method convertWay.

public void convertWay(final Way way) {
    if (way.getPoints().size() < 2 || way.getTagCount() == 0) {
        // no tags or no points => nothing to convert
        removeRestrictionsWithWay(Level.WARNING, way, "is ignored");
        return;
    }
    preConvertRules(way);
    String styleFilterTag = way.getTag(styleFilterTagKey);
    Rule rules;
    if ("polyline".equals(styleFilterTag))
        rules = lineRules;
    else if ("polygon".equals(styleFilterTag))
        rules = polygonRules;
    else {
        if (way.isClosedInOSM() && !way.isComplete() && !way.hasIdenticalEndPoints())
            way.getPoints().add(way.getPoints().get(0));
        if (way.hasIdenticalEndPoints() == false || way.getPoints().size() < 4)
            rules = lineRules;
        else
            rules = wayRules;
    }
    Way cycleWay = null;
    String cycleWayTag = way.getTag(makeCycleWayTagKey);
    if ("yes".equals(cycleWayTag)) {
        way.deleteTag("mkgmap:make-cycle-way");
        cycleWay = makeCycleWay(way);
        // make sure that bicycles are using the added bicycle way
        way.addTag("bicycle", "no");
    }
    wayTypeResult.setWay(way);
    lineCacheId = rules.resolveType(lineCacheId, way, wayTypeResult);
    if (wayTypeResult.isMatched() == false) {
        // no match found but we have to keep it for house number processing
        housenumberGenerator.addWay(way);
    }
    if (cycleWay != null) {
        wayTypeResult.setWay(cycleWay);
        lineCacheId = rules.resolveType(lineCacheId, cycleWay, wayTypeResult);
        if (wayTypeResult.isMatched() == false) {
            // no match found but we have to keep it for house number processing
            housenumberGenerator.addWay(cycleWay);
        }
    }
    if (lastRoadId != way.getId()) {
        // this way was not added to the roads list
        removeRestrictionsWithWay(Level.WARNING, way, "is not routable");
    } else {
        // which have to be skipped by WrongAngleFixer
        for (int i = lines.size() - 1; i >= 0; --i) {
            ConvertedWay cw = lines.get(i);
            if (cw.getWay().getId() == way.getId()) {
                cw.setOverlay(true);
                int lineType = cw.getGType().getType();
                if (GType.isSpecialRoutableLineType(lineType) && cw.getGType().getMinLevel() == 0) {
                    if (!routingWarningWasPrinted.get(lineType)) {
                        log.error("routable type", GType.formatType(cw.getGType().getType()), "is used with a non-routable way which was also added as a routable way. This leads to routing errors.", "Try --check-styles to check the style.");
                        routingWarningWasPrinted.set(lineType);
                    }
                }
            } else
                break;
        }
    }
}
Also used : Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Way(uk.me.parabola.mkgmap.reader.osm.Way) MapPoint(uk.me.parabola.mkgmap.general.MapPoint) MapExitPoint(uk.me.parabola.mkgmap.general.MapExitPoint)

Example 3 with Rule

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

the class ActionReaderTest method testApplyAction.

/**
 * The apply action works on the members of relations.
 */
@Test
public void testApplyAction() {
    List<Action> actions = readActionsFromString("{apply {" + "add route=bike;" + "set foo=bar; }" + "}\n");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    assertNull("Tag not set on relation", rel.getTag("route"));
    // Will be set on all members as there is no role filter.
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    Element el2 = elements.get(1).getValue();
    assertEquals("route tag added to second", "bike", el2.getTag("route"));
    assertEquals("foo tag set to second", "bar", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 4 with Rule

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

the class ActionReaderTest method testApplyWithRole.

/**
 * You can have a role filter, so that the actions are only applied
 * to members with the given role.
 */
@Test
public void testApplyWithRole() {
    List<Action> actions = readActionsFromString("{apply role=bar {" + "add route=bike;" + "set foo=bar; }}");
    Relation rel = makeRelation();
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(rel, TypeResult.NULL_RESULT);
    List<Map.Entry<String, Element>> elements = rel.getElements();
    Element el1 = elements.get(0).getValue();
    assertEquals("route tag added to first", "bike", el1.getTag("route"));
    assertEquals("foo tag set to first", "bar", el1.getTag("foo"));
    // Wrong role, so not applied.
    Element el2 = elements.get(1).getValue();
    assertNull("route tag not added to second element (role=foo)", el2.getTag("route"));
    assertNull("foo tag not set in second element (role=foo)", el2.getTag("foo"));
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Relation(uk.me.parabola.mkgmap.reader.osm.Relation) GeneralRelation(uk.me.parabola.mkgmap.reader.osm.GeneralRelation) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Example 5 with Rule

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

the class ActionReaderTest method testName.

/**
 * The name action set the element-name (not the 'name' tag).
 * The first value to set it counts, later matches are ignored.
 */
@Test
public void testName() {
    List<Action> actions = readActionsFromString("{name '${name} (${ref})' |" + "  '${ref}' | '${name}' ; }");
    Element el = makeElement();
    el.addTag("name", "Main St");
    Rule rule = new ActionRule(null, actions);
    rule.resolveType(el, TypeResult.NULL_RESULT);
    assertEquals("just name", "Main St", el.getName());
}
Also used : Action(uk.me.parabola.mkgmap.osmstyle.actions.Action) Element(uk.me.parabola.mkgmap.reader.osm.Element) Rule(uk.me.parabola.mkgmap.reader.osm.Rule) Test(org.junit.Test)

Aggregations

Rule (uk.me.parabola.mkgmap.reader.osm.Rule)12 Element (uk.me.parabola.mkgmap.reader.osm.Element)8 Test (org.junit.Test)7 Action (uk.me.parabola.mkgmap.osmstyle.actions.Action)7 GeneralRelation (uk.me.parabola.mkgmap.reader.osm.GeneralRelation)3 Relation (uk.me.parabola.mkgmap.reader.osm.Relation)3 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 MapExitPoint (uk.me.parabola.mkgmap.general.MapExitPoint)1 MapPoint (uk.me.parabola.mkgmap.general.MapPoint)1 AbstractBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractBinaryOp)1 AbstractOp (uk.me.parabola.mkgmap.osmstyle.eval.AbstractOp)1 LinkedBinaryOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedBinaryOp)1 LinkedOp (uk.me.parabola.mkgmap.osmstyle.eval.LinkedOp)1 Op (uk.me.parabola.mkgmap.osmstyle.eval.Op)1 WatchableTypeResult (uk.me.parabola.mkgmap.reader.osm.WatchableTypeResult)1 Way (uk.me.parabola.mkgmap.reader.osm.Way)1