/** * retrieve cell for a given coordinate. Cell with closest centroid will be returne * * @param coordinate coordinate within a cell * @return Cell with closest centroid. */ public Cell<T> getCell(Coordinate coordinate) { return quadTree.getClosest(coordinate.x, coordinate.y); }
final ActivityFacility getFacility( final String type, final Coord coordBarycenter, final double angle, final double distance ) { final double xLoc = coordBarycenter.getX() + distance * Math.cos( angle ); final double yLoc = coordBarycenter.getY() + distance * Math.sin( angle ); return quadTreePerType.get( type ).getClosest(xLoc, yLoc); }
public TransitStopFacility getNearestTransitStopFacility(final Coord coord) { return this.quadTree.getClosest(coord.getX(), coord.getY()); }
public TransitRouterNetworkNode getNearestNode(final Coord coord) { return this.qtNodes.getClosest(coord.getX(), coord.getY()); }
public TransitRouterNetworkNode getNearestNode(final Coord coord) { return this.qtNodes.getClosest(coord.getX(), coord.getY()); }
/** * finds the node nearest to <code>coord</code> * * @param coord the coordinate to which the closest node should be found * @return the closest node found, null if none */ @Override public Node getNearestNode(final Coord coord) { if (this.nodeQuadTree == null) { buildQuadTree(); } return this.nodeQuadTree.getClosest(coord.getX(), coord.getY()); }
/** * finds the node nearest to <code>coord</code> * * @param coord the coordinate to which the closest node should be found * @return the closest node found, null if none */ @Override public ActivityFacility getNearestFacility(final Coord coord) { if (this.facilitiesQuadTree == null) { buildQuadTree(); } return this.facilitiesQuadTree.getClosest(coord.getX(), coord.getY()); }
public double getPtTravelDistance_meter(Coord fromCoord, Coord toCoord){ PtStop fromPtStop = this.ptStops.getClosest(fromCoord.getX(), fromCoord.getY()); PtStop toPtStop = this.ptStops.getClosest(toCoord.getX(), toCoord.getY()); Entry entry = originDestinationTravelDistanceMatrix.getEntry(fromPtStop.getId().toString(), toPtStop.getId().toString()); double ptTravelDistance = Double.MAX_VALUE; if(entry != null) ptTravelDistance = entry.getValue(); else{ // log.warn("No entry found in od travel distances matrix for pt stops: " + fromPtStop.getId() + " " + toPtStop.getId()); if(fromPtStop == toPtStop) ptTravelDistance = 0.; } return ptTravelDistance; }
public double getTotalWalkTravelDistance_meter(Coord fromFacilityCoord, Coord toFacilityCoord){ PtStop fromPtStop = this.ptStops.getClosest(fromFacilityCoord.getX(), fromFacilityCoord.getY()); PtStop toPtStop = this.ptStops.getClosest(toFacilityCoord.getX(), toFacilityCoord.getY()); double walkTravelDistanceFromFacility2FromPtStop = CoordUtils.calcEuclideanDistance(fromFacilityCoord, fromPtStop.getCoord()); double walkTravelDistanceToPtStop2ToFacility = CoordUtils.calcEuclideanDistance(toPtStop.getCoord(), toFacilityCoord); double totalWalkTravelDistance = walkTravelDistanceFromFacility2FromPtStop + walkTravelDistanceToPtStop2ToFacility; return totalWalkTravelDistance; }
public double getPtTravelTime_seconds(Coord fromFacilityCoord, Coord toFacilityCoord){ // get pt stops PtStop fromPtStop = this.ptStops.getClosest(fromFacilityCoord.getX(), fromFacilityCoord.getY()); PtStop toPtStop = this.ptStops.getClosest(toFacilityCoord.getX(), toFacilityCoord.getY()); Entry entry = originDestinationTravelTimeMatrix.getEntry(fromPtStop.getId().toString(), toPtStop.getId().toString()); double ptTravelTime = Double.MAX_VALUE; if(entry != null) ptTravelTime = entry.getValue(); else{ // log.warn("No entry found in od travel times matrix for pt stops: " + fromPtStop.getId() + " " + toPtStop.getId()); if(fromPtStop == toPtStop) { ptTravelTime = 0.; } else { throw new RuntimeException("Trying to route matrix based pt through a pair of od stops that is not contained in the" + "travel time od matrix. fromPtStop = " + fromPtStop.getId() + " -- toPtStop = " + toPtStop.getId()); } } return ptTravelTime; }
/** * returns the total walk travel times in seconds including * - walk travel time from given coordinate to next pt stop * - walk travel time from destination pt stop to given destination coordinate * * @param fromFacilityCoord * @param toFacilityCoord * @return */ public double getTotalWalkTravelTime_seconds(Coord fromFacilityCoord, Coord toFacilityCoord){ PtStop fromPtStop = this.ptStops.getClosest(fromFacilityCoord.getX(), fromFacilityCoord.getY()); PtStop toPtStop = this.ptStops.getClosest(toFacilityCoord.getX(), toFacilityCoord.getY()); double walkTravelTimeFromFacility2FromPtStop = CoordUtils.calcEuclideanDistance(fromFacilityCoord, fromPtStop.getCoord()) / meterPerSecWalkSpeed; double walkTravelTimeToPtStop2ToFacility = CoordUtils.calcEuclideanDistance(toPtStop.getCoord(), toFacilityCoord) / meterPerSecWalkSpeed; double totalWalkTravelTime = walkTravelTimeFromFacility2FromPtStop + walkTravelTimeToPtStop2ToFacility; return totalWalkTravelTime; }
@Test public void testGetXY_EntryOnDividingBorder() { QuadTree<String> qt = new QuadTree<>(0, 0, 40, 60); qt.put(10.0, 10.0, "10.0, 10.0"); qt.put(20.0, 20.0, "20.0, 20.0"); // on vertical border qt.put(20.0, 30.0, "20.0, 30.0"); // exactly on center qt.put(30.0, 30.0, "30.0, 30.0"); // on horizontal border assertEquals("20.0, 20.0", qt.getClosest(20.0, 20.0)); assertEquals("20.0, 30.0", qt.getClosest(20.0, 30.0)); assertEquals("30.0, 30.0", qt.getClosest(30.0, 30.0)); }
@Test public void testGetXY_EntryOnOutsideBorder() { QuadTree<String> qt = new QuadTree<>(0.0, 0.0, 40.0, 60.0); // the 4 corners qt.put(0.0, 0.0, "SW"); qt.put(40.0, 0.0, "SE"); qt.put(0.0, 60.0, "NW"); qt.put(40.0, 60.0, "NE"); // the 4 sides qt.put(10.0, 60.0, "N"); qt.put(40.0, 10.0, "E"); qt.put(10.0, 0.0, "S"); qt.put(0.0, 10.0, "W"); assertEquals("SW", qt.getClosest(0.0, 0.0)); assertEquals("SE", qt.getClosest(40.0, 0.0)); assertEquals("NW", qt.getClosest(0.0, 60.0)); assertEquals("NE", qt.getClosest(40.0, 60.0)); assertEquals("N", qt.getClosest(10.0, 60.0)); assertEquals("E", qt.getClosest(40.0, 10.0)); assertEquals("S", qt.getClosest(10.0, 0.0)); assertEquals("W", qt.getClosest(0.0, 10.0)); }
ActivityFacility newFacility; if (requiredModes.size() > 1) { newFacility = this.facilityQuadTrees.get(this.allModes).getClosest(activity.getCoord().getX(), activity.getCoord().getY()); } else { String[] modes = new String[1]; requiredModes.toArray(modes); newFacility = this.facilityQuadTrees.get(modes[0]).getClosest(activity.getCoord().getX(), activity.getCoord().getY()); Link newLink; if (requiredModes.size() > 1) { newLink = this.linkQuadTrees.get(this.allModes).getClosest(activity.getCoord().getX(), activity.getCoord().getY()); } else { String[] modes = new String[1]; requiredModes.toArray(modes); newLink = this.linkQuadTrees.get(modes[0]).getClosest(activity.getCoord().getX(), activity.getCoord().getY());
private void setActivityCoord2NearestReceiverPointId () { double gap = noiseParams.getReceiverPointGap(); Counter counter = new Counter("fill quadtree #") ; QuadTree<ReceiverPoint> qTree = new QuadTree<>(xCoordMin - 4*gap, yCoordMin - 4* gap, xCoordMax + 4*gap, yCoordMax + 4*gap); for(ReceiverPoint p: receiverPoints.values()) { qTree.put(p.getCoord().getX(), p.getCoord().getY(), p); counter.incCounter(); } counter.printCounter(); counter = new Counter("compute nearest receiver-points #"); for (Coord coord : consideredActivityCoordsForSpatialFunctionality) { // TODO maybe add a check here so we consider only the rp in the 9 surrounding cells? ReceiverPoint rp = qTree.getClosest(coord.getX(), coord.getY()); if(rp != null) { if(activityCoord2receiverPointId.put(coord, rp.getId()) != null){ log.warn("this must not happen"); } } counter.incCounter(); } counter.printCounter(); }
assertEquals("10.0, 10.0", qt.getClosest(0.0, 0.0)); // test nearest assertEquals("-15.0, 0.0", qt.getClosest(-5.0, 0.0)); // test nearest assertEquals("20.0, 10.0", qt.getClosest(20.0, 10.0)); // test with exact coordinate String object = qt.getClosest(14.9, 14.9); assertTrue("15.0, 15.0".equals(object) || "15.0, 15.0 B".equals(object));
assertEquals("15.0, 15.0 B", qt.getClosest(15.0, 15.0)); // the other object should still be there... assertEquals("15.0, 15.0", qt.getClosest(15.0, 15.0)); // the other object should still be there...