use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GtfsController method getStops.
@RequestMapping(value = "/stops/{agencyId}/{id}")
@ResponseBody
public List<CoordinatePoint> getStops(@PathVariable String agencyId, @PathVariable String id) {
AgencyAndId routeId = new AgencyAndId(agencyId, id);
RouteEntry route = _transitGraphDao.getRouteForId(routeId);
TripEntry trip = routeToTrip(route);
List<StopTimeEntry> stopTimes = trip.getStopTimes();
List<CoordinatePoint> points = new ArrayList<CoordinatePoint>();
for (StopTimeEntry entry : stopTimes) {
StopEntry stop = entry.getStop();
points.add(stop.getStopLocation());
}
return points;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactory method ensureStopTimesHaveShapeDistanceTraveledSet.
/**
* We have to make sure shape distance traveled is set, even if we don't have
* shape information
*
* @param stopTimes
* @param shapePoints potentially null
*/
private void ensureStopTimesHaveShapeDistanceTraveledSet(List<StopTimeEntryImpl> stopTimes, ShapePoints shapePoints) {
boolean distanceTraveledSet = false;
// Do we have shape information?
if (shapePoints != null) {
try {
PointAndIndex[] stopTimePoints = _distanceAlongShapeLibrary.getDistancesAlongShape(shapePoints, stopTimes);
for (int i = 0; i < stopTimePoints.length; i++) {
PointAndIndex pindex = stopTimePoints[i];
StopTimeEntryImpl stopTime = stopTimes.get(i);
stopTime.setShapePointIndex(pindex.index);
stopTime.setShapeDistTraveled(pindex.distanceAlongShape);
}
distanceTraveledSet = true;
} catch (StopIsTooFarFromShapeException ex) {
StopTimeEntry stopTime = ex.getStopTime();
TripEntry trip = stopTime.getTrip();
StopEntry stop = stopTime.getStop();
AgencyAndId shapeId = trip.getShapeId();
CoordinatePoint point = ex.getPoint();
PointAndIndex pindex = ex.getPointAndIndex();
_log.warn("Stop is too far from shape: trip=" + trip.getId() + " stop=" + stop.getId() + " stopLat=" + stop.getStopLat() + " stopLon=" + stop.getStopLon() + " shapeId=" + shapeId + " shapePoint=" + point + " index=" + pindex.index + " distance=" + pindex.distanceFromTarget);
} catch (DistanceAlongShapeException ex) {
_invalidStopToShapeMappingExceptionCount++;
} catch (IllegalArgumentException iae) {
_log.warn("Stop has illegal coordinates along shapes=" + shapePoints);
}
}
if (!distanceTraveledSet) {
// Make do without
double d = 0;
StopTimeEntryImpl prev = null;
for (StopTimeEntryImpl stopTime : stopTimes) {
if (prev != null) {
CoordinatePoint from = prev.getStop().getStopLocation();
CoordinatePoint to = stopTime.getStop().getStopLocation();
d += SphericalGeometryLibrary.distance(from, to);
}
stopTime.setShapeDistTraveled(d);
prev = stopTime;
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method computeContinuations.
/**
* For each given StopSequence, we wish to compute the set of StopSequences
* that continue the given StopSequence. We say one StopSequence continues
* another if the two stops sequences have the same route and direction id and
* each trip in the first StopSequence is immediately followed by a Trip from
* the second StopSequence, as defined by a block id.
*
* @param sequenceStats
* @param sequencesByGroupId
*/
private void computeContinuations(Map<StopSequence, PatternStats> sequenceStats, Map<String, List<StopSequence>> sequencesByGroupId) {
Map<BlockTripEntry, StopSequence> stopSequencesByTrip = new HashMap<BlockTripEntry, StopSequence>();
Map<StopSequence, String> stopSequenceGroupIds = new HashMap<StopSequence, String>();
for (Map.Entry<String, List<StopSequence>> entry : sequencesByGroupId.entrySet()) {
String id = entry.getKey();
for (StopSequence sequence : entry.getValue()) stopSequenceGroupIds.put(sequence, id);
}
for (StopSequence sequence : sequenceStats.keySet()) {
String groupId = stopSequenceGroupIds.get(sequence);
for (BlockTripEntry trip : sequence.getTrips()) {
BlockTripEntry prevTrip = trip.getPreviousTrip();
if (prevTrip == null)
continue;
StopSequence prevSequence = stopSequencesByTrip.get(prevTrip);
// No continuations if incoming is not part of the sequence collection
if (prevSequence == null)
continue;
// No continuation if it's the same stop sequence
if (prevSequence.equals(sequence))
continue;
// No contination if the the block group ids don't match
String prevGroupId = stopSequenceGroupIds.get(prevSequence);
if (!groupId.equals(prevGroupId))
continue;
StopEntry prevStop = prevSequence.getStops().get(prevSequence.getStops().size() - 1);
StopEntry nextStop = sequence.getStops().get(0);
double d = SphericalGeometryLibrary.distance(prevStop.getStopLat(), prevStop.getStopLon(), nextStop.getStopLat(), nextStop.getStopLon());
if (d < 5280 / 4) {
/*
* System.out.println("distance=" + d + " from=" + prevStop.getId() +
* " to=" + nextStop.getId() + " ssFrom=" + prevSequence.getId() +
* " ssTo=" + stopSequence.getId());
*/
PatternStats stats = sequenceStats.get(prevSequence);
stats.continuations.add(sequence);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopSequencesServiceImpl method getStopSequencesForTrips.
@Override
public List<StopSequence> getStopSequencesForTrips(List<BlockTripEntry> trips) {
Map<StopSequenceKey, List<BlockTripEntry>> tripsByStopSequenceKey = new FactoryMap<StopSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
for (BlockTripEntry blockTrip : trips) {
TripEntry trip = blockTrip.getTrip();
String directionId = trip.getDirectionId();
if (directionId == null)
directionId = NO_DIRECTION_ID;
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues())
shapeId = NO_SHAPE_ID;
List<StopEntry> stops = getStopTimesAsStops(trip.getStopTimes());
StopSequenceKey key = new StopSequenceKey(stops, directionId, shapeId);
tripsByStopSequenceKey.get(key).add(blockTrip);
}
List<StopSequence> sequences = new ArrayList<StopSequence>();
for (Map.Entry<StopSequenceKey, List<BlockTripEntry>> entry : tripsByStopSequenceKey.entrySet()) {
StopSequenceKey key = entry.getKey();
StopSequence ss = new StopSequence();
ss.setId(sequences.size());
ss.setRoute(null);
ss.setStops(key.getStops());
if (!key.getDirectionId().equals(NO_DIRECTION_ID))
ss.setDirectionId(key.getDirectionId());
if (!key.getShapeId().equals(NO_SHAPE_ID))
ss.setShapeId(key.getShapeId());
ss.setTrips(entry.getValue());
ss.setTripCount(entry.getValue().size());
sequences.add(ss);
}
return sequences;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class WhereGeospatialServiceImpl method initialize.
@PostConstruct
@Refreshable(dependsOn = RefreshableResources.STOP_GEOSPATIAL_INDEX)
public void initialize() {
List<StopEntry> stops = _transitGraphDao.getAllStops();
if (stops.size() == 0) {
_tree = null;
return;
}
_tree = new STRtree(stops.size());
for (StopEntry stop : stops) {
float x = (float) stop.getStopLon();
float y = (float) stop.getStopLat();
Envelope env = new Envelope(x, x, y, y);
_tree.insert(env, stop.getId());
}
_tree.build();
}
Aggregations