use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTask method generateStopNarratives.
public void generateStopNarratives(NarrativeProviderImpl provider) {
Map<AgencyAndId, List<ProjectedPoint>> shapePointCache = new HashMap<AgencyAndId, List<ProjectedPoint>>();
int index = 0;
Collection<Stop> allStops = _gtfsDao.getAllStops();
Map<AgencyAndId, Stop> stopsById = MappingLibrary.mapToValue(allStops, "id");
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allStops.size());
for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
if (index % logInterval == 0)
_log.info("stops=" + index);
index++;
Stop stop = stopsById.get(stopEntry.getId());
StopNarrative.Builder narrative = StopNarrative.builder();
narrative.setCode(deduplicate(stop.getCode()));
narrative.setDescription(deduplicate(stop.getDesc()));
narrative.setName(deduplicate(stop.getName()));
narrative.setUrl(deduplicate(stop.getUrl()));
String direction = computeStopDirection(provider, shapePointCache, stop, stopEntry);
narrative.setDirection(deduplicate(direction));
provider.setNarrativeForStop(stopEntry.getId(), narrative.create());
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GenerateStopSearchIndexTask method buildIndex.
private void buildIndex() throws IOException, ParseException {
IndexWriter writer = new IndexWriter(_bundle.getStopSearchIndexPath(), new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
StopNarrative narrative = _narrativeService.getStopForId(stopEntry.getId());
Document document = getStopAsDocument(stopEntry, narrative);
writer.addDocument(document);
}
writer.optimize();
writer.close();
_refreshService.refresh(RefreshableResources.STOP_SEARCH_DATA);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class ShapeGeospatialIndexTask method buildShapeSpatialIndex.
private Map<CoordinateBounds, List<AgencyAndId>> buildShapeSpatialIndex() {
Map<CoordinatePoint, Set<AgencyAndId>> shapeIdsByGridCellCorner = new FactoryMap<CoordinatePoint, Set<AgencyAndId>>(new HashSet<AgencyAndId>());
CoordinateBounds fullBounds = new CoordinateBounds();
for (StopEntry stop : _transitGraphDao.getAllStops()) {
if (stop.getStopLat() > MIN_LAT_LON && stop.getStopLon() > MIN_LAT_LON && stop.getStopLat() < MAX_LAT_LON && stop.getStopLon() < MAX_LAT_LON) {
fullBounds.addPoint(stop.getStopLat(), stop.getStopLon());
} else {
_log.error("rejecting stop " + stop + " for invalid (lat,lon)=" + stop.getStopLat() + ", " + stop.getStopLon());
}
}
if (fullBounds.isEmpty()) {
return Collections.emptyMap();
}
double centerLat = (fullBounds.getMinLat() + fullBounds.getMaxLat()) / 2;
double centerLon = (fullBounds.getMinLon() + fullBounds.getMaxLon()) / 2;
CoordinateBounds gridCellExample = SphericalGeometryLibrary.bounds(centerLat, centerLon, _gridSize / 2);
double latStep = gridCellExample.getMaxLat() - gridCellExample.getMinLat();
double lonStep = gridCellExample.getMaxLon() - gridCellExample.getMinLon();
_log.info("generating shape point geospatial index...");
Set<AgencyAndId> allShapeIds = getAllShapeIds();
for (AgencyAndId shapeId : allShapeIds) {
ShapePoints shapePoints = _shapePointHelper.getShapePointsForShapeId(shapeId);
for (int i = 0; i < shapePoints.getSize(); i++) {
double lat = shapePoints.getLatForIndex(i);
double lon = shapePoints.getLonForIndex(i);
addGridCellForShapePoint(shapeIdsByGridCellCorner, lat, lon, latStep, lonStep, shapeId);
/**
* If there is a particularly long stretch between shape points, we want
* to fill in grid cells in-between
*/
if (i > 0) {
double prevLat = shapePoints.getLatForIndex(i - 1);
double prevLon = shapePoints.getLonForIndex(i - 1);
double totalDistance = SphericalGeometryLibrary.distance(prevLat, prevLon, lat, lon);
for (double d = _gridSize; d < totalDistance; d += _gridSize) {
double r = d / totalDistance;
double latPart = (lat - prevLat) * r + prevLat;
double lonPart = (lon - prevLon) * r + prevLon;
addGridCellForShapePoint(shapeIdsByGridCellCorner, latPart, lonPart, latStep, lonStep, shapeId);
}
}
}
}
_log.info("block shape geospatial nodes: " + shapeIdsByGridCellCorner.size());
Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByGridCell = new HashMap<CoordinateBounds, List<AgencyAndId>>();
for (Map.Entry<CoordinatePoint, Set<AgencyAndId>> entry : shapeIdsByGridCellCorner.entrySet()) {
CoordinatePoint p = entry.getKey();
CoordinateBounds bounds = new CoordinateBounds(p.getLat(), p.getLon(), p.getLat() + latStep, p.getLon() + lonStep);
List<AgencyAndId> shapeIds = new ArrayList<AgencyAndId>(entry.getValue());
shapeIdsByGridCell.put(bounds, shapeIds);
}
return shapeIdsByGridCell;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class UserReportingServiceImpl method getRecordAsBean.
private TripProblemReportBean getRecordAsBean(TripProblemReportRecord record) {
AgencyAndId stopId = record.getStopId();
AgencyAndId tripId = record.getTripId();
TripProblemReportBean bean = new TripProblemReportBean();
bean.setCode(record.getCode());
bean.setId(record.getId());
bean.setServiceDate(record.getServiceDate());
bean.setStatus(record.getStatus());
bean.setLabel(record.getLabel());
bean.setStopId(AgencyAndIdLibrary.convertToString(stopId));
bean.setTime(record.getTime());
bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
bean.setUserComment(record.getUserComment());
bean.setUserLat(record.getUserLat());
bean.setUserLon(record.getUserLon());
bean.setUserLocationAccuracy(record.getUserLocationAccuracy());
bean.setUserOnVehicle(record.isUserOnVehicle());
bean.setUserVehicleNumber(record.getUserVehicleNumber());
bean.setPredicted(record.isPredicted());
bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
bean.setScheduleDeviation(record.getScheduleDeviation());
bean.setVehicleLat(record.getVehicleLat());
bean.setVehicleLon(record.getVehicleLon());
if (stopId != null) {
try {
bean.setStop(_stopBeanService.getStopForId(stopId));
} catch (NoSuchStopServiceException ex) {
}
}
if (tripId != null) {
bean.setTrip(_tripBeanService.getTripForId(tripId));
}
if (tripId != null && stopId != null) {
TripEntry trip = _graph.getTripEntryForId(tripId);
StopEntry stop = _graph.getStopEntryForId(stopId);
if (trip != null && stop != null) {
AgencyAndId vehicleId = record.getMatchedVehicleId();
if (vehicleId == null)
vehicleId = record.getVehicleId();
ArrivalAndDepartureQuery query = new ArrivalAndDepartureQuery();
query.setStop(stop);
query.setStopSequence(-1);
query.setTrip(trip);
query.setServiceDate(record.getServiceDate());
query.setVehicleId(vehicleId);
query.setTime(record.getTime());
ArrivalAndDepartureInstance instance = _arrivalAndDepartureService.getArrivalAndDepartureForStop(query);
if (instance != null) {
StopTimeInstance sti = instance.getStopTimeInstance();
StopTimeInstanceBean stopTimeBean = _stopTimeBeanService.getStopTimeInstanceAsBean(sti);
bean.setStopTime(stopTimeBean);
}
}
}
return bean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class WhereGeospatialServiceImplTest method test.
@Test
public void test() {
WhereGeospatialServiceImpl service = new WhereGeospatialServiceImpl();
TransitGraphDao dao = Mockito.mock(TransitGraphDao.class);
service.setTransitGraphDao(dao);
StopEntry stopA = stop("a", -0.5, -0.5);
StopEntry stopB = stop("b", -0.5, 0.5);
StopEntry stopC = stop("c", 0.5, -0.5);
StopEntry stopD = stop("d", 0.5, 0.5);
List<StopEntry> allStops = Arrays.asList(stopA, stopB, stopC, stopD);
Mockito.when(dao.getAllStops()).thenReturn(allStops);
service.initialize();
List<AgencyAndId> stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 0, 0));
assertEquals(1, stops.size());
assertTrue(stops.contains(stopA.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(0, -1, 1, 0));
assertEquals(1, stops.size());
assertTrue(stops.contains(stopC.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 0));
assertEquals(2, stops.size());
assertTrue(stops.contains(stopA.getId()));
assertTrue(stops.contains(stopC.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(-1, -1, 1, 1));
assertEquals(4, stops.size());
assertTrue(stops.contains(stopA.getId()));
assertTrue(stops.contains(stopB.getId()));
assertTrue(stops.contains(stopC.getId()));
assertTrue(stops.contains(stopD.getId()));
stops = service.getStopsByBounds(new CoordinateBounds(0.8, 0.8, 1, 1));
assertEquals(0, stops.size());
}
Aggregations