Search in sources :

Example 1 with JourneyPattern

use of org.rutebanken.netex.model.JourneyPattern in project OpenTripPlanner by opentripplanner.

the class NetexMapper method mapTripPatterns.

private void mapTripPatterns(NetexImportDataIndexReadOnlyView netexIndex) {
    TripPatternMapper tripPatternMapper = new TripPatternMapper(idFactory, transitBuilder.getStops(), transitBuilder.getRoutes(), transitBuilder.getShapePoints().keySet(), netexIndex.getRouteById(), netexIndex.getJourneyPatternsById(), netexIndex.getQuayIdByStopPointRef(), netexIndex.getDestinationDisplayById(), netexIndex.getServiceJourneyByPatternId(), deduplicator);
    for (JourneyPattern journeyPattern : netexIndex.getJourneyPatternsById().localValues()) {
        TripPatternMapper.Result result = tripPatternMapper.mapTripPattern(journeyPattern);
        for (Map.Entry<Trip, List<StopTime>> it : result.tripStopTimes.entrySet()) {
            transitBuilder.getStopTimesSortedByTrip().put(it.getKey(), it.getValue());
            transitBuilder.getTripsById().add(it.getKey());
        }
        for (TripPattern it : result.tripPatterns) {
            transitBuilder.getTripPatterns().put(it.stopPattern, it);
        }
        stopTimesByNetexId.putAll(result.stopTimeByNetexId);
    }
}
Also used : JourneyPattern(org.rutebanken.netex.model.JourneyPattern) Trip(org.opentripplanner.model.Trip) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TripPattern(org.opentripplanner.model.TripPattern)

Example 2 with JourneyPattern

use of org.rutebanken.netex.model.JourneyPattern in project OpenTripPlanner by opentripplanner.

the class TripMapperTest method mapTripWithRouteRefViaJourneyPattern.

@Test
public void mapTripWithRouteRefViaJourneyPattern() {
    OtpTransitServiceBuilder transitBuilder = new OtpTransitServiceBuilder();
    Route route = new Route();
    route.setId(ID_FACTORY.createId(ROUTE_ID));
    transitBuilder.getRoutes().add(route);
    JourneyPattern journeyPattern = new JourneyPattern().withId(JOURNEY_PATTERN_ID);
    journeyPattern.setRouteRef(new RouteRefStructure().withRef(ROUTE_ID));
    ServiceJourney serviceJourney = createExampleServiceJourney();
    serviceJourney.setJourneyPatternRef(MappingSupport.createWrappedRef(JOURNEY_PATTERN_ID, JourneyPatternRefStructure.class));
    org.rutebanken.netex.model.Route netexRoute = new org.rutebanken.netex.model.Route();
    netexRoute.setLineRef(LINE_REF);
    netexRoute.setId(ROUTE_ID);
    HierarchicalMapById<org.rutebanken.netex.model.Route> routeById = new HierarchicalMapById<>();
    routeById.add(netexRoute);
    HierarchicalMapById<JourneyPattern> journeyPatternById = new HierarchicalMapById<>();
    journeyPatternById.add(journeyPattern);
    TripMapper tripMapper = new TripMapper(ID_FACTORY, transitBuilder.getRoutes(), routeById, journeyPatternById, Collections.emptySet());
    Trip trip = tripMapper.mapServiceJourney(serviceJourney);
    assertEquals(trip.getId(), ID_FACTORY.createId("RUT:ServiceJourney:1"));
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ServiceJourney(org.rutebanken.netex.model.ServiceJourney) Trip(org.opentripplanner.model.Trip) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) JourneyPatternRefStructure(org.rutebanken.netex.model.JourneyPatternRefStructure) RouteRefStructure(org.rutebanken.netex.model.RouteRefStructure) Route(org.opentripplanner.model.Route) Test(org.junit.Test)

Example 3 with JourneyPattern

use of org.rutebanken.netex.model.JourneyPattern in project OpenTripPlanner by opentripplanner.

the class NetexImportDataIndexTest method lookupJourneyPatternById.

@Test
public void lookupJourneyPatternById() {
    JourneyPattern value = new JourneyPattern().withId(ID);
    root.journeyPatternsById.add(value);
    assertEquals(value, child.journeyPatternsById.lookup(ID));
}
Also used : JourneyPattern(org.rutebanken.netex.model.JourneyPattern) Test(org.junit.Test)

Example 4 with JourneyPattern

use of org.rutebanken.netex.model.JourneyPattern in project OpenTripPlanner by opentripplanner.

the class ServiceLinkMapperTest method mapServiceLinks.

