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

org.opentripplanner.ext.vectortiles.layers.stations.StationsLayerBuilder Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.ext.vectortiles.layers.stations;

import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;
import org.opentripplanner.common.geometry.GeometryUtils;
import org.opentripplanner.ext.vectortiles.LayerBuilder;
import org.opentripplanner.ext.vectortiles.PropertyMapper;
import org.opentripplanner.ext.vectortiles.VectorTilesResource;
import org.opentripplanner.model.Station;
import org.opentripplanner.routing.graph.Graph;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class StationsLayerBuilder extends LayerBuilder {
  enum MapperType { Digitransit }

  static Map>> mappers = Map.of(
      MapperType.Digitransit, DigitransitStationPropertyMapper::create
  );

  private final Graph graph;

  public StationsLayerBuilder(Graph graph, VectorTilesResource.LayerParameters layerParameters) {
    super(
        layerParameters.name(),
        mappers.get(MapperType.valueOf(layerParameters.mapper())).apply(graph)
    );
    this.graph = graph;
  }

  protected List getGeometries(Envelope query) {
    return graph.getStations().stream().map(station -> {
      Coordinate coordinate = station.getCoordinate().asJtsCoordinate();
      Point point = GeometryUtils.getGeometryFactory().createPoint(coordinate);
      point.setUserData(station);
      return point;
    }).collect(Collectors.toList());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy