use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class RoadMerger method workoutThroughRoutes.
private void workoutThroughRoutes(List<Relation> throughRouteRelations) {
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");
}
}
if (node == null)
log.warn("Through route relation " + relation.toBrowseURL() + " is missing the junction node");
if (w1 == null || w2 == null)
log.warn("Through route relation " + relation.toBrowseURL() + " should reference 2 ways that meet at the junction node");
if (node != null && w1 != null && w2 != null) {
restrictions.add(node.getLocation(), w1.getId());
restrictions.add(node.getLocation(), w2.getId());
}
}
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class HousenumberGenerator method addRelation.
/**
* Evaluate type=associatedStreet relations.
*/
public void addRelation(Relation r) {
String relType = r.getTag("type");
// the wiki says that we should also evaluate type=street
if ("associatedStreet".equals(relType) || "street".equals(relType)) {
List<Element> houses = new ArrayList<>();
List<Element> streets = new ArrayList<>();
for (Map.Entry<String, Element> member : r.getElements()) {
if (member.getValue() instanceof Node) {
Node node = (Node) member.getValue();
houses.add(node);
} else if (member.getValue() instanceof Way) {
Way w = (Way) member.getValue();
String role = member.getKey();
switch(role) {
case "house":
case "addr:houselink":
case "address":
houses.add(w);
break;
case "street":
streets.add(w);
break;
case "":
if (w.getTag("highway") != null) {
streets.add(w);
continue;
}
String buildingTag = w.getTag("building");
if (buildingTag != null)
houses.add(w);
else
log.warn("Relation", r.toBrowseURL(), ": role of member", w.toBrowseURL(), "unclear");
break;
default:
if ("associatedStreet".equals(relType))
log.warn("Relation", r.toBrowseURL(), ": don't know how to handle member with role", role);
break;
}
}
}
String streetName = r.getTag("name");
String streetNameFromRoads = null;
List<Element> unnamedStreetElems = new ArrayList<>();
boolean nameFromStreetsIsUnclear = false;
if (streets.isEmpty() == false) {
for (Element street : streets) {
String roadName = street.getTag(streetTagKey);
if (roadName == null)
roadName = street.getTag("name");
if (roadName == null) {
unnamedStreetElems.add(street);
continue;
}
if (streetNameFromRoads == null)
streetNameFromRoads = roadName;
else if (streetNameFromRoads.equals(roadName) == false)
nameFromStreetsIsUnclear = true;
}
}
if (streetName == null) {
if (nameFromStreetsIsUnclear == false)
streetName = streetNameFromRoads;
else {
log.warn("Relation", r.toBrowseURL(), ": ignored, street name is not clear.");
return;
}
} else {
if (streetNameFromRoads != null) {
if (nameFromStreetsIsUnclear == false && streetName.equals(streetNameFromRoads) == false) {
if (unnamedStreetElems.isEmpty() == false) {
log.warn("Relation", r.toBrowseURL(), ": ignored, street name is not clear.");
return;
}
log.warn("Relation", r.toBrowseURL(), ": street name is not clear, using the name from the way, not that of the relation.");
streetName = streetNameFromRoads;
} else if (nameFromStreetsIsUnclear == true) {
log.warn("Relation", r.toBrowseURL(), ": street name is not clear, using the name from the relation.");
}
}
}
int countModHouses = 0;
if (streetName != null && streetName.isEmpty() == false) {
for (Element house : houses) {
if (addStreetTagFromRel(r, house, streetName))
countModHouses++;
}
for (Element street : unnamedStreetElems) {
street.addTag(streetTagKey, streetName);
street.addTag("name", streetName);
}
}
if (log.isInfoEnabled()) {
if (countModHouses > 0 || !unnamedStreetElems.isEmpty()) {
if (countModHouses > 0)
log.info("Relation", r.toBrowseURL(), ": added tag mkgmap:street=", streetName, "to", countModHouses, "of", houses.size(), "house members");
if (!unnamedStreetElems.isEmpty())
log.info("Relation", r.toBrowseURL(), ": added tag mkgmap:street=", streetName, "to", unnamedStreetElems.size(), "of", streets.size(), "street members");
} else
log.info("Relation", r.toBrowseURL(), ": ignored, no house or street member was changed");
}
}
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class OsmXmlHandler method startInRelation.
/**
* A new tag has been started while we are inside the relation tag.
* @param qName The new tag name.
* @param attributes Its attributes.
*/
private void startInRelation(String qName, Attributes attributes) {
if (qName.equals("member")) {
long id = idVal(attributes.getValue("ref"));
Element el;
String type = attributes.getValue("type");
if ("way".equals(type)) {
el = saver.getWay(id);
} else if ("node".equals(type)) {
el = saver.getNode(id);
if (el == null) {
// we didn't make a node for this point earlier,
// do it now (if it exists)
Coord co = saver.getCoord(id);
if (co != null) {
el = new Node(id, co);
saver.addNode((Node) el);
}
}
} else if ("relation".equals(type)) {
el = saver.getRelation(id);
if (el == null) {
saver.deferRelation(id, currentRelation, attributes.getValue("role"));
}
} else
el = null;
if (// ignore non existing ways caused by splitting files
el != null)
currentRelation.addElement(attributes.getValue("role"), el);
} else if (qName.equals("tag")) {
String key = attributes.getValue("k");
String val = attributes.getValue("v");
// the type tag is required for relations - all other tags are filtered
if ("type".equals(key))
// intern the key
key = "type";
else
key = keepTag(key, val);
if (key == null) {
currentRelation.setTagsIncomplete(true);
} else {
currentRelation.addTagFromRawOSM(key, val);
}
}
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class AddAccessActionTest method testNoMatchingAlternatives.
/**
* The add/set commands now support alternatives just like the name command
* has always done.
* Several alternatives, but none match.
*/
@Test
public void testNoMatchingAlternatives() {
AddAccessAction act = new AddAccessAction("${notset}", false);
act.add("${hello}");
act.add("${world}");
Element el = stdElement();
act.perform(el);
for (String accessTag : ACCESS_TAGS.keySet()) assertNull(accessTag + "a not set", el.getTag(accessTag));
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class AddAccessActionTest method stdElement.
private Element stdElement() {
Element el1 = new Way(1);
el1.addTag("access", ACCESSVAL);
el1.addTag("bicycle", "yes");
el1.addTag("foot", "private");
el1.addTag("highway", "track");
return el1;
}
Aggregations