use of org.onebusaway.transit_data_federation.model.ProjectedPoint 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.transit_data_federation.model.ProjectedPoint in project onebusaway-application-modules by camsys.
the class GenerateNarrativesTask method generateStopNarratives.
public void generateStopNarratives(NarrativeProviderImpl provider) {
Map<AgencyAndId, List<ProjectedPoint>> shapePointCache = new HashMap<AgencyAndId, List<ProjectedPoint>>();
int index = 0;
Collection<Stop> allStops = _gtfsDao.getAllStops();
Map<AgencyAndId, Stop> stopsById = MappingLibrary.mapToValue(allStops, "id");
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(allStops.size());
for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
if (index % logInterval == 0)
_log.info("stops=" + index);
index++;
Stop stop = stopsById.get(stopEntry.getId());
StopNarrative.Builder narrative = StopNarrative.builder();
narrative.setCode(deduplicate(stop.getCode()));
narrative.setDescription(deduplicate(stop.getDesc()));
narrative.setName(deduplicate(stop.getName()));
narrative.setUrl(deduplicate(stop.getUrl()));
String direction = computeStopDirection(provider, shapePointCache, stop, stopEntry);
narrative.setDirection(deduplicate(direction));
provider.setNarrativeForStop(stopEntry.getId(), narrative.create());
}
}
use of org.onebusaway.transit_data_federation.model.ProjectedPoint in project onebusaway-application-modules by camsys.
the class ProjectedPointFactory method forward.
public static ProjectedPoint forward(CoordinatePoint latlon, int zone) {
UTMProjection projection = new UTMProjection(zone);
XYPoint point = projection.forward(latlon);
return new ProjectedPoint(latlon.getLat(), latlon.getLon(), point.getX(), point.getY(), zone);
}
use of org.onebusaway.transit_data_federation.model.ProjectedPoint in project onebusaway-application-modules by camsys.
the class ProjectedPointFactory method reverse.
public static ProjectedPoint reverse(double x, double y, int srid) {
UTMProjection projection = new UTMProjection(srid);
XYPoint p = new XYPoint(x, y);
CoordinatePoint latlon = projection.reverse(p);
return new ProjectedPoint(latlon.getLat(), latlon.getLon(), x, y, srid);
}
Aggregations