Search in sources :

Example 1 with ProjectedPoint

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();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) Min(org.onebusaway.collections.Min) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) List(java.util.List) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Example 2 with ProjectedPoint

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());
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) DoubleArrayList(cern.colt.list.DoubleArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative)

Example 3 with ProjectedPoint

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);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint)

Example 4 with ProjectedPoint

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);
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) UTMProjection(org.onebusaway.geospatial.services.UTMProjection) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint)

Aggregations

ProjectedPoint (org.onebusaway.transit_data_federation.model.ProjectedPoint)4 XYPoint (org.onebusaway.geospatial.model.XYPoint)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)2 UTMProjection (org.onebusaway.geospatial.services.UTMProjection)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 HashMap (java.util.HashMap)1 Min (org.onebusaway.collections.Min)1 Stop (org.onebusaway.gtfs.model.Stop)1 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)1 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)1 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)1 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1