duration = Long.parseLong(way.getTag("duration:seconds")); } catch (Exception ex) { Number estimatedLength = way.getTag("estimated_distance", null); if (durationInHours > 0) try { long lastId = way.getNodes().isEmpty() ? -1 : way.getNodes().get(way.getNodes().size() - 1); long firstId = way.getNodes().isEmpty() ? -1 : way.getNodes().get(0); if (firstId != lastId) logger.warn("Unrealistic long duration ignored in way with way ID=" + way.getId() + " : Duration tag value=" + way.getTag("duration") + " (=" + Math.round(duration / 60d) + " minutes)"); durationInHours = 0;
@Override public long acceptWay(ReaderWay way) { String highwayValue = way.getTag("highway"); String firstValue = way.getFirstPriorityTag(restrictions); if (highwayValue == null) { if (way.hasTag("route", ferries)) { if (restrictedValues.contains(firstValue)) return 0; if (intendedValues.contains(firstValue) || firstValue.isEmpty() && !way.hasTag("foot") && !way.hasTag("bicycle")) return acceptBit | ferryBit; return 0; if (way.hasTag("impassable", "yes") || way.hasTag("status", "impassable")) return 0; if (isBlockFords() && ("ford".equals(highwayValue) || way.hasTag("ford"))) return 0;
@Override boolean isPushingSection(ReaderWay way) { String highway = way.getTag("highway"); String trackType = way.getTag("tracktype"); return way.hasTag("highway", pushingSectionsHighways) || way.hasTag("railway", "platform") || way.hasTag("bicycle", "dismount") || "track".equals(highway) && trackType != null && !"grade1".equals(trackType); }
/** * Filter ways but do not analyze properties wayNodes will be filled with participating node * ids. * <p> * * @return true the current xml entry is a way entry and has nodes */ boolean filterWay(ReaderWay item) { // ignore broken geometry if (item.getNodes().size() < 2) return false; // ignore multipolygon geometry if (!item.hasTags()) return false; return encodingManager.acceptWay(item) > 0; }
if (way.getNodes().size() < 2) return; if (!way.hasTags()) return; long wayOsmId = way.getId(); return; long relationFlags = getRelFlagsMap().get(way.getId()); LongArrayList osmNodeIds = way.getNodes(); double estimatedDist = distCalc.calcDist(firstLat, firstLon, lastLat, lastLon); way.setTag("estimated_distance", estimatedDist); way.setTag("estimated_center", new GHPoint((firstLat + lastLat) / 2, (firstLon + lastLon) / 2)); if (way.getTag("duration") != null) { try { long dur = OSMTagParser.parseDuration(way.getTag("duration")); way.setTag("duration:seconds", Long.toString(dur)); } catch (Exception ex) { LOGGER.warn("Parsing error in way with OSMID=" + way.getId() + " : " + ex.getMessage()); createdEdges.addAll(addOSMWay(way.getNodes(), wayFlags, wayOsmId));
private void processWays(List<Osmformat.Way> ways, PbfFieldDecoder fieldDecoder) { for (Osmformat.Way way : ways) { Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder); ReaderWay osmWay = new ReaderWay(way.getId()); osmWay.setTags(tags); // Build up the list of way nodes for the way. The node ids are // delta encoded meaning that each id is stored as a delta against // the previous one. long nodeId = 0; LongIndexedContainer wayNodes = osmWay.getNodes(); for (long nodeIdOffset : way.getRefsList()) { nodeId += nodeIdOffset; wayNodes.add(nodeId); } decodedEntities.add(osmWay); } }
protected boolean applies(ReaderWay way, boolean checkPermissiveValues) { for (int index = 0; index < tagsToCheck.size(); index++) { String tagToCheck = tagsToCheck.get(index); String val = way.getTag(tagToCheck); if (val == null || val.isEmpty()) continue; try { if (checkPermissiveValues) { if (permitParser.checkCondition(val)) return true; } else { if (restrictiveParser.checkCondition(val)) return true; } } catch (Exception e) { if (enabledLogs) { // log only if no date ala 21:00 as currently date and numbers do not support time precise restrictions if (!val.contains(":")) logger.warn("for way " + way.getId() + " could not parse the conditional value '" + val + "' of tag '" + tagToCheck + "'. Exception:" + e.getMessage()); } } } return false; } }
private long extractTons(ReaderWay way, long flags, EncodedDoubleValue valueEncoder, List<String> keys) { String value = way.getFirstPriorityTag(keys); if (isEmpty(value)) return flags; double val; try { val = stringToTons(value); } catch (Throwable t) { LOG.warn("Unable to extract tons from malformed road attribute '{}' for way (OSM_ID = {}).", value, way.getId(), t); return flags; } try { flags = valueEncoder.setDoubleValue(flags, val); } catch (IllegalArgumentException e) { LOG.warn("Unable to process tons value '{}' for way (OSM_ID = {}).", val, way.getId(), e); } return flags; }
double maxSpeed = parseSpeed(way.getTag("maxspeed")); if (maxSpeed < 0) { maxSpeed = getSpatialRule(way).getMaxSpeed(way.getTag("highway", ""), maxSpeed); double fwdSpeed = parseSpeed(way.getTag("maxspeed:forward")); if (fwdSpeed < 0 && maxSpeed > 0) fwdSpeed = maxSpeed; double bwdSpeed = parseSpeed(way.getTag("maxspeed:backward")); if (bwdSpeed < 0 && maxSpeed > 0) bwdSpeed = maxSpeed; String surfaceValue = way.getTag("surface"); Integer sValue = surfaceMap.get(surfaceValue); if (sValue == null) if (way.hasTag(tm)) { tmValue = transportModeMap.get(tm); break; boolean isRoundabout = way.hasTag("junction", "roundabout") || way.hasTag("junction", "circular"); if (isRoundabout) flags = setBool(flags, K_ROUNDABOUT, true); boolean isOneway = way.hasTag("oneway", oneways) || way.hasTag("vehicle:backward") || way.hasTag("vehicle:forward") || way.hasTag("motor_vehicle:backward")
private double getBeelineDistance(ReaderWay way) { return way.getTag("estimated_distance", Double.POSITIVE_INFINITY); }
@Override public String toString() { return "Way id:" + getId() + ", nodes:" + nodes.size() + ", tags:" + super.toString(); } }
private static void readNodes(ReaderWay way, XMLStreamReader parser) throws XMLStreamException { int event = parser.getEventType(); while (event != XMLStreamConstants.END_DOCUMENT && parser.getLocalName().equals("nd")) { if (event == XMLStreamConstants.START_ELEMENT) { // read node reference String ref = parser.getAttributeValue(null, "ref"); way.getNodes().add(Long.parseLong(ref)); } event = parser.nextTag(); } }
/** * @param way needed to retrieve tags * @param speed speed guessed e.g. from the road type or other tags * @return The assumed speed */ protected double applyBadSurfaceSpeed(ReaderWay way, double speed) { // limit speed if bad surface if (badSurfaceSpeed > 0 && speed > badSurfaceSpeed && way.hasTag("surface", badSurfaceSpeedMap)) speed = badSurfaceSpeed; return speed; }
@Test public void testHasTag() { ReaderElement instance = new ReaderWay(1); instance.setTag("surface", "something"); assertTrue(instance.hasTag("surface", "now", "something")); assertFalse(instance.hasTag("surface", "now", "not")); }
if (way.getNodes().size() < 2) return; if (!way.hasTags()) return; long wayOsmId = way.getId(); return; long relationFlags = getRelFlagsMap().get(way.getId()); LongArrayList osmNodeIds = way.getNodes(); double estimatedDist = distCalc.calcDist(firstLat, firstLon, lastLat, lastLon); way.setTag("estimated_distance", estimatedDist); way.setTag("estimated_center", new GHPoint((firstLat + lastLat) / 2, (firstLon + lastLon) / 2)); if (way.getTag("duration") != null) { try { long dur = OSMTagParser.parseDuration(way.getTag("duration")); way.setTag("duration:seconds", Long.toString(dur)); } catch (Exception ex) { LOGGER.warn("Parsing error in way with OSMID=" + way.getId() + " : " + ex.getMessage()); createdEdges.addAll(addOSMWay(way.getNodes(), wayFlags, wayOsmId));
int getHighwayValue(ReaderWay way) { String highwayValue = way.getTag("highway"); Integer hwValue = highwayMap.get(highwayValue); if (way.hasTag("impassable", "yes") || way.hasTag("status", "impassable")) hwValue = 0; if (hwValue == null) { hwValue = 0; if (way.hasTag("route", ferries)) { String motorcarTag = way.getTag("motorcar"); if (motorcarTag == null) motorcarTag = way.getTag("motor_vehicle"); if (motorcarTag == null && !way.hasTag("foot") && !way.hasTag("bicycle") || "yes".equals(motorcarTag)) hwValue = highwayMap.get("ferry"); } } return hwValue; }
private void processWays(List<Osmformat.Way> ways, PbfFieldDecoder fieldDecoder) { for (Osmformat.Way way : ways) { Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder); ReaderWay osmWay = new ReaderWay(way.getId()); osmWay.setTags(tags); // Build up the list of way nodes for the way. The node ids are // delta encoded meaning that each id is stored as a delta against // the previous one. long nodeId = 0; LongIndexedContainer wayNodes = osmWay.getNodes(); for (long nodeIdOffset : way.getRefsList()) { nodeId += nodeIdOffset; wayNodes.add(nodeId); } decodedEntities.add(osmWay); } }
protected boolean applies(ReaderWay way, boolean checkPermissiveValues) { for (int index = 0; index < tagsToCheck.size(); index++) { String tagToCheck = tagsToCheck.get(index); String val = way.getTag(tagToCheck); if (val == null || val.isEmpty()) continue; try { if (checkPermissiveValues) { if (permitParser.checkCondition(val)) return true; } else { if (restrictiveParser.checkCondition(val)) return true; } } catch (Exception e) { if (enabledLogs) { // log only if no date ala 21:00 as currently date and numbers do not support time precise restrictions if (!val.contains(":")) logger.warn("for way " + way.getId() + " could not parse the conditional value '" + val + "' of tag '" + tagToCheck + "'. Exception:" + e.getMessage()); } } } return false; } }