use of org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure 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.rutebanken.netex.model.LinkSequenceProjection_VersionStructure in project OpenTripPlanner by opentripplanner.
the class ServiceLinkMapperTest method createServiceLink.
private ServiceLink createServiceLink(String id, double distance, Double[] coordinates) {
DirectPositionListType directPositionListType = new DirectPositionListType().withValue(coordinates);
LinkSequenceProjection linkSequenceProjection = new LinkSequenceProjection().withLineString(new LineStringType().withPosList(directPositionListType));
JAXBElement<LinkSequenceProjection_VersionStructure> linkSequenceProjection_versionStructure = MappingSupport.createJaxbElement(linkSequenceProjection);
Projections_RelStructure projections_relStructure = new Projections_RelStructure().withProjectionRefOrProjection(linkSequenceProjection_versionStructure);
return new ServiceLink().withId(id).withDistance(new BigDecimal(distance)).withProjections(projections_relStructure);
}
Aggregations