/** * This method set the spatial ID (e.g. country ID) of the specified flags to the specified id. Fetch the unique * spatial ID via spatialRuleLookup.lookup().getSpatialId */ public long setSpatialId(long flags, int id) { return spatialEncoder.setValue(flags, id); }
long setTransfers(long flags, int transfers) { return this.transfers.setValue(flags, transfers); }
long setValidityId(long flags, int validityId) { return this.validityId.setValue(flags, validityId); }
public long setDefaultValue(long flags) { return setValue(flags, defaultValue); }
long setTime(long flags, long time) { return this.time.setValue(flags, time); }
/** * Swap the contents controlled by this value encoder with the given value. * <p> * * @return the new flags */ public long swap(long flags, EncodedValue otherEncoder) { long otherValue = otherEncoder.getValue(flags); flags = otherEncoder.setValue(flags, getValue(flags)); return setValue(flags, otherValue); } }
@Override public long getTurnFlags(boolean restricted, double costs) { if (maxTurnCosts == 0) return 0; else if (maxTurnCosts == 1) { if (costs != 0) throw new IllegalArgumentException("Only restrictions are supported"); return restricted ? turnRestrictionBit : 0; } if (restricted) { if (costs != 0 || Double.isInfinite(costs)) throw new IllegalArgumentException("Restricted turn can only have infinite costs (or use 0)"); } else if (costs >= maxTurnCosts) throw new IllegalArgumentException("Cost is too high. Or specify restricted == true"); if (costs < 0) throw new IllegalArgumentException("Turn costs cannot be negative"); if (costs >= maxTurnCosts || restricted) costs = maxTurnCosts; return turnCostEncoder.setValue(0L, (int) costs); }
long setEdgeType(long flags, GtfsStorage.EdgeType edgeType) { return type.setValue(flags, edgeType.ordinal()); }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { oldRelationFlags = super.handleRelationTags(relation, oldRelationFlags); int code = 0; if (relation.hasTag("route", "mtb")) code = PREFER.getValue(); int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Test public void testSwap() { EncodedValue instance1 = new EncodedValue("test1", 0, 10, 1, 5, 1000); EncodedValue instance2 = new EncodedValue("test2", 10, 10, 1, 5, 1000); long flags = instance2.setValue(instance1.setValue(0, 13), 874); long swappedFlags = instance1.setValue(instance2.setValue(0, 13), 874); assertEquals(swappedFlags, instance1.swap(flags, instance2)); } }
/** * Handle surface and wayType encoding */ long handleBikeRelated(ReaderWay way, long encoded, boolean partOfCycleRelation) { String surfaceTag = way.getTag("surface"); String highway = way.getTag("highway"); String trackType = way.getTag("tracktype"); // Populate unpavedBit if ("track".equals(highway) && (trackType == null || !"grade1".equals(trackType)) || "path".equals(highway) && surfaceTag == null || unpavedSurfaceTags.contains(surfaceTag)) { encoded = setBool(encoded, K_UNPAVED, true); } WayType wayType; if (roadValues.contains(highway)) wayType = WayType.ROAD; else wayType = WayType.OTHER_SMALL_WAY; boolean isPushingSection = isPushingSection(way); if (isPushingSection && !partOfCycleRelation || "steps".equals(highway)) wayType = WayType.PUSHING_SECTION; if (way.hasTag("bicycle", intendedValues)) { if (isPushingSection && !way.hasTag("bicycle", "designated")) wayType = WayType.OTHER_SMALL_WAY; else if (wayType == WayType.OTHER_SMALL_WAY || wayType == WayType.PUSHING_SECTION) wayType = WayType.CYCLEWAY; } else if ("cycleway".equals(highway)) wayType = WayType.CYCLEWAY; return wayTypeEncoder.setValue(encoded, wayType.getValue()); }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { int code = 0; if (relation.hasTag("route", "hiking") || relation.hasTag("route", "foot")) { Integer val = hikingNetworkToCode.get(relation.getTag("network")); if (val != null) code = val; else code = hikingNetworkToCode.get("lwn"); } else if (relation.hasTag("route", "ferry")) { code = PriorityCode.AVOID_IF_POSSIBLE.getValue(); } int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Override public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) { int code = 0; if (relation.hasTag("route", "bicycle")) { Integer val = bikeNetworkToCode.get(relation.getTag("network")); if (val != null) code = val; else code = PriorityCode.PREFER.getValue(); // Assume priority of network "lcn" as bicycle route default } else if (relation.hasTag("route", "ferry")) { code = AVOID_IF_POSSIBLE.getValue(); } int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags); if (oldCode < code) return relationCodeEncoder.setValue(0, code); return oldRelationFlags; }
@Test public void testPriority() { long flags = encoder.priorityWayEncoder.setValue(0, PriorityCode.BEST.getValue()); assertEquals(1, encoder.getDouble(flags, PriorityWeighting.KEY), 1e-3); flags = encoder.priorityWayEncoder.setValue(0, PriorityCode.AVOID_IF_POSSIBLE.getValue()); assertEquals(3d / 7d, encoder.getDouble(flags, PriorityWeighting.KEY), 1e-3); }
@Override public void applyWayTags(ReaderWay way, EdgeIteratorState edge) { double speed = this.getSpeed(edge.getFlags()); double roadDistance = edge.getDistance(); double beelineDistance = getBeelineDistance(way); double bendiness = beelineDistance / roadDistance; bendiness = discriminateSlowStreets(bendiness, speed); bendiness = increaseBendinessImpact(bendiness); bendiness = correctErrors(bendiness); edge.setFlags(this.curvatureEncoder.setValue(edge.getFlags(), convertToInt(bendiness))); }
@Test public void testSetValue() { EncodedValue instance = new EncodedValue("test", 6, 4, 1, 5, 10); assertEquals(10, instance.getValue(instance.setValue(0, 10))); instance = new EncodedValue("test", 0, 4, 1, 5, 10); assertEquals(10, instance.getValue(instance.setValue(0, 10))); instance = new EncodedValue("test", 0, 4, 1, 5, 10); assertEquals(5, instance.getValue(instance.setDefaultValue(0))); }
@Override public long handleWayTags(ReaderWay way, long allowed, long relationFlags) { if (!isAccept(allowed)) return 0; long flags = 0; if (!isFerry(allowed)) { String sacScale = way.getTag("sac_scale"); if (sacScale != null) { if ("hiking".equals(sacScale)) flags = speedEncoder.setDoubleValue(flags, MEAN_SPEED); else flags = speedEncoder.setDoubleValue(flags, SLOW_SPEED); } else { flags = speedEncoder.setDoubleValue(flags, MEAN_SPEED); } flags |= directionBitMask; boolean isRoundabout = way.hasTag("junction", "roundabout") || way.hasTag("junction", "circular"); if (isRoundabout) flags = setBool(flags, K_ROUNDABOUT, true); } else { double ferrySpeed = getFerrySpeed(way); flags = setSpeed(flags, ferrySpeed); flags |= directionBitMask; } int priorityFromRelation = 0; if (relationFlags != 0) priorityFromRelation = (int) relationCodeEncoder.getValue(relationFlags); flags = priorityWayEncoder.setValue(flags, handlePriority(way, priorityFromRelation)); return flags; }
@Override public long handleWayTags(ReaderWay way, long allowed, long relationFlags) { if (!isAccept(allowed)) return 0; long flags = 0; double wayTypeSpeed = getSpeed(way); if (!isFerry(allowed)) { wayTypeSpeed = applyMaxSpeed(way, wayTypeSpeed); flags = handleSpeed(way, wayTypeSpeed, flags); flags = handleBikeRelated(way, flags, relationFlags > UNCHANGED.getValue()); boolean isRoundabout = way.hasTag("junction", "roundabout") || way.hasTag("junction", "circular"); if (isRoundabout) { flags = setBool(flags, K_ROUNDABOUT, true); } } else { double ferrySpeed = getFerrySpeed(way); flags = handleSpeed(way, ferrySpeed, flags); flags |= directionBitMask; } int priorityFromRelation = 0; if (relationFlags != 0) priorityFromRelation = (int) relationCodeEncoder.getValue(relationFlags); flags = priorityWayEncoder.setValue(flags, handlePriority(way, wayTypeSpeed, priorityFromRelation)); return flags; }