Search in sources :

Example 1 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class RouteConfigAction method getModel.

@Override
public Body<Route> getModel() {
    Body<Route> body = new Body<Route>();
    if (isValid(body)) {
        List<String> agencyIds = processAgencyIds(agencyId);
        List<AgencyAndId> routeIds = new ArrayList<AgencyAndId>();
        List<RouteBean> routeBeans = new ArrayList<RouteBean>();
        int routes_count = 1;
        if (processRouteIds(routeId, routeIds, agencyIds, body)) {
            for (AgencyAndId routeId : routeIds) {
                routeBeans.add(_transitDataService.getRouteForId(routeId.toString()));
            }
        } else if (routeId == null) {
            routeBeans = _transitDataService.getRoutesForAgencyId(agencyId).getList();
        }
        Collections.sort(routeBeans, new Comparator<RouteBean>() {

            AlphanumComparator alphaComparator = new AlphanumComparator();

            public int compare(RouteBean arg0, RouteBean arg1) {
                return alphaComparator.compare(arg0.getId(), arg1.getId());
            }
        });
        for (RouteBean routeBean : routeBeans) {
            // Limit Number of Routes Returned
            if (routes_count > MAX_ROUTES)
                break;
            Route route = new Route();
            route.setTag(getIdNoAgency(routeBean.getId()));
            route.setTitle(route.getTag() + " " + routeBean.getLongName());
            route.setShortTitle(routeBean.getShortName());
            route.setColor(routeBean.getColor());
            route.setOppositeColor(routeBean.getTextColor());
            StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
            // Stops
            for (StopBean stopBean : stopsForRoute.getStops()) {
                Stop stop = new Stop();
                stop.setTag(getIdNoAgency(stopBean.getId()));
                stop.setTitle(stopBean.getName());
                stop.setLat(stopBean.getLat());
                stop.setLon(stopBean.getLon());
                stop.setStopId(stopBean.getCode());
                route.getStops().add(stop);
            }
            // Directions
            for (StopGroupingBean stopGroupingBean : stopsForRoute.getStopGroupings()) {
                for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
                    Direction direction = new Direction();
                    direction.setTag(stopGroupBean.getId());
                    direction.setTitle(stopGroupBean.getName().getName());
                    for (String stopId : stopGroupBean.getStopIds()) {
                        direction.getStops().add(new DisplayStop(getIdNoAgency(stopId)));
                    }
                    route.getDirections().add(direction);
                }
            }
            // PolyLines
            for (EncodedPolylineBean polyline : stopsForRoute.getPolylines()) {
                Path path = new Path();
                List<CoordinatePoint> coordinatePoints = PolylineEncoder.decode(polyline);
                for (CoordinatePoint coordinatePoint : coordinatePoints) {
                    path.getPoints().add(new Point(coordinatePoint.getLat(), coordinatePoint.getLon()));
                }
                route.getPaths().add(path);
            }
            body.getResponse().add(route);
            routes_count++;
        }
    }
    return body;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) Stop(org.onebusaway.nextbus.model.nextbus.Stop) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) Direction(org.onebusaway.nextbus.model.nextbus.Direction) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) DisplayStop(org.onebusaway.nextbus.model.nextbus.DisplayStop) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) Body(org.onebusaway.nextbus.model.nextbus.Body) Route(org.onebusaway.nextbus.model.nextbus.Route) DisplayRoute(org.onebusaway.nextbus.model.nextbus.DisplayRoute) Path(org.onebusaway.nextbus.model.nextbus.Path) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) Point(org.onebusaway.nextbus.model.nextbus.Point) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) AlphanumComparator(org.onebusaway.util.comparators.AlphanumComparator) StopBean(org.onebusaway.transit_data.model.StopBean)

Example 2 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class ShapeBeanServiceImpl method getMergedPolylinesForShapeIds.

