use of uk.org.siri.siri_2.DirectionRefStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method fillAnnotatedStopPointStructure.
public static boolean fillAnnotatedStopPointStructure(AnnotatedStopPointStructure annotatedStopPoint, StopRouteDirection stopRouteDirection, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
StopBean stopBean = stopRouteDirection.getStop();
List<RouteForDirection> routeDirections = stopRouteDirection.getRouteDirections();
// Set Stop Name
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stopBean.getName());
// Set Route and Direction
Lines lines = new Lines();
for (RouteForDirection routeDirection : routeDirections) {
String directionId = routeDirection.getDirectionId();
String routeId = routeDirection.getRouteId();
LineRefStructure line = new LineRefStructure();
line.setValue(routeId);
DirectionRefStructure direction = new DirectionRefStructure();
direction.setValue(directionId);
LineDirectionStructure lineDirection = new LineDirectionStructure();
lineDirection.setDirectionRef(direction);
lineDirection.setLineRef(line);
lines.getLineRefOrLineDirection().add(lineDirection);
}
// Set Lat and Lon
BigDecimal stopLat = new BigDecimal(stopBean.getLat());
BigDecimal stopLon = new BigDecimal(stopBean.getLon());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
// Set StopId
StopPointRefStructure stopPointRef = new StopPointRefStructure();
stopPointRef.setValue(stopBean.getId());
// Details -- minimum
annotatedStopPoint.getStopName().add(stopName);
// Details -- normal
if (detailLevel.equals(DetailLevel.NORMAL) || detailLevel.equals(DetailLevel.FULL)) {
annotatedStopPoint.setLocation(location);
annotatedStopPoint.setLines(lines);
annotatedStopPoint.setMonitored(true);
}
annotatedStopPoint.setStopPointRef(stopPointRef);
return true;
}
use of uk.org.siri.siri_2.DirectionRefStructure in project onebusaway-application-modules by camsys.
the class SiriSupportV2 method fillAnnotatedLineStructure.
public static boolean fillAnnotatedLineStructure(AnnotatedLineStructure annotatedLineStructure, RouteResult routeResult, Map<Filters, String> filters, DetailLevel detailLevel, long currentTime) {
Directions directions = new Directions();
// Set Line Value
LineRefStructure line = new LineRefStructure();
line.setValue(routeResult.getId());
NaturalLanguageStringStructure lineName = new NaturalLanguageStringStructure();
lineName.setValue(routeResult.getShortName());
// DETAIL - minimum: Return only the name and identifier of stops
// ideally, this would return only stops with scheduled service
annotatedLineStructure.setLineRef(line);
annotatedLineStructure.getLineName().add(lineName);
annotatedLineStructure.setDirections(directions);
annotatedLineStructure.setMonitored(true);
// Loop through Direction Ids
for (RouteDirection direction : routeResult.getDirections()) {
// Check for existing stops in direction
if (direction == null | direction.getStops().size() == 0)
continue;
String directionId = direction.getDirectionId();
// Journey patterns - holds stop points for direction
JourneyPattern pattern = new JourneyPattern();
JourneyPatterns patterns = new JourneyPatterns();
// Directions
DirectionRefStructure dirRefStructure = new DirectionRefStructure();
dirRefStructure.setValue(directionId);
RouteDirectionStructure routeDirectionStructure = new RouteDirectionStructure();
NaturalLanguageStringStructure directionName = new NaturalLanguageStringStructure();
directionName.setValue(direction.getDestination());
routeDirectionStructure.getDirectionName().add(directionName);
directions.getDirection().add(routeDirectionStructure);
// Destination
Destinations destinations = new Destinations();
AnnotatedDestinationStructure annotatedDest = new AnnotatedDestinationStructure();
DestinationRefStructure destRef = new DestinationRefStructure();
destRef.setValue(direction.getDestination());
annotatedDest.setDestinationRef(destRef);
destinations.getDestination().add(annotatedDest);
// Stops
StopsInPattern stopsInPattern = new StopsInPattern();
List<StopOnRoute> scheduledStops = new ArrayList<StopOnRoute>();
List<StopOnRoute> allStops = new ArrayList<StopOnRoute>();
// Categorize by Scheduled and Unscheduled Stops
for (StopOnRoute stop : direction.getStops()) {
if (stop.getHasUpcomingScheduledStop() != null && stop.getHasUpcomingScheduledStop())
scheduledStops.add(stop);
allStops.add(stop);
}
if (detailLevel.equals(DetailLevel.NORMAL)) {
for (int i = 0; i < scheduledStops.size(); i++) {
StopOnRoute stop = direction.getStops().get(i);
BigDecimal stopLat = new BigDecimal(stop.getLatitude());
BigDecimal stopLon = new BigDecimal(stop.getLongitude());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
pointInPattern.setLocation(location);
pointInPattern.setOrder(BigInteger.valueOf(i));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stop.getName());
pointInPattern.getStopName().add(stopName);
StopPointRefStructure spr = new StopPointRefStructure();
spr.setValue(stop.getId());
stopsInPattern.getStopPointInPattern().add(pointInPattern);
}
}
if (detailLevel.equals(DetailLevel.STOPS) || detailLevel.equals(DetailLevel.FULL)) {
for (int i = 0; i < allStops.size(); i++) {
StopOnRoute stop = direction.getStops().get(i);
Boolean hasUpcomingScheduledService = stop.getHasUpcomingScheduledStop();
BigDecimal stopLat = new BigDecimal(stop.getLatitude());
BigDecimal stopLon = new BigDecimal(stop.getLongitude());
LocationStructure location = new LocationStructure();
location.setLongitude(stopLon.setScale(6, BigDecimal.ROUND_HALF_DOWN));
location.setLatitude(stopLat.setScale(6, BigDecimal.ROUND_HALF_DOWN));
StopPointRefStructure spr = new StopPointRefStructure();
spr.setValue(stop.getId());
StopPointInPatternStructure pointInPattern = new StopPointInPatternStructure();
pointInPattern.setLocation(location);
pointInPattern.setOrder(BigInteger.valueOf(i));
NaturalLanguageStringStructure stopName = new NaturalLanguageStringStructure();
stopName.setValue(stop.getName());
pointInPattern.getStopName().add(stopName);
pointInPattern.setStopPointRef(spr);
stopsInPattern.getStopPointInPattern().add(pointInPattern);
// HasUpcomingService Extension
SiriUpcomingServiceExtension upcomingService = new SiriUpcomingServiceExtension();
upcomingService.setUpcomingScheduledService(hasUpcomingScheduledService);
ExtensionsStructure upcomingServiceExtensions = new ExtensionsStructure();
upcomingServiceExtensions.setAny(upcomingService);
pointInPattern.setExtensions(upcomingServiceExtensions);
}
}
String includePolylineFilter = filters.get(Filters.INCLUDE_POLYLINES);
if (includePolylineFilter != null && passFilter("true", includePolylineFilter)) {
// Polyline Extension
SiriPolyLinesExtension polylines = new SiriPolyLinesExtension();
for (String polyline : direction.getPolylines()) {
polylines.getPolylines().add(polyline);
}
ExtensionsStructure PolylineExtension = new ExtensionsStructure();
PolylineExtension.setAny(polylines);
routeDirectionStructure.setExtensions(PolylineExtension);
}
routeDirectionStructure.setJourneyPatterns(patterns);
pattern.setStopsInPattern(stopsInPattern);
patterns.getJourneyPattern().add(pattern);
routeDirectionStructure.setDirectionRef(dirRefStructure);
}
return true;
}
Aggregations