@Override public String toString() { return "[TemporaryOrderedNode: id = " + this.nodeIdentifier + " (" + this.node.getLocation() + "), offset = " + this.offset + ", occurrence = " + this.occurrenceIndex + "]"; } }
@Override public Location getLocation() { return subNode().getLocation(); }
@Override public boolean validCheckForObject(final AtlasObject object) { return object instanceof Node && !this.isFlagged(((Node) object).getLocation()); }
@Override public Location getLocation() { return getRepresentativeSubNode().getLocation(); }
@Override public boolean equals(final Object other) { if (other instanceof TemporaryOrderedNode) { final TemporaryOrderedNode that = (TemporaryOrderedNode) other; return this.node.getLocation().equals(that.node.getLocation()) && this.offset.equals(that.offset) && this.occurrenceIndex == that.getOccurrenceIndex(); } return false; }
/** * @param atlas * The {@link Atlas} on which the router works * @param threshold * The threshold to look for edges in case of routing between locations * @return A Dijkstra router (the heuristic looks at the distance from the start only) */ public static AStarRouter dijkstra(final Atlas atlas, final Distance threshold) { return new AStarRouter(atlas, threshold, (start, candidate, end) -> start.getLocation() .distanceTo(candidate.getLocation()).asMeters()); }
/** * @param atlas * The {@link Atlas} on which the router works * @param threshold * The threshold to look for edges in case of routing between locations * @return A balanced A* Router, which gives 75% cost to the distance from the end and 25% cost * to the distance from the start. */ public static AStarRouter balanced(final Atlas atlas, final Distance threshold) { final double distanceFromStartCostRatio = 0.25; return new AStarRouter(atlas, threshold, (start, candidate, end) -> distanceFromStartCostRatio * start.getLocation().distanceTo(candidate.getLocation()).asMeters() + (1 - distanceFromStartCostRatio) * candidate.getLocation().distanceTo(end.getLocation()).asMeters()); }
/** * @param atlas * The {@link Atlas} on which the router works * @param threshold * The threshold to look for edges in case of routing between locations * @return A fast A* Router, which gives all cost to the distance from the end. The route will * be found faster, but the result will be non-optimal */ public static AStarRouter fastComputationAndSubOptimalRoute(final Atlas atlas, final Distance threshold) { return new AStarRouter(atlas, threshold, (start, candidate, end) -> candidate.getLocation() .distanceTo(end.getLocation()).asMeters()); }
/** * Note: The start and end {@link Node}s of the {@link Route} are part of the hash code to * reduce the probability of a collision. There are other candidates to add here, like distance * between start/end, but start/end by themselves are the least computationally intensive to * derive. */ @Override public int hashCode() { return new HashCodeBuilder().append(this.start().start().getLocation()) .append(this.end().end().getLocation()).append(Iterables.asList(this)).hashCode(); }
/** * Create a full copy of the given node. * * @param node * the {@link Node} to deep copy * @return the new {@link CompleteNode} */ public static CompleteNode from(final Node node) { return new CompleteNode(node.getIdentifier(), node.getLocation(), node.getTags(), node.inEdges().stream().map(Edge::getIdentifier) .collect(Collectors.toCollection(TreeSet::new)), node.outEdges().stream().map(Edge::getIdentifier) .collect(Collectors.toCollection(TreeSet::new)), node.relations().stream().map(Relation::getIdentifier).collect(Collectors.toSet())); }
public static AtlasPrimitiveLocationItem from(final Node node) { final AtlasPrimitiveLocationItem locationItem = new AtlasPrimitiveLocationItem( node.getIdentifier(), node.getLocation(), node.getTags()); return locationItem; }
public LocationIterableProperties asGeoJsonBigNode() { final List<Location> locations = new ArrayList<>(); nodes().stream().forEach(node -> locations .addAll(Rectangle.forLocated(node.getLocation()).expand(Distance.meters(2)))); return new LocationIterableProperties(new Polygon(locations), Maps.hashMap("BigNode", String.valueOf(getSource().getIdentifier()))); }
/** * Create a shallow copy of a given node. All fields (except the identifier and the geometry) * are left null until updated by a with() call. * * @param node * the {@link Node} to copy * @return the new {@link CompleteNode} */ public static CompleteNode shallowFrom(final Node node) { return new CompleteNode(node.getIdentifier()) .withInitialBounds(node.getLocation().bounds()); }
@Override public Iterable<Node> nodesWithin(final Polygon polygon) { final Iterable<Node> nodes = this.getNodeSpatialIndex().get(polygon.bounds()); if (polygon instanceof Rectangle) { return nodes; } return Iterables.filter(nodes, node -> polygon.fullyGeometricallyEncloses(node.getLocation())); }
private boolean canAddEdgeToBoundary(final Edge edge, final Route boundary) { return edge.getIdentifier() != -boundary.end().getIdentifier() && edge.getOsmIdentifier() == boundary.end().getOsmIdentifier() && boundary.end().end().getLocation().equals(edge.start().getLocation()) && !boundary.includes(edge); } }
@Override public String toString() { return "[Node: id=" + this.getIdentifier() + ", location=" + this.getLocation() + ", inEdges=" + connectedEdgesIdentifiers(() -> inEdges()) + ", outEdges=" + connectedEdgesIdentifiers(() -> outEdges()) + ", " + tagString() + "]"; }
@Override public String toDiffViewFriendlyString() { final String relationsString = this.parentRelationsAsDiffViewFriendlyString(); return "[Node: id=" + this.getIdentifier() + ", location=" + this.getLocation() + ", inEdges=" + connectedEdgesIdentifiers(() -> inEdges()) + ", outEdges=" + connectedEdgesIdentifiers(() -> outEdges()) + ", relations=(" + relationsString + "), " + tagString() + "]"; }
private String convertNode(final Node item) { final StringList list = new StringList(); list.add(item.getIdentifier()); list.add(item.getLocation().toCompactString()); list.add(convertTags(item)); return list.join(SEPARATOR); }
@Test public void testNode() { final Node node1 = this.atlas.node(123); final Node node2 = this.atlas.node(1234); final Node node3 = this.atlas.node(12345); logger.trace(node1.toString()); logger.trace(node2.toString()); logger.trace(node3.toString()); Assert.assertEquals(node1.getLocation(), Location.TEST_6); Assert.assertEquals(node2.getLocation(), Location.TEST_5); Assert.assertEquals(node3.getLocation(), Location.TEST_2); Assert.assertEquals("turning_circle", node1.getTags().get("highway")); Assert.assertEquals("turning_circle", node2.getTags().get("highway")); Assert.assertEquals("turning_circle", node3.getTags().get("highway")); }
@Test public void testIndex() { final Rectangle testBox = Location.TEST_6.boxAround(Distance.ONE_METER); Assert.assertEquals(1, Iterables.size(this.atlas.nodesWithin(testBox))); Assert.assertEquals(Location.TEST_6, this.atlas.nodesWithin(testBox).iterator().next().getLocation()); Assert.assertEquals(3, Iterables.size(this.atlas.edgesIntersecting(testBox))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(9))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(-9))); Assert.assertTrue( Iterables.contains(this.atlas.edgesIntersecting(testBox), this.atlas.edge(987))); }