Search in sources :

Example 1 with Position

use of com.google.transit.realtime.GtfsRealtime.Position in project onebusaway-application-modules by camsys.

the class VehiclePositionConvertor method readFeedEntity.

@Override
public VehiclePositionModel readFeedEntity(FeedEntity entity, long timestamp) {
    if (entity == null)
        return null;
    VehiclePositionModel vpm = new VehiclePositionModel();
    if (entity.hasVehicle()) {
        if (entity.getVehicle().hasTimestamp()) {
            timestamp = entity.getVehicle().getTimestamp() * 1000;
        }
        if (entity.getVehicle().hasTrip()) {
            TripDescriptor td = entity.getVehicle().getTrip();
            if (td.hasTripId()) {
                vpm.setTripId(td.getTripId());
            }
            if (td.hasRouteId()) {
                vpm.setRouteId(td.getRouteId());
            }
            if (td.hasStartDate() && td.hasStartTime()) {
                vpm.setTripStart(GtfsRealtimeConversionLibrary.parseDate(td.getStartDate(), td.getStartTime()));
            }
        }
        if (entity.getVehicle().hasVehicle()) {
            VehicleDescriptor vd = entity.getVehicle().getVehicle();
            if (vd.hasId()) {
                vpm.setVehicleId(vd.getId());
            }
            if (vd.hasLabel()) {
                vpm.setVehicleLabel(vd.getLabel());
            }
            if (vd.hasLicensePlate()) {
                vpm.setVehicleLicensePlate(vd.getLicensePlate());
            }
        }
        if (entity.getVehicle().hasPosition()) {
            Position p = entity.getVehicle().getPosition();
            vpm.setLat(p.getLatitude());
            vpm.setLon(p.getLongitude());
            if (p.hasBearing()) {
                vpm.setBearing(p.getBearing());
            }
            if (p.hasSpeed()) {
                vpm.setSpeed(p.getSpeed());
            }
        }
        if (entity.getVehicle().hasTrip()) {
            if (vpm.getTripId() == null) {
                if (entity.getVehicle().getTrip().hasTripId()) {
                    vpm.setTripId(entity.getVehicle().getTrip().getTripId());
                }
            }
            if (vpm.getRouteId() == null) {
                if (entity.getVehicle().getTrip().hasRouteId()) {
                    vpm.setRouteId(entity.getVehicle().getTrip().getRouteId());
                }
            }
        }
    }
    if (entity.getVehicle().hasStopId()) {
        vpm.setStopId(entity.getVehicle().getStopId());
    }
    vpm.setTimestamp(new Date(timestamp));
    return vpm;
}
Also used : TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) Position(com.google.transit.realtime.GtfsRealtime.Position) VehiclePositionModel(org.onebusaway.gtfs_realtime.model.VehiclePositionModel) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor) Date(java.util.Date)

Example 2 with Position

use of com.google.transit.realtime.GtfsRealtime.Position 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)

Example 3 with Position

use of com.google.transit.realtime.GtfsRealtime.Position in project onebusaway-application-modules by camsys.

the class VehiclePositionsForAgencyAction method fillFeedMessage.

@Override
protected void fillFeedMessage(FeedMessage.Builder feed, String agencyId, long timestamp) {
    ListBean<VehicleStatusBean> vehicles = _service.getAllVehiclesForAgency(agencyId, timestamp);
    for (VehicleStatusBean vehicle : vehicles.getList()) {
        FeedEntity.Builder entity = feed.addEntityBuilder();
        entity.setId(Integer.toString(feed.getEntityCount()));
        VehiclePosition.Builder vehiclePosition = entity.getVehicleBuilder();
        TripStatusBean tripStatus = vehicle.getTripStatus();
        if (tripStatus != null) {
            TripBean activeTrip = tripStatus.getActiveTrip();
            RouteBean route = activeTrip.getRoute();
            TripDescriptor.Builder tripDesc = vehiclePosition.getTripBuilder();
            tripDesc.setTripId(normalizeId(activeTrip.getId()));
            tripDesc.setRouteId(normalizeId(route.getId()));
        }
        VehicleDescriptor.Builder vehicleDesc = vehiclePosition.getVehicleBuilder();
        vehicleDesc.setId(normalizeId(vehicle.getVehicleId()));
        CoordinatePoint location = vehicle.getLocation();
        if (location != null) {
            Position.Builder position = vehiclePosition.getPositionBuilder();
            position.setLatitude((float) location.getLat());
            position.setLongitude((float) location.getLon());
        }
        vehiclePosition.setTimestamp(vehicle.getLastUpdateTime() / 1000);
    }
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) Position(com.google.transit.realtime.GtfsRealtime.Position) TripBean(org.onebusaway.transit_data.model.trips.TripBean) VehicleStatusBean(org.onebusaway.transit_data.model.VehicleStatusBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) VehiclePosition(com.google.transit.realtime.GtfsRealtime.VehiclePosition) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) VehicleDescriptor(com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)

Aggregations

Position (com.google.transit.realtime.GtfsRealtime.Position)3 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)2 VehicleDescriptor (com.google.transit.realtime.GtfsRealtime.VehicleDescriptor)2 VehiclePosition (com.google.transit.realtime.GtfsRealtime.VehiclePosition)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2 FeedEntity (com.google.transit.realtime.GtfsRealtime.FeedEntity)1 Date (java.util.Date)1 VehiclePositionModel (org.onebusaway.gtfs_realtime.model.VehiclePositionModel)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 VehicleStatusBean (org.onebusaway.transit_data.model.VehicleStatusBean)1 TripBean (org.onebusaway.transit_data.model.trips.TripBean)1 TripStatusBean (org.onebusaway.transit_data.model.trips.TripStatusBean)1 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)1