@SuppressWarnings("deprecation") public LocationIterableProperties asGeoJson() { final Map<String, String> tagsNo = Maps.hashMap("highway", "primary", "oneway", "yes", "type", "NO"); final Map<String, String> tagsOnly = Maps.hashMap("highway", "primary", "oneway", "yes", "type", "ONLY"); return new LocationIterableProperties(this.route().asPolyLine(), this.getTurnRestrictionType() == TurnRestrictionType.NO ? tagsNo : tagsOnly); }
/** * Create a {@link TurnRestriction} from a {@link Relation} * * @param relation * The {@link Relation} to use * @return An option on a {@link TurnRestriction}, which is filled if the {@link Relation} could * be translated to a {@link TurnRestriction} */ public static Optional<TurnRestriction> from(final Relation relation) { final TurnRestriction turnRestriction = new TurnRestriction(relation); if (turnRestriction.isValid()) { return Optional.of(turnRestriction); } else { return Optional.empty(); } }
/** * @param turnRestriction * The {@link TurnRestriction} to use for comparison * @param path * The target {@link Route} to examine * @return {@code true} if the given {@link Route} contains all parts - via/from/to edges */ private static boolean routeContainsAllTurnRestrictionParts( final TurnRestriction turnRestriction, final Route route) { final Optional<Route> possibleVia = turnRestriction.getVia(); boolean viaMatches = true; if (possibleVia.isPresent()) { viaMatches = route.isSubRoute(possibleVia.get()); } return viaMatches && route.isSubRoute(turnRestriction.getTo()) && route.isSubRoute(turnRestriction.getFrom()); }
.from(relation); if (turnRestrictionOption.isPresent()) final Route path = turnRestriction.route(); switch (turnRestriction.getTurnRestrictionType()) && routeContainsAllTurnRestrictionParts(turnRestriction, candidate)) final Route from = turnRestriction.getFrom(); .subRoute(fromSubRouteIndex + 1, routeEndIndex + 1); if (turnRestriction.otherToOptions().stream() .anyMatch(partialRoute::startsWith)) turnRestriction.getTurnRestrictionType()); return false; default: turnRestriction.getTurnRestrictionType());
@Override protected Optional<CheckFlag> flag(final AtlasObject object) { final Optional<CheckFlag> result; final Relation relation = (Relation) object; if (!TurnRestriction.from(relation).isPresent()) { final Set<AtlasObject> members = relation.members().stream() .map(RelationMember::getEntity).collect(Collectors.toSet()); result = Optional.of(createFlag(members, this.getLocalizedInstruction(0, relation.getOsmIdentifier()))); } else { result = Optional.empty(); } return result; }
protected ComplexTurnRestriction(final AtlasEntity source, final Predicate<Edge> validEdge) { super(source); try { this.turnRestriction = TurnRestriction.from((Relation) source) .orElseThrow(() -> new CoreException( "{} is not a turn restriction according to Atlas", source.getIdentifier())); final Route route = this.turnRestriction.route(); final int routeLength = route.size(); if (routeLength < 2) { throw new CoreException("Must have at least two edges in the route"); } final long filteredLength = StreamSupport.stream(route.spliterator(), false) .filter(validEdge).count(); if (filteredLength < routeLength) { throw new CoreException("{} invalid edges", routeLength - filteredLength); } } catch (final Exception oops) { logger.trace("Unable to create ComplexTurnRestriction from {}", source, oops); setInvalidReason("Couldn't create ComplexTurnRestriction", oops); } }
Route toMember = null; this.relation = relation; this.type = getTurnRestrictionType(relation); if (this.type == TurnRestrictionType.OTHER) if (viaMembers.isEmpty()) if (isSameRoadViaAndTo(relation))
@Test public void testOnlyRestriction() { final Atlas atlasOnly = this.rule.getAtlasOnly(); logger.trace("AtlasOnly: {}", atlasOnly); final Route candidate = Route.forEdges(atlasOnly.edge(102), atlasOnly.edge(203)); int counter = 0; for (final ComplexTurnRestriction restriction : new ComplexTurnRestrictionFinder() .find(atlasOnly, Finder::ignore)) { if (restriction.getTurnRestriction() .getTurnRestrictionType() == TurnRestrictionType.ONLY) { final Route route = restriction.route(); if (candidate.equals(route)) { counter++; } } } Assert.assertEquals(1, counter); final Set<RestrictedPath> paths = new HashSet<>(); for (final BigNode bigNode : new BigNodeFinder().find(atlasOnly, Finder::ignore)) { paths.addAll(bigNode.turnRestrictions()); } Assert.assertEquals(3, paths.size()); }
/** * @return true if this {@link Route} contains a Turn Restriction given OSM's definition. */ public boolean isTurnRestriction() { return TurnRestriction.isTurnRestriction(this); }
@Override public GeoJsonObject convert(final Atlas atlas) { return new GeoJsonBuilder() .create(Iterables.translate(new ComplexTurnRestrictionFinder().find(atlas), turnRestriction -> turnRestriction.getTurnRestriction().asGeoJson())); } }
@Test public void testTurnRestrictionWithTwoViaNodesInRelation() { final Atlas testAtlas = this.rule.getRelationWithTwoViaNodes(); logger.trace("Atlas relation with 2 via nodes: {}", testAtlas); // For more than 1 via nodes in relation for restriction, TurnRestriction will always // return an empty optional final Optional<TurnRestriction> possibleTurnRestriction = TurnRestriction .from(testAtlas.relation(1L)); Assert.assertEquals(Optional.empty(), possibleTurnRestriction); }
.find(atlasNo, Finder::ignore)) if (restriction.getTurnRestriction().getTurnRestrictionType() == TurnRestrictionType.NO)
@Test public void testTurnRestrictionNoUTurn() { // Test edge as via member final Atlas testAtlas = this.rule.getAtlasNoUTurn(); final Optional<TurnRestriction> possibleTurnRestriction = TurnRestriction .from(testAtlas.relation(1L)); Assert.assertTrue(possibleTurnRestriction.isPresent()); } }