Search in sources :

Example 6 with ShapePoint

use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.

the class OtpTransitServiceImplTest method toString.

private static String toString(ShapePoint sp) {
    int lat = (int) sp.getLat();
    int lon = (int) sp.getLon();
    return "#" + sp.getSequence() + " (" + lat + "," + lon + ")";
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint)

Example 7 with ShapePoint

use of org.opentripplanner.model.ShapePoint 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 8 with ShapePoint

use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.

the class GeometryAndBlockProcessor method getUniqueShapePointsForShapeId.

/**
 * If a shape appears in more than one feed, the shape points will be loaded several
 * times, and there will be duplicates in the DAO. Filter out duplicates and repeated
 * coordinates because 1) they are unnecessary, and 2) they define 0-length line segments
 * which cause JTS location indexed line to return a segment location of NaN,
 * which we do not want.
 */
private List<ShapePoint> getUniqueShapePointsForShapeId(FeedScopedId shapeId) {
    List<ShapePoint> points = transitService.getShapePointsForShapeId(shapeId);
    ArrayList<ShapePoint> filtered = new ArrayList<>(points.size());
    ShapePoint last = null;
    for (ShapePoint sp : points) {
        if (last == null || last.getSequence() != sp.getSequence()) {
            if (last != null && last.getLat() == sp.getLat() && last.getLon() == sp.getLon()) {
                LOG.trace("pair of identical shape points (skipping): {} {}", last, sp);
            } else {
                filtered.add(sp);
            }
        }
        last = sp;
    }
    if (filtered.size() != points.size()) {
        filtered.trimToSize();
        return filtered;
    } else {
        return new ArrayList<>(points);
    }
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint) ArrayList(java.util.ArrayList)

Example 9 with ShapePoint

use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.

the class GeometryAndBlockProcessor method getLineStringForShapeId.

private LineString getLineStringForShapeId(FeedScopedId shapeId) {
    LineString geometry = geometriesByShapeId.get(shapeId);
    if (geometry != null)
        return geometry;
    List<ShapePoint> points = getUniqueShapePointsForShapeId(shapeId);
    if (points.size() < 2) {
        return null;
    }
    Coordinate[] coordinates = new Coordinate[points.size()];
    double[] distances = new double[points.size()];
    boolean hasAllDistances = true;
    int i = 0;
    for (ShapePoint point : points) {
        coordinates[i] = new Coordinate(point.getLon(), point.getLat());
        distances[i] = point.getDistTraveled();
        if (!point.isDistTraveledSet())
            hasAllDistances = false;
        i++;
    }
    // assume the units will match
    if (!hasAllDistances) {
        distances = null;
    }
    CoordinateSequence sequence = new PackedCoordinateSequence.Double(coordinates, 2);
    geometry = geometryFactory.createLineString(sequence);
    geometriesByShapeId.put(shapeId, geometry);
    distancesByShapeId.put(shapeId, distances);
    return geometry;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence) ShapePoint(org.opentripplanner.model.ShapePoint) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ShapePoint(org.opentripplanner.model.ShapePoint)

Example 10 with ShapePoint

use of org.opentripplanner.model.ShapePoint in project OpenTripPlanner by opentripplanner.

the class GTFSToOtpTransitServiceMapper method map.

private OtpTransitServiceBuilder map(GtfsRelationalDao data) {
    OtpTransitServiceBuilder builder = new OtpTransitServiceBuilder();
    builder.getAgenciesById().addAll(agencyMapper.map(data.getAllAgencies()));
    builder.getCalendarDates().addAll(serviceCalendarDateMapper.map(data.getAllCalendarDates()));
    builder.getCalendars().addAll(serviceCalendarMapper.map(data.getAllCalendars()));
    builder.getFareAttributes().addAll(fareAttributeMapper.map(data.getAllFareAttributes()));
    builder.getFareRules().addAll(fareRuleMapper.map(data.getAllFareRules()));
    builder.getFeedInfos().addAll(feedInfoMapper.map(data.getAllFeedInfos()));
    builder.getFrequencies().addAll(frequencyMapper.map(data.getAllFrequencies()));
    builder.getRoutes().addAll(routeMapper.map(data.getAllRoutes()));
    for (ShapePoint shapePoint : shapePointMapper.map(data.getAllShapePoints())) {
        builder.getShapePoints().put(shapePoint.getShapeId(), shapePoint);
    }
    mapGtfsStopsToOtpTypes(data, builder);
    builder.getPathways().addAll(pathwayMapper.map(data.getAllPathways()));
    builder.getStopTimesSortedByTrip().addAll(stopTimeMapper.map(data.getAllStopTimes()));
    builder.getTransfers().addAll(transferMapper.map(data.getAllTransfers()));
    builder.getTripsById().addAll(tripMapper.map(data.getAllTrips()));
    return builder;
}
Also used : OtpTransitServiceBuilder(org.opentripplanner.model.impl.OtpTransitServiceBuilder) ShapePoint(org.opentripplanner.model.ShapePoint)

Aggregations

ShapePoint (org.opentripplanner.model.ShapePoint)11 ArrayList (java.util.ArrayList)3 MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)2 Test (org.junit.Test)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 FeedScopedId (org.opentripplanner.model.FeedScopedId)2 Quay (org.rutebanken.netex.model.Quay)2 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)1 LineString (org.locationtech.jts.geom.LineString)1 PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)1 DataImportIssueStore (org.opentripplanner.graph_builder.DataImportIssueStore)1 MissingProjectionInServiceLink (org.opentripplanner.graph_builder.issues.MissingProjectionInServiceLink)1 OtpTransitServiceBuilder (org.opentripplanner.model.impl.OtpTransitServiceBuilder)1 HierarchicalMap (org.opentripplanner.netex.loader.util.HierarchicalMap)1 HierarchicalMapById (org.opentripplanner.netex.loader.util.HierarchicalMapById)1 HierarchicalVersionMapById (org.opentripplanner.netex.loader.util.HierarchicalVersionMapById)1 JourneyPattern (org.rutebanken.netex.model.JourneyPattern)1 LinkInLinkSequence_VersionedChildStructure (org.rutebanken.netex.model.LinkInLinkSequence_VersionedChildStructure)1 LinkSequenceProjection_VersionStructure (org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure)1