@Test
public void mapServiceLinks() {
    JourneyPattern journeyPattern = new JourneyPattern().withId("RUT:JourneyPattern:1300");
    journeyPattern.setLinksInSequence(new LinksInJourneyPattern_RelStructure().withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:1"))).withServiceLinkInJourneyPatternOrTimingLinkInJourneyPattern(new ServiceLinkInJourneyPattern_VersionedChildStructure().withServiceLinkRef(new ServiceLinkRefStructure().withRef("RUT:ServiceLink:2"))));
    ServiceLink serviceLink1 = createServiceLink("RUT:ServiceLink:1", 200.0, new Double[] { COORDINATES[0], COORDINATES[1], COORDINATES[2], COORDINATES[3] });
    ServiceLink serviceLink2 = createServiceLink("RUT:ServiceLink:2", 100.0, new Double[] { COORDINATES[2], COORDINATES[3], COORDINATES[4], COORDINATES[5] });
    HierarchicalMapById<ServiceLink> serviceLinksById = new HierarchicalMapById<>();
    serviceLinksById.add(serviceLink1);
    serviceLinksById.add(serviceLink2);
    Quay quay1 = new Quay().withId("NSR:Quay:1");
    Quay quay2 = new Quay().withId("NSR:Quay:2");
    Quay quay3 = new Quay().withId("NSR:Quay:3");
    HierarchicalVersionMapById<Quay> quaysById = new HierarchicalVersionMapById<>();
    quaysById.add(quay1);
    quaysById.add(quay2);
    quaysById.add(quay3);
    HierarchicalMap<String, String> quayIdByStopPointRef = new HierarchicalMap<>();
    quayIdByStopPointRef.add("RUT:StopPoint:1", "NSR:Quay:1");
    quayIdByStopPointRef.add("RUT:StopPoint:2", "NSR:Quay:2");
    quayIdByStopPointRef.add("RUT:StopPoint:3", "NSR:Quay:3");
    ServiceLinkMapper serviceLinkMapper = new ServiceLinkMapper(new FeedScopedIdFactory("RB"), new DataImportIssueStore(false));
    Collection<ShapePoint> shapePoints = serviceLinkMapper.getShapePointsByJourneyPattern(journeyPattern, serviceLinksById, quayIdByStopPointRef, quaysById);
    List<ShapePoint> shapePointList = shapePoints.stream().sorted(Comparator.comparing(ShapePoint::getSequence)).collect(Collectors.toList());
    Assert.assertEquals(COORDINATES[0], shapePointList.get(0).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[1], shapePointList.get(0).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[2], shapePointList.get(1).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[3], shapePointList.get(1).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[2], shapePointList.get(2).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[3], shapePointList.get(2).getLon(), 0.0001);
    Assert.assertEquals(COORDINATES[4], shapePointList.get(3).getLat(), 0.0001);
    Assert.assertEquals(COORDINATES[5], shapePointList.get(3).getLon(), 0.0001);
}
Also used : ServiceLinkRefStructure(org.rutebanken.netex.model.ServiceLinkRefStructure) HierarchicalVersionMapById(org.opentripplanner.netex.loader.util.HierarchicalVersionMapById) HierarchicalMapById(org.opentripplanner.netex.loader.util.HierarchicalMapById) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) ShapePoint(org.opentripplanner.model.ShapePoint) LinksInJourneyPattern_RelStructure(org.rutebanken.netex.model.LinksInJourneyPattern_RelStructure) ServiceLink(org.rutebanken.netex.model.ServiceLink) Quay(org.rutebanken.netex.model.Quay) DataImportIssueStore(org.opentripplanner.graph_builder.DataImportIssueStore) HierarchicalMap(org.opentripplanner.netex.loader.util.HierarchicalMap) ServiceLinkInJourneyPattern_VersionedChildStructure(org.rutebanken.netex.model.ServiceLinkInJourneyPattern_VersionedChildStructure) Test(org.junit.Test)

Example 5 with JourneyPattern

use of org.rutebanken.netex.model.JourneyPattern in project OpenTripPlanner by opentripplanner.

the class NetexImportDataIndex method readOnlyView.

