/** * This method determines if an observation record is within a certain radius, * _terminalSearchRadius argument, of a stop at the start or end of a block. <br> * Note: all trips' stops within the radius are checked. * * @param record * @return whether the observation is within the search radius */ public boolean isAtPotentialBlockTerminal(NycRawLocationRecord record) { final CoordinatePoint loc = new CoordinatePoint(record.getLatitude(), record.getLongitude()); final CoordinateBounds bounds = SphericalGeometryLibrary.bounds(loc, _terminalSearchRadius); final List<BlockConfigurationEntry> blocks = new ArrayList<BlockConfigurationEntry>(); final List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds); for (final StopEntry stop : stops) { final List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop); for (final BlockStopTimeIndex stopTimeIndex : stopTimeIndices) { blocks.addAll(stopTimeIndex.getBlockConfigs()); } } for (final BlockConfigurationEntry block : blocks) { final StopEntry firstStop = block.getStopTimes().get(0).getStopTime().getStop(); final double firstStopDist = TurboButton.distance(loc, firstStop.getStopLocation()); final int lastStopIdx = block.getStopTimes().size() - 1; final StopEntry lastStop = block.getStopTimes().get(lastStopIdx).getStopTime().getStop(); final double lastStopDist = TurboButton.distance(loc, lastStop.getStopLocation()); if (firstStopDist <= _terminalSearchRadius || lastStopDist <= _terminalSearchRadius) { return true; } } return false; }
/** * This method determines if an observation record is within a certain radius, * _terminalSearchRadius argument, of a stop at the start or end of a trip. <br> * Note: all trips' stops within the radius are checked. * * @param record * @return whether the observation is within the search radius */ public boolean isAtPotentialTripTerminal(NycRawLocationRecord record) { final CoordinatePoint loc = new CoordinatePoint(record.getLatitude(), record.getLongitude()); final CoordinateBounds bounds = SphericalGeometryLibrary.bounds(loc, _terminalSearchRadius); final List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds); for (final StopEntry stop : stops) { final List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop); for (final BlockStopTimeIndex stopTimeIndex : stopTimeIndices) { for (final BlockTripEntry bte : stopTimeIndex.getTrips()) { /* * is this the first stop on this trip? */ final List<StopTimeEntry> stopsOnTrip = bte.getTrip().getStopTimes(); if (stop.equals(stopsOnTrip.get(0).getStop())) { return true; } final int numOfStops = stopsOnTrip.size() - 1; if (stop.equals(stopsOnTrip.get(numOfStops).getStop())) { return true; } } } } return false; }
/** * This method determines if an observation record is within a certain radius, * _terminalSearchRadius argument, of a stop at the start or end of a given block. * * @param record * @param blockInstance * @return whether the observation is within the search radius */ public static boolean isAtPotentialBlockTerminal( NycRawLocationRecord record, BlockInstance blockInstance) { final CoordinatePoint loc = new CoordinatePoint(record.getLatitude(), record.getLongitude()); final StopEntry firstStop = blockInstance.getBlock().getStopTimes().get(0).getStopTime().getStop(); final double firstStopDist = TurboButton.distance(loc, firstStop.getStopLocation()); final int lastStopIdx = blockInstance.getBlock().getStopTimes().size() - 1; final StopEntry lastStop = blockInstance.getBlock().getStopTimes().get(lastStopIdx).getStopTime().getStop(); final double lastStopDist = TurboButton.distance(loc, lastStop.getStopLocation()); if (firstStopDist <= _terminalSearchRadius || lastStopDist <= _terminalSearchRadius) { return true; } return false; }