use of uk.me.parabola.mkgmap.reader.osm.Way 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.Way 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.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class StyledConverter method makeCycleWay.
/**
* Construct a cycleway that has the same points as an existing way. Used for separate
* cycle lanes.
* @param way The original way.
* @return The new way, which will have the same points and have suitable cycle tags.
*/
private static Way makeCycleWay(Way way) {
Way cycleWay = new Way(way.getId(), way.getPoints());
cycleWay.copyTags(way);
cycleWay.addTag("access", "no");
cycleWay.addTag("bicycle", "yes");
cycleWay.addTag("mkgmap:synthesised", "yes");
cycleWay.addTag(onewayTagKey, "no");
// remove explicit access tags
cycleWay.deleteTag("foot");
cycleWay.deleteTag("motorcar");
cycleWay.deleteTag("goods");
cycleWay.deleteTag("hgv");
cycleWay.deleteTag("bus");
cycleWay.deleteTag("taxi");
cycleWay.deleteTag("emergency");
cycleWay.deleteTag("vehicle");
cycleWay.deleteTag("motor_vehicle");
cycleWay.deleteTag("carpool");
cycleWay.deleteTag("motorcycle");
cycleWay.deleteTag("psv");
cycleWay.deleteTag("truck");
return cycleWay;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class StyledConverter method filterCoordPOI.
/**
* Make sure that only CoordPOI which affect routing will be treated as
* nodes in the following routines.
*/
private void filterCoordPOI() {
if (!linkPOIsToWays)
return;
log.info("translating CoordPOI");
for (ConvertedWay cw : roads) {
if (!cw.isValid())
continue;
Way way = cw.getWay();
if ("true".equals(way.getTag("mkgmap:way-has-pois"))) {
String wayPOI = "";
List<Coord> points = way.getPoints();
int numPoints = points.size();
for (int i = 0; i < numPoints; i++) {
Coord p = points.get(i);
if (p instanceof CoordPOI) {
CoordPOI cp = (CoordPOI) p;
Node node = cp.getNode();
boolean usedInThisWay = false;
byte wayAccess = cw.getAccess();
if (node.getTag("mkgmap:road-class") != null || node.getTag("mkgmap:road-speed") != null) {
if (wayAccess != AccessTagsAndBits.FOOT)
usedInThisWay = true;
}
byte nodeAccess = AccessTagsAndBits.evalAccessTags(node);
if (nodeAccess != (byte) 0xff) {
// barriers etc.
if ((wayAccess & nodeAccess) != wayAccess) {
// node is more restrictive
if (p.getHighwayCount() >= 2 || (i != 0 && i != numPoints - 1)) {
usedInThisWay = true;
cp.setConvertToViaInRouteRestriction(true);
} else {
log.info("POI node", node.getId(), "with access restriction is ignored, it is not connected to other routable ways");
}
} else
log.info("Access restriction in POI node", node.toBrowseURL(), "was ignored for way", way.toBrowseURL());
}
if (usedInThisWay) {
cp.setUsed(true);
wayPOI += "[" + node.getId() + "]";
}
}
}
if (wayPOI.isEmpty()) {
way.deleteTag("mkgmap:way-has-pois");
log.info("ignoring CoordPOI(s) for way", way.toBrowseURL(), "because routing is not affected.");
} else {
way.addTag(WAY_POI_NODE_IDS, wayPOI);
}
}
}
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class StyledConverter method splitWayAt.
/**
* split a Way at the specified point and return the new Way (the
* original Way is truncated, both ways will contain the split point)
* @param way the way to split
* @param index the split position.
* @return the trailing part of the way
*/
private static Way splitWayAt(Way way, int index) {
if (way.isViaWay()) {
log.warn("via way of restriction is split, restriction will be ignored", way);
}
Way trailingWay = new Way(way.getId());
List<Coord> wayPoints = way.getPoints();
int numPointsInWay = wayPoints.size();
for (int i = index; i < numPointsInWay; ++i) trailingWay.addPoint(wayPoints.get(i));
// ensure split point becomes a node
wayPoints.get(index).incHighwayCount();
// copy the way's name and tags to the new way
trailingWay.copyTags(way);
// it's probably more efficient to remove from the end first
for (int i = numPointsInWay - 1; i > index; --i) wayPoints.remove(i);
return trailingWay;
}
Aggregations