Vehicle v = new Vehicle(); v.setId(vehicleId); v.setLat(position.getLatitude()); v.setLon(position.getLongitude()); v.setLastUpdate(System.currentTimeMillis());
} else if (!GtfsUtils.isPositionValid(position)) { RuleUtils.addOccurrence(E026, id + " has latitude/longitude of (" + position.getLatitude() + "," + position.getLongitude() + ")", e026List, _log); } else {
continue; double lat = position.getLatitude(); double lon = position.getLongitude();
vpm.setLat(p.getLatitude()); vpm.setLon(p.getLongitude()); if (p.hasBearing()) {
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";
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()); } }
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; }
/** * 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; }
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 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); }
private void cacheVehicleLocations(FeedMessage vehiclePositions) { for (FeedEntity entity : vehiclePositions.getEntityList()) { if (entity.hasVehicle()) { GtfsRealtime.VehiclePosition vehicle = entity.getVehicle(); _vehicleLocationListener.handleRawPosition( new AgencyAndId(getAgencyIds().get(0), vehicle.getVehicle().getId()), vehicle.getPosition().getLatitude(), vehicle.getPosition().getLongitude(), vehicle.getTimestamp()); } } }
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; }