use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.
the class StyledConverter method createRouteRestrictionsFromPOI.
/**
* If POI changes access restrictions (e.g. bollards), create corresponding
* route restrictions so that only allowed vehicles/pedestrians are routed
* through this point.
*/
private void createRouteRestrictionsFromPOI() {
Iterator<Map.Entry<Node, List<Way>>> iter = poiRestrictions.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Node, List<Way>> entry = iter.next();
Node node = entry.getKey();
Coord p = node.getLocation();
// list of ways that are connected to the poi
List<Way> wayList = entry.getValue();
byte exceptMask = AccessTagsAndBits.evalAccessTags(node);
Map<Integer, CoordNode> otherNodeIds = new LinkedHashMap<>();
CoordNode viaNode = null;
boolean viaIsUnique = true;
for (Way way : wayList) {
CoordNode lastNode = null;
for (Coord co : way.getPoints()) {
// not 100% fail safe: points may have been replaced before
if (co instanceof CoordNode == false)
continue;
CoordNode cn = (CoordNode) co;
if (p.highPrecEquals(cn)) {
if (viaNode == null)
viaNode = cn;
else if (viaNode != cn) {
log.error("Found multiple points with equal coords as CoordPOI at " + p.toOSMURL());
// if we ever get here we can add code to identify the exact node
viaIsUnique = false;
}
if (lastNode != null)
otherNodeIds.put(lastNode.getId(), lastNode);
} else {
if (p.highPrecEquals(lastNode))
otherNodeIds.put(cn.getId(), cn);
}
lastNode = cn;
}
}
if (viaNode == null) {
log.error("Did not find CoordPOI node at " + p.toOSMURL() + " in ways " + wayList);
continue;
}
if (viaIsUnique == false) {
log.error("Found multiple points with equal coords as CoordPOI at " + p.toOSMURL());
continue;
}
if (otherNodeIds.size() < 2) {
log.info("Access restriction in POI node " + node.toBrowseURL() + " was ignored, has no effect on any connected way");
continue;
}
GeneralRouteRestriction rr = new GeneralRouteRestriction("no_through", exceptMask, "CoordPOI at " + p.toOSMURL());
rr.setViaNodes(Arrays.asList(viaNode));
int added = collector.addRestriction(rr);
if (added == 0) {
log.info("Access restriction in POI node " + node.toBrowseURL() + " was ignored, has no effect on any connected way");
} else {
log.info("Access restriction in POI node", node.toBrowseURL(), "was translated to", added, "route restriction(s)");
}
if (wayList.size() > 1 && added > 2) {
log.warn("Access restriction in POI node", node.toBrowseURL(), "affects routing on multiple ways");
}
}
}
use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.
the class StyledConverterTest method makeConverter.
private StyledConverter makeConverter(String name) throws FileNotFoundException {
Style style = new StyleImpl(LOC, name);
MapCollector coll = new MapCollector() {
public void addToBounds(Coord p) {
}
// could save points in the same way as lines to test them
public void addPoint(MapPoint point) {
}
public void addLine(MapLine line) {
// Save line so that it can be examined in the tests.
assertNotNull("points are not null", line.getPoints());
lines.add(line);
}
public void addShape(MapShape shape) {
}
public void addRoad(MapRoad road) {
lines.add(road);
}
public int addRestriction(GeneralRouteRestriction grr) {
return 0;
}
public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) {
}
};
return new StyledConverter(style, coll, new EnhancedProperties());
}
use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.
the class RestrictionHelper method processAndAddRestrictions.
public void processAndAddRestrictions(RoadHelper roadHelper, MapDetails mapper) {
Map<Long, CoordNode> allNodes = roadHelper.getNodeCoords();
for (PolishTurnRestriction tr : allRestrictions) {
GeneralRouteRestriction grr = new GeneralRouteRestriction("not", tr.getExceptMask(), Long.toString(tr.getNodId()));
grr.setFromNode(allNodes.get(tr.getFromNodId()));
grr.setFromWayId(tr.getRoadIdA());
grr.setToNode(allNodes.get(tr.getToNodId()));
if (tr.getViaNodId() != 0) {
grr.setViaNodes(Arrays.asList(allNodes.get(tr.getNodId()), allNodes.get(tr.getViaNodId())));
grr.setViaWayIds(Arrays.asList(tr.getRoadIdB()));
grr.setToWayId(tr.getRoadIdC());
} else {
grr.setViaNodes(Arrays.asList(allNodes.get(tr.getNodId())));
grr.setToWayId(tr.getRoadIdB());
}
// restriction should be part of the map
mapper.addRestriction(grr);
}
}
use of uk.me.parabola.imgfmt.app.net.GeneralRouteRestriction in project mkgmap by openstreetmap.
the class RestrictionRelation method addRestriction.
public void addRestriction(MapCollector collector, IdentityHashMap<Coord, CoordNode> nodeIdMap) {
if (!valid)
return;
List<CoordNode> viaNodes = new ArrayList<>();
for (Coord v : viaPoints) {
CoordNode vn = nodeIdMap.get(v);
if (vn == null) {
log.error(messagePrefix, "via node is not a routing node");
return;
}
viaNodes.add(vn);
}
if (viaNodes.size() > 6) {
log.warn(messagePrefix, "has more than 6 via nodes, this is not supported");
return;
}
if (restriction == null) {
log.error("internal error: can't add valid restriction relation", this.getId(), "type", restriction);
return;
}
int addedRestrictions = 0;
GeneralRouteRestriction grr;
if (restriction.startsWith("no_")) {
for (long fromWayId : fromWayIds) {
for (long toWayId : toWayIds) {
grr = new GeneralRouteRestriction("not", exceptMask, messagePrefix);
grr.setFromWayId(fromWayId);
grr.setToWayId(toWayId);
grr.setViaNodes(viaNodes);
grr.setViaWayIds(viaWayIds);
grr.setDirIndicator(dirIndicator);
addedRestrictions += collector.addRestriction(grr);
}
}
if (log.isInfoEnabled())
log.info(messagePrefix, restriction, "translated to", addedRestrictions, "img file restrictions");
} else if (restriction.startsWith("only_")) {
grr = new GeneralRouteRestriction("only", exceptMask, messagePrefix);
grr.setFromWayId(fromWayIds.get(0));
grr.setToWayId(toWayIds.get(0));
grr.setViaNodes(viaNodes);
grr.setViaWayIds(viaWayIds);
grr.setDirIndicator(dirIndicator);
int numAdded = collector.addRestriction(grr);
if (numAdded > 0)
log.info(messagePrefix, restriction, "added - allows routing to way", toWayIds.get(0));
} else {
log.error("mkgmap internal error: unknown restriction", restriction);
}
}
Aggregations