Search in sources :

Example 66 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class MTAEntrancesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    ExternalServices es = new ExternalServicesBridgeFactory().getExternalServices();
    Collection<FeedInfo> feedInfos = dao.getAllFeedInfos();
    String feed = null;
    if (feedInfos.size() > 0)
        feed = feedInfos.iterator().next().getPublisherName();
    File entrancesFile = new File(entrancesCsv);
    if (!entrancesFile.exists()) {
        es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, entrancesCsv }, 1);
        throw new IllegalStateException("Entrances file does not exist: " + entrancesFile.getName());
    }
    if (elevatorsCsv != null) {
        File elevatorsFile = new File(elevatorsCsv);
        if (!elevatorsFile.exists()) {
            es.publishMultiDimensionalMetric(getNamespace(), "MissingControlFiles", new String[] { "feed", "controlFileName" }, new String[] { feed, elevatorsCsv }, 1);
            throw new IllegalStateException("Elevators file does not exist: " + elevatorsFile.getName());
        }
    }
    agencyId = dao.getAllAgencies().iterator().next().getId();
    newStops = new HashSet<>();
    newPathways = new HashSet<>();
    pathwayUtil = new PathwayUtil(agencyId, newPathways);
    for (Pathway pathway : dao.getAllPathways()) {
        stopIdsWithPathways.add(pathway.getFromStop().getId());
        stopIdsWithPathways.add(pathway.getToStop().getId());
    }
    Map<String, StopGroup> stopGroups = new HashMap<>();
    // For every stop that's not a station, add an entrance which is not wheelchair accessible, and a pathway.
    for (Stop stop : dao.getAllStops()) {
        if (stopsHaveParents) {
            // Put stop into a stop-group with parent, uptown, downtown
            String gid = stop.getLocationType() == LOCATION_TYPE_STOP ? stop.getParentStation() : stop.getId().getId();
            if (gid == null) {
                gid = stop.getId().getId();
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.warn("stop {} didn't have a parent set--using own stop ID.", stop.getName());
                continue;
            }
            StopGroup group = stopGroups.get(gid);
            if (group == null) {
                group = new StopGroup();
                stopGroups.put(gid, group);
            }
            if (stop.getLocationType() == LOCATION_TYPE_STATION) {
                group.parent = stop;
            } else if (stop.getId().getId().endsWith("S")) {
                group.downtown = stop;
            } else if (stop.getId().getId().endsWith("N")) {
                group.uptown = stop;
            } else {
                // it's a pathway, ignore
                if (stop.getLocationType() >= 2)
                    continue;
                // don't fret about this one, it's a shuttle stop
                if (stop.getName().contains("SHUTTLE BUS STOP"))
                    continue;
                _log.error("unexpected stop not of parent type but of {} for stop {}: {}", stop.getLocationType(), stop.getId(), stop.getName());
                continue;
            }
        } else {
            StopGroup group = new StopGroup();
            group.parent = stop;
            String gid = stop.getId().getId();
            stopGroups.put(gid, group);
        }
    }
    readEntranceData(stopGroups);
    if (elevatorsCsv != null) {
        readElevatorData(stopGroups, getComplexList(dao));
    }
    for (Stop s : newStops) {
        dao.saveEntity(s);
    }
    for (Pathway pathway : newPathways) {
        dao.saveEntity(pathway);
    }
}
Also used : ExternalServicesBridgeFactory(org.onebusaway.cloud.api.ExternalServicesBridgeFactory) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Pathway(org.onebusaway.gtfs.model.Pathway) FeedInfo(org.onebusaway.gtfs.model.FeedInfo) PathwayUtil(org.onebusaway.gtfs_transformer.util.PathwayUtil) ExternalServices(org.onebusaway.cloud.api.ExternalServices) File(java.io.File)

Example 67 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class MTAEntrancesStrategy method readElevatorData.

