Search in sources :

Example 1 with LinkSequenceProjection_VersionStructure

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());
            }
        }
    }
}
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 2 with LinkSequenceProjection_VersionStructure

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);
}
Also used : LinkSequenceProjection(org.rutebanken.netex.model.LinkSequenceProjection) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) Projections_RelStructure(org.rutebanken.netex.model.Projections_RelStructure) LinkSequenceProjection_VersionStructure(org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure) ServiceLink(org.rutebanken.netex.model.ServiceLink) LineStringType(net.opengis.gml._3.LineStringType) BigDecimal(java.math.BigDecimal)

Aggregations

LinkSequenceProjection_VersionStructure (org.rutebanken.netex.model.LinkSequenceProjection_VersionStructure)2 BigDecimal (java.math.BigDecimal)1 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)1 LineStringType (net.opengis.gml._3.LineStringType)1 MutableDouble (org.apache.commons.lang3.mutable.MutableDouble)1 ShapePoint (org.opentripplanner.model.ShapePoint)1 LinkSequenceProjection (org.rutebanken.netex.model.LinkSequenceProjection)1 Projections_RelStructure (org.rutebanken.netex.model.Projections_RelStructure)1 ServiceLink (org.rutebanken.netex.model.ServiceLink)1