Search in sources :

Example 1 with ShapePoint

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

the class ShapePointMapper method doMap.

private ShapePoint doMap(org.onebusaway.gtfs.model.ShapePoint rhs) {
    ShapePoint lhs = new ShapePoint();
    lhs.setShapeId(AgencyAndIdMapper.mapAgencyAndId(rhs.getShapeId()));
    lhs.setSequence(rhs.getSequence());
    lhs.setLat(rhs.getLat());
    lhs.setLon(rhs.getLon());
    lhs.setDistTraveled(rhs.getDistTraveled());
    // private transient StopTimeProxy proxy;
    if (rhs.getProxy() != null) {
        throw new IllegalStateException("Did not expect proxy to be set! Data: " + rhs);
    }
    return lhs;
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint)

Example 2 with ShapePoint

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

the class ServiceLinkMapper method mapServiceLink.

private Collection<ShapePoint> mapServiceLink(ServiceLink serviceLink, JourneyPattern journeyPattern, MutableInt sequenceCounter, MutableDouble distanceCounter, ReadOnlyHierarchicalMap<String, String> quayIdByStopPointRef, ReadOnlyHierarchicalVersionMapById<Quay> quayById) {
    Collection<ShapePoint> shapePoints = new ArrayList<>();
    FeedScopedId shapePointIdFromJourneyPatternId = createShapePointIdFromJourneyPatternId(idFactory.createId(journeyPattern.getId()));
    if (serviceLink.getProjections() == null || serviceLink.getProjections().getProjectionRefOrProjection() == null) {
        addStraightLine(serviceLink, sequenceCounter, distanceCounter, quayIdByStopPointRef, quayById, shapePoints, shapePointIdFromJourneyPatternId);
    } else {
        mapCoordinates(serviceLink, sequenceCounter, distanceCounter, shapePoints, shapePointIdFromJourneyPatternId);
    }
    return shapePoints;
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint) ArrayList(java.util.ArrayList) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 3 with ShapePoint

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

the class ServiceLinkMapper method mapCoordinates.

private void mapCoordinates(ServiceLink serviceLink, MutableInt sequenceCounter, MutableDouble distanceCounter, Collection<ShapePoint> shapePoints, FeedScopedId shapePointIdFromJourneyPatternId) {
    for (JAXBElement<?> projectionElement : serviceLink.getProjections().getProjectionRefOrProjection()) {
        Object projectionObj = projectionElement.getValue();
        if (projectionObj instanceof LinkSequenceProjection_VersionStructure) {
            LinkSequenceProjection_VersionStructure linkSequenceProjection = (LinkSequenceProjection_VersionStructure) projectionObj;
            if (linkSequenceProjection.getLineString() != null) {
                List<Double> coordinates = linkSequenceProjection.getLineString().getPosList().getValue();
                double distance = serviceLink.getDistance() != null ? serviceLink.getDistance().doubleValue() : -1;
                for (int i = 0; i < coordinates.size(); i += 2) {
                    ShapePoint shapePoint = new ShapePoint();
                    shapePoint.setShapeId(shapePointIdFromJourneyPatternId);
                    shapePoint.setLat(coordinates.get(i));
                    shapePoint.setLon(coordinates.get(i + 1));
                    shapePoint.setSequence(sequenceCounter.toInteger());
                    if (distance != -1) {
                        shapePoint.setDistTraveled(distanceCounter.doubleValue() + (distance / (coordinates.size() / 2.0) * (i / 2.0)));
                    }
                    sequenceCounter.increment();
                    shapePoints.add(shapePoint);
                }
                distanceCounter.add(distance != -1 ? distance : 0);
            } else {
                LOG.warn("Ignore linkSequenceProjection without linestring for: " + linkSequenceProjection.toString());
            }
        }
    }
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint) LinkSequenceProjection_VersionStructure(org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure) MutableDouble(org.apache.commons.lang3.mutable.MutableDouble) ShapePoint(org.opentripplanner.model.ShapePoint)

