All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.ext.transmodelapi.mapping.GeometryMapper Maven / Gradle / Ivy

package org.opentripplanner.ext.transmodelapi.mapping;

import java.util.ArrayList;
import java.util.List;
import org.opentripplanner.ext.transmodelapi.model.util.EncodedPolylineBeanWithStops;
import org.opentripplanner.transit.model.network.TripPattern;
import org.opentripplanner.util.PolylineEncoder;

public class GeometryMapper {

  /**
   * Based Trip Pattern, create a list of geometries for each stop-to-stop section in the pattern
   */
  public static List mapStopToStopGeometries(
    TripPattern tripPattern
  ) {
    var stopToStopGeometries = new ArrayList();

    for (int i = 0; i < tripPattern.numberOfStops() - 1; i++) {
      var startLocation = tripPattern.getStop(i);
      var endLocation = tripPattern.getStop(i + 1);
      var geometry = PolylineEncoder.encodeGeometry(tripPattern.getHopGeometry(i));

      var stopToStopGeometry = new EncodedPolylineBeanWithStops(
        startLocation,
        endLocation,
        geometry
      );

      stopToStopGeometries.add(stopToStopGeometry);
    }

    return stopToStopGeometries;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy