/** * <code>optional .transit_realtime.Position position = 2;</code> * * <pre> * Current position of this vehicle. * </pre> */ public Builder mergePosition(com.google.transit.realtime.GtfsRealtime.Position value) { if (positionBuilder_ == null) { if (((bitField0_ & 0x00000004) == 0x00000004) && position_ != com.google.transit.realtime.GtfsRealtime.Position.getDefaultInstance()) { position_ = com.google.transit.realtime.GtfsRealtime.Position.newBuilder(position_).mergeFrom(value).buildPartial(); } else { position_ = value; } onChanged(); } else { positionBuilder_.mergeFrom(value); } bitField0_ |= 0x00000004; return this; } /**
if (v.hasPosition() && v.getPosition().hasSpeed()) { if (v.getPosition().getSpeed() > MAX_REALISTIC_SPEED_METERS_PER_SECOND || v.getPosition().getSpeed() < 0f) { " speed of " + v.getPosition().getSpeed() + " m/s (" + String.format("%.2f", GtfsUtils.toMilesPerHour(v.getPosition().getSpeed())) + " mph)"; RuleUtils.addOccurrence(W004, prefix, w004List, _log); GtfsRealtime.Position position = v.getPosition(); String id = getVehicleId(entity, v); if (!position.hasLatitude() || !position.hasLongitude()) { RuleUtils.addOccurrence(E026, id + " has latitude/longitude of (" + position.getLatitude() + "," + position.getLongitude() + ")", e026List, _log); } else { RuleUtils.addOccurrence(E027, id + " has bearing of " + position.getBearing(), e027List, _log);
if (!position.hasLatitude() || !position.hasLongitude()) continue; double lat = position.getLatitude(); double lon = position.getLongitude(); if (position.hasSpeed()) { speed = position.getSpeed(); if (position.hasBearing()) { heading = position.getBearing();
vpm.setLat(p.getLatitude()); vpm.setLon(p.getLongitude()); if (p.hasBearing()) { vpm.setBearing(p.getBearing()); if (p.hasSpeed()) { vpm.setSpeed(p.getSpeed());
Vehicle v = new Vehicle(); v.setId(vehicleId); v.setLat(position.getLatitude()); v.setLon(position.getLongitude()); v.setLastUpdate(System.currentTimeMillis());
Position.Builder position = Position.newBuilder() .setLatitude(vehicleData.getLatitude()) .setLongitude(vehicleData.getLongitude());
String prefix = id + " trip_id " + tripId + " at (" + position.getLatitude() + "," + position.getLongitude() + ") is more than " + TRIP_BUFFER_METERS + " meters (" + String.format("%.2f", GtfsUtils.toMiles(TRIP_BUFFER_METERS)) + " mile(s)) from the GTFS trip shape"; RuleUtils.addOccurrence(E029, prefix, errors, _log);
String prefix = id + " at (" + position.getLatitude() + "," + position.getLongitude() + ") is more than " + GtfsMetadata.REGION_BUFFER_METERS + " meters (" + String.format("%.2f", GtfsUtils.toMiles(GtfsMetadata.REGION_BUFFER_METERS)) + " mile(s)) outside entire GTFS " + boundingDescription + " coverage area";
@Override public FeedMessage getVehiclePositions() { FeedMessage.Builder feedMessage = createFeedWithDefaultHeader(); List<VehicleStatus> statuses = _vehicleStatusService.getAllVehicleStatuses(); for (VehicleStatus status : statuses) { VehicleLocationRecord record = status.getRecord(); VehiclePosition.Builder vehiclePosition = VehiclePosition.newBuilder(); if (record.isCurrentLocationSet()) { Position.Builder position = Position.newBuilder(); position.setLatitude((float) record.getCurrentLocationLat()); position.setLongitude((float) record.getCurrentLocationLon()); vehiclePosition.setPosition(position); } VehicleDescriptor.Builder vehicleDescriptor = VehicleDescriptor.newBuilder(); vehicleDescriptor.setId(AgencyAndId.convertToString(record.getVehicleId())); vehiclePosition.setVehicle(vehicleDescriptor); if (record.getTimeOfLocationUpdate() != 0) vehiclePosition.setTimestamp(record.getTimeOfLocationUpdate() / 1000); else vehiclePosition.setTimestamp(record.getTimeOfRecord() / 1000); /** * TODO: Block? Trip? */ FeedEntity.Builder feedEntity = FeedEntity.newBuilder(); feedEntity.setVehicle(vehiclePosition); feedEntity.setId(vehicleDescriptor.getId()); feedMessage.addEntity(feedEntity); } return feedMessage.build(); }
private void applyVehiclePositionToRecord(MonitoredResult result, BlockDescriptor blockDescriptor, VehiclePosition vehiclePosition, VehicleLocationRecord record) { Position position = vehiclePosition.getPosition(); if (vehiclePosition.hasTimestamp()) { record.setTimeOfLocationUpdate(TimeUnit.SECONDS.toMillis(vehiclePosition.getTimestamp())); //vehicle timestamp is in seconds } 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; double oldDeviation = record.getScheduleDeviation(); record.setScheduleDeviation(deviation); _log.debug("deviation reset to {} from {} for vehicle {}", deviation, oldDeviation, vehiclePosition.getVehicle().getId()); } }
/** * <code>optional .transit_realtime.Position position = 2;</code> * * <pre> * Current position of this vehicle. * </pre> */ public Builder mergePosition(com.google.transit.realtime.GtfsRealtime.Position value) { if (positionBuilder_ == null) { if (((bitField0_ & 0x00000004) == 0x00000004) && position_ != com.google.transit.realtime.GtfsRealtime.Position.getDefaultInstance()) { position_ = com.google.transit.realtime.GtfsRealtime.Position.newBuilder(position_).mergeFrom(value).buildPartial(); } else { position_ = value; } onChanged(); } else { positionBuilder_.mergeFrom(value); } bitField0_ |= 0x00000004; return this; } /**
public final boolean isInitialized() { byte isInitialized = memoizedIsInitialized; if (isInitialized != -1) return isInitialized == 1; if (!hasLatitude()) { memoizedIsInitialized = 0; return false; } if (!hasLongitude()) { memoizedIsInitialized = 0; return false; } if (!extensionsAreInitialized()) { memoizedIsInitialized = 0; return false; } memoizedIsInitialized = 1; return true; }
public Builder mergeFrom(com.google.transit.realtime.GtfsRealtime.Position other) { if (other == com.google.transit.realtime.GtfsRealtime.Position.getDefaultInstance()) return this; if (other.hasLatitude()) { setLatitude(other.getLatitude()); } if (other.hasLongitude()) { setLongitude(other.getLongitude()); } if (other.hasBearing()) { setBearing(other.getBearing()); } if (other.hasOdometer()) { setOdometer(other.getOdometer()); } if (other.hasSpeed()) { setSpeed(other.getSpeed()); } this.mergeExtensionFields(other); this.mergeUnknownFields(other.getUnknownFields()); return this; }
public Builder toBuilder() { return newBuilder(this); }
/** * Returns true if this position has valid bearing, and false if it does not * * @param position Vehicle position to validate * @return true if this position has valid bearing, and false if it does not */ public static boolean isBearingValid(GtfsRealtime.Position position) { if (!position.hasBearing()) { return true; } if (position.getBearing() < 0 || position.getBearing() > 360) { return false; } return true; }
private boolean isValidLocation(VehicleLocationRecord record, CombinedTripUpdatesAndVehiclePosition update) { if (_maxDeltaLocationMeters == null) return true; // validation turned off CoordinatePoint reported = new CoordinatePoint(update.vehiclePosition.getPosition().getLatitude(), update.vehiclePosition.getPosition().getLongitude()); BlockLocation blockLocation = _blockLocationService.getScheduledLocationForBlockInstance(update.block.getBlockInstance(), record.getTimeOfRecord()); if (blockLocation == null) return true; // this record will be tossed for other reasons CoordinatePoint calculated = blockLocation.getLocation(); double delta = SphericalGeometryLibrary.distanceFaster(reported.getLat(), reported.getLon(), calculated.getLat(), calculated.getLon()); if (delta < _maxDeltaLocationMeters) return true; _log.info("dropped vehicle {} has distance of {} with deviation {} when limit is {}", record.getVehicleId(), delta, record.getScheduleDeviation(), _maxDeltaLocationMeters); return false; }
/** * Returns true if this position has valid latitude and longitude values, and false if it does not * * @param position Vehicle position to validate * @return true if this position has valid latitude and longitude values, and false if it does not */ public static boolean isPositionValid(GtfsRealtime.Position position) { if (position.getLatitude() < -90f || position.getLatitude() > 90f) { return false; } if (position.getLongitude() < -180f || position.getLongitude() > 180f) { return false; } return true; }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder(com.google.transit.realtime.GtfsRealtime.Position prototype) {
public static Builder newBuilder(com.google.transit.realtime.GtfsRealtime.Position prototype) { return newBuilder().mergeFrom(prototype); } public Builder toBuilder() { return newBuilder(this); }
/** * Returns true if the provided vehiclePosition is within the provided shape, false if it is not * * @param vehiclePosition the vehiclePosition to test against the shape * @param bounds the shape to test against the vehiclePosition * @return true if the provided vehiclePosition is within the provided shape, false if it is not */ public static boolean isPositionWithinShape(GtfsRealtime.Position vehiclePosition, Shape bounds) { ShapeFactory sf = GEO.getShapeFactory(); org.locationtech.spatial4j.shape.Point p = sf.pointXY(vehiclePosition.getLongitude(), vehiclePosition.getLatitude()); return bounds.relate(p).equals(SpatialRelation.CONTAINS); }