Search in sources :

Example 1 with CoordinatePoint

use of org.onebusaway.geospatial.model.CoordinatePoint 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 CoordinatePoint

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

the class VehicleStatusBeanServiceImpl method getVehicleLocationRecordAsBean.

private VehicleLocationRecordBean getVehicleLocationRecordAsBean(VehicleLocationRecord record) {
    VehicleLocationRecordBean bean = new VehicleLocationRecordBean();
    bean.setBlockId(AgencyAndIdLibrary.convertToString(record.getBlockId()));
    if (record.getPhase() != null)
        bean.setPhase(record.getPhase().toLabel());
    if (record.isCurrentLocationSet()) {
        CoordinatePoint location = new CoordinatePoint(record.getCurrentLocationLat(), record.getCurrentLocationLon());
        bean.setCurrentLocation(location);
    }
    if (record.isCurrentOrientationSet())
        bean.setCurrentOrientation(record.getCurrentOrientation());
    if (record.isDistanceAlongBlockSet())
        bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
    if (record.isScheduleDeviationSet())
        bean.setScheduleDeviation(record.getScheduleDeviation());
    bean.setStatus(record.getStatus());
    bean.setServiceDate(record.getServiceDate());
    bean.setTimeOfRecord(record.getTimeOfRecord());
    bean.setTripId(AgencyAndIdLibrary.convertToString(record.getTripId()));
    bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
    return bean;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehicleLocationRecordBean(org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)

Example 3 with CoordinatePoint

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

the class VehicleStatusBeanServiceImpl method getBlockLocationAsVehicleLocationRecord.

private VehicleLocationRecordBean getBlockLocationAsVehicleLocationRecord(BlockLocation record) {
    VehicleLocationRecordBean bean = new VehicleLocationRecordBean();
    bean.setBlockId(AgencyAndIdLibrary.convertToString(record.getBlockInstance().getBlock().getBlock().getId()));
    if (record.getPhase() != null)
        bean.setPhase(record.getPhase().toLabel());
    CoordinatePoint location = record.getLocation();
    if (location != null)
        bean.setCurrentLocation(location);
    if (record.isOrientationSet())
        bean.setCurrentOrientation(record.getOrientation());
    if (record.isDistanceAlongBlockSet())
        bean.setDistanceAlongBlock(record.getDistanceAlongBlock());
    if (record.isScheduleDeviationSet())
        bean.setScheduleDeviation(record.getScheduleDeviation());
    bean.setStatus(record.getStatus());
    bean.setServiceDate(record.getBlockInstance().getServiceDate());
    bean.setTimeOfRecord(record.getLastUpdateTime());
    bean.setTimeOfLocationUpdate(record.getLastLocationUpdateTime());
    bean.setTripId(AgencyAndIdLibrary.convertToString(record.getActiveTrip().getTrip().getId()));
    bean.setVehicleId(AgencyAndIdLibrary.convertToString(record.getVehicleId()));
    return bean;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehicleLocationRecordBean(org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)

Example 4 with CoordinatePoint

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

the class BlockGeospatialServiceImpl method getBestScheduledBlockLocationForLocation.

public ScheduledBlockLocation getBestScheduledBlockLocationForLocation(BlockInstance blockInstance, CoordinatePoint location, long timestamp, double blockDistanceFrom, double blockDistanceTo) {
    BlockConfigurationEntry block = blockInstance.getBlock();
    ProjectedPoint targetPoint = ProjectedPointFactory.forward(location);
    List<AgencyAndId> shapePointIds = MappingLibrary.map(block.getTrips(), "trip.shapeId");
    T2<List<XYPoint>, double[]> tuple = _projectedShapePointService.getProjectedShapePoints(shapePointIds, targetPoint.getSrid());
    if (tuple == null) {
        throw new IllegalStateException("block had no shape points: " + block.getBlock().getId());
    }
    List<XYPoint> projectedShapePoints = tuple.getFirst();
    double[] distances = tuple.getSecond();
    int fromIndex = 0;
    int toIndex = distances.length;
    if (blockDistanceFrom > 0) {
        fromIndex = Arrays.binarySearch(distances, blockDistanceFrom);
        if (fromIndex < 0) {
            fromIndex = -(fromIndex + 1);
            // Include the previous point if we didn't get an exact match
            if (fromIndex > 0)
                fromIndex--;
        }
    }
    if (blockDistanceTo < distances[distances.length - 1]) {
        toIndex = Arrays.binarySearch(distances, blockDistanceTo);
        if (toIndex < 0) {
            toIndex = -(toIndex + 1);
            // Include the previous point if we didn't get an exact match
            if (toIndex < distances.length)
                toIndex++;
        }
    }
    XYPoint xyPoint = new XYPoint(targetPoint.getX(), targetPoint.getY());
    List<PointAndIndex> assignments = _shapePointsLibrary.computePotentialAssignments(projectedShapePoints, distances, xyPoint, fromIndex, toIndex);
    Min<ScheduledBlockLocation> best = new Min<ScheduledBlockLocation>();
    for (PointAndIndex index : assignments) {
        double distanceAlongBlock = index.distanceAlongShape;
        if (distanceAlongBlock > block.getTotalBlockDistance())
            distanceAlongBlock = block.getTotalBlockDistance();
        ScheduledBlockLocation blockLocation = _scheduledBlockLocationService.getScheduledBlockLocationFromDistanceAlongBlock(block, distanceAlongBlock);
        if (blockLocation != null) {
            int scheduledTime = blockLocation.getScheduledTime();
            long scheduleTimestamp = blockInstance.getServiceDate() + scheduledTime * 1000;
            double delta = Math.abs(scheduleTimestamp - timestamp);
            best.add(delta, blockLocation);
        }
    }
    return best.getMinElement();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Min(org.onebusaway.collections.Min) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) List(java.util.List) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 5 with CoordinatePoint

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

the class GtfsRealtimeTripLibrary method applyVehiclePositionToRecord.

private void applyVehiclePositionToRecord(MonitoredResult result, BlockDescriptor blockDescriptor, VehiclePosition vehiclePosition, VehicleLocationRecord record) {
    Position position = vehiclePosition.getPosition();
    if (vehiclePosition.hasTimestamp()) {
        // vehicle timestamp is in seconds
        record.setTimeOfLocationUpdate(TimeUnit.SECONDS.toMillis(vehiclePosition.getTimestamp()));
    }
    record.setCurrentLocationLat(position.getLatitude());
    record.setCurrentLocationLon(position.getLongitude());
    if (result != null) {
        result.addLatLon(position.getLatitude(), position.getLongitude());
    }
    if (_scheduleAdherenceFromLocation) {
        CoordinatePoint location = new CoordinatePoint(position.getLatitude(), position.getLongitude());
        double totalDistance = blockDescriptor.getBlockInstance().getBlock().getTotalBlockDistance();
        long timestamp = vehiclePosition.hasTimestamp() ? record.getTimeOfLocationUpdate() : record.getTimeOfRecord();
        ScheduledBlockLocation loc = _blockGeospatialService.getBestScheduledBlockLocationForLocation(blockDescriptor.getBlockInstance(), location, timestamp, 0, totalDistance);
        long serviceDateTime = record.getServiceDate();
        long effectiveScheduleTime = loc.getScheduledTime() + (serviceDateTime / 1000);
        double deviation = timestamp / 1000 - effectiveScheduleTime;
        record.setScheduleDeviation(deviation);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) Position(com.google.transit.realtime.GtfsRealtime.Position)

Aggregations

CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)57 ArrayList (java.util.ArrayList)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)12 Test (org.junit.Test)10 XYPoint (org.onebusaway.geospatial.model.XYPoint)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)9 CoordinateBounds (org.onebusaway.geospatial.model.CoordinateBounds)7 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)6 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)6 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)5 EncodedPolylineBean (org.onebusaway.geospatial.model.EncodedPolylineBean)4 VehicleLocationRecordBean (org.onebusaway.transit_data.model.realtime.VehicleLocationRecordBean)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)3 List (java.util.List)3 Min (org.onebusaway.collections.Min)3 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)3 Record (org.onebusaway.transit_data.model.realtime.CurrentVehicleEstimateQueryBean.Record)3