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;
}
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;
}
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());
}
}
}
}
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);
}
}
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());
}
Aggregations