private void readElevatorData(Map<String, StopGroup> stopGroups, Map<String, List<Stop>> complexIdToStops) {
    List<MTAElevator> elevators = getElevators();
    for (MTAElevator e : elevators) {
        StopGroup g = stopGroups.get(e.getStopId());
        if (g == null)
            _log.error("No stop group for elevator={}, stop={}", e.getId(), e.getStopId());
        else
            g.elevators.add(e);
    }
    int unknown = 0;
    for (StopGroup group : stopGroups.values()) {
        // there should be no more. Therefore, we can skip this stop completely.
        if (skipStopsWithExistingPathways && (group.parent != null && stopIdsWithPathways.contains(group.parent.getId()) || (group.uptown != null && stopIdsWithPathways.contains(group.uptown.getId())) || (group.downtown != null && stopIdsWithPathways.contains(group.downtown.getId())))) {
            _log.info("Stop {} already has pathways from other sources; skipping.", group);
            continue;
        }
        Stop entrance = null;
        // elevator is defined by ID, type, and direction iff it includes platform
        Set<String> seenElevatorPathways = new HashSet<>();
        Map<String, Stop> mezzByName = new HashMap<>();
        for (MTAElevator e : group.elevators) {
            ElevatorPathwayType type = ElevatorPathwayType.valueOf(e.getLoc());
            type.resolveElevatorNames(e);
            if (type == ElevatorPathwayType.UNKNOWN) {
                unknown++;
                _log.debug("unknown type={}, elev={}", e.getLoc(), e.getId());
                continue;
            }
            if (entrance == null && type.shouldCreateStreetEntrance()) {
                entrance = createAccessibleStreetEntrance(group.parent);
            }
            Stop platform = null;
            if (e.getDirection() != null) {
                if (e.getDirection().equals("N")) {
                    platform = group.uptown;
                    if (platform == null) {
                        _log.warn("Elevator file refers to platform {} and direction {} which is not in the GTFS. Check your data.", e.getStopId(), e.getDirection());
                        continue;
                    }
                } else if (e.getDirection().equals("S")) {
                    platform = group.downtown;
                    if (platform == null) {
                        _log.warn("Elevator file refers to platform {} and direction {} which is not in the GTFS. Check your data.", e.getStopId(), e.getDirection());
                        continue;
                    }
                } else {
                    _log.error("Unexpected direction={}, elev={}", e.getDirection(), e.getId());
                }
            }
            // only if the user hasn't already done so by naming the mezzes
            if (type.mezzanineNames != null) {
                List<String> newMezzanineNames = new ArrayList<>();
                for (String name : type.mezzanineNames) {
                    boolean partOfComplex = false;
                    for (String complexId : complexIdToStops.keySet()) {
                        List<Stop> stopsInComplex = complexIdToStops.get(complexId);
                        if (stopsInComplex.contains(platform)) {
                            newMezzanineNames.add(complexId + "-mezz-" + name);
                            partOfComplex = true;
                            break;
                        }
                    }
                    // parent stop ID as we would have before
                    if (!partOfComplex)
                        newMezzanineNames.add(group.parent.getId().getId() + "-mezz-" + name);
                }
                type.mezzanineNames = newMezzanineNames;
            }
            if (type.shouldCreateMezzanine()) {
                for (String name : type.mezzanineNames) {
                    Stop m = mezzByName.get(name);
                    if (m == null) {
                        m = createMezzanineWithId(group.parent, new AgencyAndId(platform.getId().getAgencyId(), name));
                        mezzByName.put(name, m);
                    }
                }
            }
            String code = e.getId();
            if (type.shouldCreateStreetToMezzanine()) {
                String id_base = "S2M_" + code;
                for (String name : type.mezzanineNames) {
                    Stop mezz = mezzByName.get(name);
                    String id = id_base + "_" + name;
                    createElevPathways(entrance, mezz, code, id, seenElevatorPathways);
                }
            }
            if (type.shouldCreateMezzanineToPlatform()) {
                String id_base = "M2P_" + code + "_" + e.getDirection();
                for (String name : type.mezzanineNames) {
                    Stop mezz = mezzByName.get(name);
                    String id = id_base + "_" + name;
                    createElevPathways(mezz, platform, code, id, seenElevatorPathways);
                }
            }
            if (type.shouldCreateStreetToPlatform()) {
                String id = "S2P_" + code + "_" + e.getDirection();
                createElevPathways(entrance, platform, code, id, seenElevatorPathways);
            }
            if (type.shouldCreateMezzanineToMezzanine()) {
                for (int i = 0; i < type.mezzanineNames.size(); i++) {
                    for (int j = i + 1; j < type.mezzanineNames.size(); j++) {
                        String name0 = type.mezzanineNames.get(i);
                        String name1 = type.mezzanineNames.get(j);
                        Stop mezz0 = mezzByName.get(name0);
                        Stop mezz1 = mezzByName.get(name1);
                        String id = "M2M_" + code + "_" + name0 + "_" + name1;
                        createElevPathways(mezz0, mezz1, code, id, seenElevatorPathways);
                    }
                }
            }
        }
    }
    _log.info("Processed {} / {} ({} are unknown)", elevators.size() - unknown, elevators.size(), unknown);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MTAElevator(org.onebusaway.gtfs_transformer.csv.MTAElevator) HashSet(java.util.HashSet)

Example 68 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class MTASubwayShuttleRouteStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<Route, Route> shuttleRoutes = new HashMap<>();
    for (Trip trip : dao.getAllTrips()) {
        if (trip.getTripHeadsign().endsWith(SHUTTLE_HEADSIGN_SUFFIX)) {
            Route shuttleRoute = shuttleRoutes.computeIfAbsent(trip.getRoute(), r -> getShuttleRoute(dao, r));
            trip.setRoute(shuttleRoute);
            dao.updateEntity(trip);
        }
    }
    // Shuttle stops share mta_stop_id with non-shuttle version
    Map<String, String> parentStopByMtaStopId = new HashMap<>();
    for (Stop stop : dao.getAllStops()) {
        if (!stop.getName().endsWith(SHUTTLE_STOP_SUFFIX) && stop.getParentStation() != null) {
            parentStopByMtaStopId.put(stop.getMtaStopId(), stop.getParentStation());
        }
    }
    for (Stop stop : dao.getAllStops()) {
        if (stop.getName().endsWith(SHUTTLE_STOP_SUFFIX)) {
            String parent = parentStopByMtaStopId.get(stop.getMtaStopId());
            if (parent == null) {
                _log.info("No parent for shuttle stop {}", stop.getId());
            }
            stop.setParentStation(parent);
            dao.updateEntity(stop);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Example 69 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class AddOmnyLIRRData method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    int stop_count = 0;
    File stopsFile = new File((String) context.getParameter("omnyStopsFile"));
    if (!stopsFile.exists()) {
        throw new IllegalStateException("OMNY Stops file does not exist: " + stopsFile.getName());
    }
    List<String> stopLines = new InputLibrary().readList((String) context.getParameter("omnyStopsFile"));
    _log.info("Length of stop file: {}", stopLines.size());
    for (String stopInfo : stopLines) {
        String[] stopArray = stopInfo.split(",");
        if (stopArray == null || stopArray.length < 2) {
            _log.info("bad line {}", stopInfo);
            continue;
        }
        String stopId = stopArray[STOP_ID];
        String zoneId = stopArray[ZONE_ID];
        // See MOTP-1232
        for (Stop stop : dao.getAllStops()) {
            if (stop.getId().getId().equals(stopId)) {
                stop.setZoneId(zoneId);
                stop_count++;
                break;
            }
        }
    }
    _log.info("Set {} stops with zone_id", stop_count);
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) File(java.io.File)

Example 70 with Stop

use of org.onebusaway.gtfs.model.Stop in project onebusaway-gtfs-modules by OneBusAway.

the class UpdateStopIdFromReferenceStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    // list of ids added to prevent duplicates
    ArrayList<AgencyAndId> stopsAdded = new ArrayList();
    // list of stops to add
    ArrayList<Stop> stopsToAdd = new ArrayList<>();
    HashMap<String, Stop> referenceStops = new HashMap<>();
    for (Stop stop : reference.getAllStops()) {
        referenceStops.put(stop.getId().getId(), stop);
    }
    AgencyAndId agencyAndId = dao.getAllStops().iterator().next().getId();
    for (Stop stop : dao.getAllStops()) {
        String parentStation = stop.getParentStation();
        if (parentStation != null) {
            Stop existingStop = dao.getStopForId(new AgencyAndId(agencyAndId.getAgencyId(), parentStation));
            if (existingStop == null && !stopsAdded.contains(referenceStops.get(parentStation).getId())) {
                Stop stopToAdd = new Stop();
                stopToAdd.setId(referenceStops.get(parentStation).getId());
                stopToAdd.setName(referenceStops.get(parentStation).getName());
                stopToAdd.setLat(referenceStops.get(parentStation).getLat());
                stopToAdd.setLon(referenceStops.get(parentStation).getLon());
                stopToAdd.setLocationType(referenceStops.get(parentStation).getLocationType());
                stopsAdded.add(referenceStops.get(parentStation).getId());
                stopsToAdd.add(stopToAdd);
            }
        }
    }
    for (Stop stop : stopsToAdd) {
        dao.saveOrUpdateEntity(stop);
        _log.info("updating stops {}", stop.getId());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

Stop (org.onebusaway.gtfs.model.Stop)160 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)75 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Trip (org.onebusaway.gtfs.model.Trip)40 Test (org.junit.Test)39 ArrayList (java.util.ArrayList)33 StopTime (org.onebusaway.gtfs.model.StopTime)33 Route (org.onebusaway.gtfs.model.Route)28 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)23 Agency (org.onebusaway.gtfs.model.Agency)19 Vertex (org.opentripplanner.routing.graph.Vertex)18 HashMap (java.util.HashMap)14 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)13 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)11 LineString (com.vividsolutions.jts.geom.LineString)10 List (java.util.List)10 GET (javax.ws.rs.GET)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10 GraphPath (org.opentripplanner.routing.spt.GraphPath)10 Coordinate (com.vividsolutions.jts.geom.Coordinate)9