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;
}
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;
}
}
}
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"));
}
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"));
}
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());
}
Aggregations