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