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;
}
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;
}
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;
}
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();
}
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);
}
}
Aggregations