@Cacheable
public List<EncodedPolylineBean> getMergedPolylinesForShapeIds(Collection<AgencyAndId> shapeIds) {
    List<EncodedPolylineBean> polylines = new ArrayList<EncodedPolylineBean>();
    if (shapeIds.isEmpty())
        return polylines;
    List<CoordinatePoint> currentLine = new ArrayList<CoordinatePoint>();
    Set<Edge> edges = new HashSet<Edge>();
    for (AgencyAndId shapeId : shapeIds) {
        ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
        if (shapePoints == null) {
            _log.warn("no shape points for shapeId=" + shapeId);
            continue;
        }
        double[] lats = shapePoints.getLats();
        double[] lons = shapePoints.getLons();
        CoordinatePoint prev = null;
        for (int i = 0; i < shapePoints.getSize(); i++) {
            CoordinatePoint loc = new CoordinatePoint(lats[i], lons[i]);
            if (prev != null && !prev.equals(loc)) {
                Edge edge = new Edge(prev, loc);
                if (!edges.add(edge)) {
                    if (currentLine.size() > 1)
                        polylines.add(PolylineEncoder.createEncodings(currentLine));
                    currentLine.clear();
                }
            }
            if (prev == null || !prev.equals(loc))
                currentLine.add(loc);
            prev = loc;
        }
        if (currentLine.size() > 1)
            polylines.add(PolylineEncoder.createEncodings(currentLine));
        currentLine.clear();
    }
    return polylines;
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 3 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class RealtimeServiceV2Impl method getRouteResult.

private RouteResult getRouteResult(RouteBean routeBean, Map<Filters, String> filters) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    // Filter Values
    String directionIdFilter = filters.get(Filters.DIRECTION_REF);
    String upcomingScheduledServiceFilter = filters.get(Filters.UPCOMING_SCHEDULED_SERVICE);
    // create stop ID->stop bean map
    Map<String, StopBean> stopIdToStopBeanMap = new HashMap<String, StopBean>();
    for (StopBean stopBean : stopsForRoute.getStops()) {
        stopIdToStopBeanMap.put(stopBean.getId(), stopBean);
    }
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            String directionId = stopGroupBean.getId();
            // Destination and DirectionId Filter
            if (!type.equals("destination") || !SiriSupportV2.passFilter(directionId, directionIdFilter))
                continue;
            List<String> polylines = new ArrayList<String>();
            for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                polylines.add(polyline.getPoints());
            }
            // TODO - Re-evaluate the best method to determine upcoming scheduled service
            Boolean routeHasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), directionId);
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = getVehiclesInServiceForRoute(routeBean.getId(), directionId, SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                routeHasUpcomingScheduledService = true;
            }
            String hasUpcomingScheduledServiceVal = String.valueOf(routeHasUpcomingScheduledService);
            // String hasUpcomingScheduledServiceVal = String.valueOf(routeHasVehiclesInService);
            if (!SiriSupportV2.passFilter(hasUpcomingScheduledServiceVal, upcomingScheduledServiceFilter) || routeHasUpcomingScheduledService == null || !routeHasUpcomingScheduledService)
                continue;
            // stops in this direction
            List<StopOnRoute> stopsOnRoute = null;
            if (!stopGroupBean.getStopIds().isEmpty()) {
                stopsOnRoute = new ArrayList<StopOnRoute>();
                for (String stopId : stopGroupBean.getStopIds()) {
                    // service in this direction
                    StopBean stopBean = stopIdToStopBeanMap.get(stopId);
                    Boolean stopHasUpcomingScheduledService = _transitDataService.stopHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), stopBean.getId(), routeBean.getId(), stopGroupBean.getId());
                    stopsOnRoute.add(new StopOnRoute(stopBean, stopHasUpcomingScheduledService));
                }
            }
            directions.add(new RouteDirection(stopGroupBean, polylines, stopsOnRoute, routeHasUpcomingScheduledService));
        }
    }
    return new RouteResult(routeBean, directions);
}
Also used : RouteDirection(org.onebusaway.api.actions.siri.model.RouteDirection) StopRouteDirection(org.onebusaway.api.actions.siri.model.StopRouteDirection) HashMap(java.util.HashMap) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) RouteResult(org.onebusaway.api.actions.siri.model.RouteResult) StopBean(org.onebusaway.transit_data.model.StopBean) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean) StopOnRoute(org.onebusaway.api.actions.siri.model.StopOnRoute)

Example 4 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class SearchResultFactoryImpl method getRouteResult.