Example 4 with ShapePoint

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

the class ServiceLinkMapper method addStraightLine.

private void addStraightLine(ServiceLink serviceLink, MutableInt sequenceCounter, MutableDouble distanceCounter, ReadOnlyHierarchicalMap<String, String> quayIdByStopPointRef, ReadOnlyHierarchicalVersionMapById<Quay> quayById, Collection<ShapePoint> shapePoints, FeedScopedId shapePointIdFromJourneyPatternId) {
    String fromPointQuayId = quayIdByStopPointRef.lookup(serviceLink.getFromPointRef().getRef());
    Quay fromPointQuay = quayById.lookupLastVersionById(fromPointQuayId);
    String toPointQuayId = quayIdByStopPointRef.lookup(serviceLink.getToPointRef().getRef());
    Quay toPointQuay = quayById.lookupLastVersionById(toPointQuayId);
    if (fromPointQuay != null && fromPointQuay.getCentroid() != null && toPointQuay != null && toPointQuay.getCentroid() != null) {
        issueStore.add(new MissingProjectionInServiceLink(serviceLink.getId()));
        ShapePoint fromShapePoint = new ShapePoint();
        fromShapePoint.setShapeId(shapePointIdFromJourneyPatternId);
        fromShapePoint.setLat(fromPointQuay.getCentroid().getLocation().getLatitude().doubleValue());
        fromShapePoint.setLon(fromPointQuay.getCentroid().getLocation().getLongitude().doubleValue());
        fromShapePoint.setSequence(sequenceCounter.toInteger());
        fromShapePoint.setDistTraveled(distanceCounter.getValue());
        shapePoints.add(fromShapePoint);
        sequenceCounter.increment();
        ShapePoint toShapePoint = new ShapePoint();
        toShapePoint.setShapeId(shapePointIdFromJourneyPatternId);
        toShapePoint.setLat(toPointQuay.getCentroid().getLocation().getLatitude().doubleValue());
        toShapePoint.setLon(toPointQuay.getCentroid().getLocation().getLongitude().doubleValue());
        toShapePoint.setSequence(sequenceCounter.toInteger());
        shapePoints.add(toShapePoint);
        sequenceCounter.increment();
        double distance;
        if (serviceLink.getDistance() != null) {
            distance = serviceLink.getDistance().doubleValue();
        } else {
            Coordinate fromCoord = new Coordinate(fromShapePoint.getLon(), fromShapePoint.getLat());
            Coordinate toCoord = new Coordinate(toShapePoint.getLon(), toShapePoint.getLat());
            distance = SphericalDistanceLibrary.distance(fromCoord, toCoord);
        }
        distanceCounter.add(distance);
        toShapePoint.setDistTraveled(distanceCounter.doubleValue());
    } else {
        LOG.warn("Ignore service link without projection and missing or unknown quays: " + serviceLink);
    }
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint) Coordinate(org.locationtech.jts.geom.Coordinate) MissingProjectionInServiceLink(org.opentripplanner.graph_builder.issues.MissingProjectionInServiceLink) Quay(org.rutebanken.netex.model.Quay)

Example 5 with ShapePoint

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

the class OtpTransitServiceImplTest method testGetShapePointsForShapeId.

@Test
public void testGetShapePointsForShapeId() {
    List<ShapePoint> shapePoints = subject.getShapePointsForShapeId(new FeedScopedId("Z", "5"));
    assertEquals("[#1 (41,-72), #2 (41,-72), #3 (40,-72), #4 (41,-73), #5 (41,-74)]", shapePoints.stream().map(OtpTransitServiceImplTest::toString).collect(toList()).toString());
}
Also used : ShapePoint(org.opentripplanner.model.ShapePoint) FeedScopedId(org.opentripplanner.model.FeedScopedId) Test(org.junit.Test)

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