public NetexImportDataIndexReadOnlyView readOnlyView() {
    return new NetexImportDataIndexReadOnlyView() {

        /**
         * Lookup a Network given a GroupOfLine id or an Network id. If the given
         * {@code groupOfLineOrNetworkId} is a GroupOfLine ID, we lookup the GroupOfLine, and then
         * lookup its Network. If the given {@code groupOfLineOrNetworkId} is a Network ID then we
         * can lookup the Network directly.
         * <p/>
         * If no Network is found {@code null} is returned.
         */
        public Network lookupNetworkForLine(String groupOfLineOrNetworkId) {
            GroupOfLines groupOfLines = groupOfLinesById.lookup(groupOfLineOrNetworkId);
            String networkId = groupOfLines == null ? groupOfLineOrNetworkId : networkIdByGroupOfLineId.lookup(groupOfLines.getId());
            return networkById.lookup(networkId);
        }

        public ReadOnlyHierarchicalMapById<Authority> getAuthoritiesById() {
            return authoritiesById;
        }

        public ReadOnlyHierarchicalMapById<DayType> getDayTypeById() {
            return dayTypeById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<DayTypeAssignment>> getDayTypeAssignmentByDayTypeId() {
            return dayTypeAssignmentByDayTypeId;
        }

        public Iterable<DayTypeRefsToServiceIdAdapter> getDayTypeRefs() {
            return Collections.unmodifiableSet(dayTypeRefs);
        }

        public ReadOnlyHierarchicalMapById<DestinationDisplay> getDestinationDisplayById() {
            return destinationDisplayById;
        }

        public ReadOnlyHierarchicalMapById<GroupOfStopPlaces> getGroupOfStopPlacesById() {
            return groupOfStopPlacesById;
        }

        public ReadOnlyHierarchicalMapById<JourneyPattern> getJourneyPatternsById() {
            return journeyPatternsById;
        }

        public ReadOnlyHierarchicalMapById<Line> getLineById() {
            return lineById;
        }

        public ReadOnlyHierarchicalMapById<StopPlace> getMultiModalStopPlaceById() {
            return multiModalStopPlaceById;
        }

        public ReadOnlyHierarchicalMapById<Notice> getNoticeById() {
            return noticeById;
        }

        public ReadOnlyHierarchicalMapById<NoticeAssignment> getNoticeAssignmentById() {
            return noticeAssignmentById;
        }

        public ReadOnlyHierarchicalMapById<OperatingPeriod> getOperatingPeriodById() {
            return operatingPeriodById;
        }

        public ReadOnlyHierarchicalMapById<Operator> getOperatorsById() {
            return operatorsById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<TimetabledPassingTime>> getPassingTimeByStopPointId() {
            return passingTimeByStopPointId;
        }

        public ReadOnlyHierarchicalVersionMapById<Quay> getQuayById() {
            return quayById;
        }

        public ReadOnlyHierarchicalMap<String, String> getQuayIdByStopPointRef() {
            return quayIdByStopPointRef;
        }

        public ReadOnlyHierarchicalMapById<Route> getRouteById() {
            return routeById;
        }

        public ReadOnlyHierarchicalMap<String, Collection<ServiceJourney>> getServiceJourneyByPatternId() {
            return serviceJourneyByPatternId;
        }

        public ReadOnlyHierarchicalMapById<ServiceLink> getServiceLinkById() {
            return serviceLinkById;
        }

        public ReadOnlyHierarchicalVersionMapById<StopPlace> getStopPlaceById() {
            return stopPlaceById;
        }

        public ReadOnlyHierarchicalMapById<TariffZone> getTariffZonesById() {
            return tariffZonesById;
        }

        public String getTimeZone() {
            return timeZone.get();
        }
    };
}
Also used : Operator(org.rutebanken.netex.model.Operator) StopPlace(org.rutebanken.netex.model.StopPlace) TariffZone(org.rutebanken.netex.model.TariffZone) DestinationDisplay(org.rutebanken.netex.model.DestinationDisplay) GroupOfStopPlaces(org.rutebanken.netex.model.GroupOfStopPlaces) Authority(org.rutebanken.netex.model.Authority) DayType(org.rutebanken.netex.model.DayType) GroupOfLines(org.rutebanken.netex.model.GroupOfLines) Line(org.rutebanken.netex.model.Line) JourneyPattern(org.rutebanken.netex.model.JourneyPattern) Notice(org.rutebanken.netex.model.Notice) DayTypeRefsToServiceIdAdapter(org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter) OperatingPeriod(org.rutebanken.netex.model.OperatingPeriod) Collection(java.util.Collection) NoticeAssignment(org.rutebanken.netex.model.NoticeAssignment) Quay(org.rutebanken.netex.model.Quay) ServiceLink(org.rutebanken.netex.model.ServiceLink) Route(org.rutebanken.netex.model.Route)

Aggregations

JourneyPattern (org.rutebanken.netex.model.JourneyPattern)7 Test (org.junit.Test)3 Trip (org.opentripplanner.model.Trip)2 HierarchicalMapById (org.opentripplanner.netex.loader.util.HierarchicalMapById)2 DayTypeRefsToServiceIdAdapter (org.opentripplanner.netex.support.DayTypeRefsToServiceIdAdapter)2 Quay (org.rutebanken.netex.model.Quay)2 ServiceLink (org.rutebanken.netex.model.ServiceLink)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 FeedScopedId (org.opentripplanner.model.FeedScopedId)1 Route (org.opentripplanner.model.Route)1 ShapePoint (org.opentripplanner.model.ShapePoint)1 TripPattern (org.opentripplanner.model.TripPattern)1 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)1 HierarchicalMap (org.opentripplanner.netex.loader.util.HierarchicalMap)1 HierarchicalVersionMapById (org.opentripplanner.netex.loader.util.HierarchicalVersionMapById)1 Authority (org.rutebanken.netex.model.Authority)1