@Override
public SearchResult getRouteResult(RouteBean routeBean) {
    List<RouteDirection> directions = new ArrayList<RouteDirection>();
    StopsForRouteBean stopsForRoute = _transitDataService.getStopsForRoute(routeBean.getId());
    List<StopGroupingBean> stopGroupings = stopsForRoute.getStopGroupings();
    for (StopGroupingBean stopGroupingBean : stopGroupings) {
        for (StopGroupBean stopGroupBean : stopGroupingBean.getStopGroups()) {
            NameBean name = stopGroupBean.getName();
            String type = name.getType();
            if (!type.equals("destination"))
                continue;
            List<String> polylines = new ArrayList<String>();
            for (EncodedPolylineBean polyline : stopGroupBean.getPolylines()) {
                polylines.add(polyline.getPoints());
            }
            Boolean hasUpcomingScheduledService = _transitDataService.routeHasUpcomingScheduledService((routeBean.getAgency() != null ? routeBean.getAgency().getId() : null), SystemTime.currentTimeMillis(), routeBean.getId(), stopGroupBean.getId());
            // if there are buses on route, always have "scheduled service"
            Boolean routeHasVehiclesInService = _realtimeService.getVehiclesInServiceForRoute(routeBean.getId(), stopGroupBean.getId(), SystemTime.currentTimeMillis());
            if (routeHasVehiclesInService) {
                hasUpcomingScheduledService = true;
            }
            directions.add(new RouteDirection(stopGroupBean, polylines, null, hasUpcomingScheduledService));
        }
    }
    return new RouteResult(routeBean, directions);
}
Also used : RouteDirection(org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection) StopGroupBean(org.onebusaway.transit_data.model.StopGroupBean) ArrayList(java.util.ArrayList) StopsForRouteBean(org.onebusaway.transit_data.model.StopsForRouteBean) StopGroupingBean(org.onebusaway.transit_data.model.StopGroupingBean) RouteResult(org.onebusaway.enterprise.webapp.actions.api.model.RouteResult) NameBean(org.onebusaway.transit_data.model.NameBean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean)

Example 5 with EncodedPolylineBean

use of org.onebusaway.geospatial.model.EncodedPolylineBean in project onebusaway-application-modules by camsys.

the class BeanFactoryV2 method getSituationConsequence.

private SituationConsequenceV2Bean getSituationConsequence(SituationConsequenceBean consequence) {
    SituationConsequenceV2Bean bean = new SituationConsequenceV2Bean();
    if (consequence.getEffect() != null)
        bean.setCondition(consequence.getEffect().toString().toLowerCase());
    if (_includeConditionDetails && (consequence.getDetourPath() != null || !CollectionsLibrary.isEmpty(consequence.getDetourStopIds()))) {
        SituationConditionDetailsV2Bean detailsBean = new SituationConditionDetailsV2Bean();
        if (consequence.getDetourPath() != null) {
            EncodedPolylineBean poly = new EncodedPolylineBean();
            poly.setPoints(consequence.getDetourPath());
            detailsBean.setDiversionPath(poly);
        }
        detailsBean.setDiversionStopIds(consequence.getDetourStopIds());
        bean.setConditionDetails(detailsBean);
    }
    return bean;
}
Also used : SituationConditionDetailsV2Bean(org.onebusaway.api.model.transit.service_alerts.SituationConditionDetailsV2Bean) SituationConsequenceV2Bean(org.onebusaway.api.model.transit.service_alerts.SituationConsequenceV2Bean) EncodedPolylineBean(org.onebusaway.geospatial.model.EncodedPolylineBean)

Aggregations

EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)15 ArrayList (java.util.ArrayList)9 StopGroupBean (org.onebusaway.transit_data.model.StopGroupBean)7 StopGroupingBean (org.onebusaway.transit_data.model.StopGroupingBean)7 StopsForRouteBean (org.onebusaway.transit_data.model.StopsForRouteBean)7 NameBean (org.onebusaway.transit_data.model.NameBean)6 Test (org.junit.Test)5 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 StopBean (org.onebusaway.transit_data.model.StopBean)3 HashSet (java.util.HashSet)2 RouteDirection (org.onebusaway.enterprise.webapp.actions.api.model.RouteDirection)2 RouteBean (org.onebusaway.transit_data.model.RouteBean)2 BlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex)2 HashMap (java.util.HashMap)1 RouteDirection (org.onebusaway.api.actions.siri.model.RouteDirection)1 RouteResult (org.onebusaway.api.actions.siri.model.RouteResult)1 StopOnRoute (org.onebusaway.api.actions.siri.model.StopOnRoute)1 StopRouteDirection (org.onebusaway.api.actions.siri.model.StopRouteDirection)1 BeanFactoryV2 (org.onebusaway.api.model.transit.BeanFactoryV2)1