Search in sources :

Example 1 with ConformingDelaunayTriangulator

use of com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator in project graphhopper by graphhopper.

the class FakeWalkNetworkBuilder method buildWalkNetwork.

static void buildWalkNetwork(Collection<GTFSFeed> feeds, GraphHopperStorage graph, PtFlagEncoder encoder, DistanceCalc distCalc) {
    Collection<ConstraintVertex> sites = new ArrayList<>();
    Map<Vertex, Integer> vertex2nodeId = new HashMap<>();
    feeds.stream().flatMap(feed -> feed.stops.values().stream()).forEach(stop -> {
        int i = graph.getNodes();
        graph.getNodeAccess().setNode(i++, stop.stop_lat, stop.stop_lon);
        ConstraintVertex site = new ConstraintVertex(new Coordinate(stop.stop_lon, stop.stop_lat));
        sites.add(site);
        vertex2nodeId.put(site, i - 1);
    });
    ConformingDelaunayTriangulator conformingDelaunayTriangulator = new ConformingDelaunayTriangulator(sites, 0.0);
    conformingDelaunayTriangulator.setConstraints(new ArrayList(), new ArrayList());
    conformingDelaunayTriangulator.formInitialDelaunay();
    QuadEdgeSubdivision tin = conformingDelaunayTriangulator.getSubdivision();
    List<QuadEdge> edges = tin.getPrimaryEdges(false);
    for (QuadEdge edge : edges) {
        EdgeIteratorState ghEdge = graph.edge(vertex2nodeId.get(edge.orig()), vertex2nodeId.get(edge.dest()));
        double distance = distCalc.calcDist(edge.orig().getY(), edge.orig().getX(), edge.dest().getY(), edge.dest().getX());
        ghEdge.setDistance(distance);
        ghEdge.setFlags(encoder.setSpeed(ghEdge.getFlags(), 5.0));
        ghEdge.setFlags(encoder.setAccess(ghEdge.getFlags(), true, true));
    }
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Coordinate(com.vividsolutions.jts.geom.Coordinate) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) java.util(java.util) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) GTFSFeed(com.conveyal.gtfs.GTFSFeed) DistanceCalc(com.graphhopper.util.DistanceCalc) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Aggregations

GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 DistanceCalc (com.graphhopper.util.DistanceCalc)1 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ConformingDelaunayTriangulator (com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator)1 ConstraintVertex (com.vividsolutions.jts.triangulate.ConstraintVertex)1 QuadEdge (com.vividsolutions.jts.triangulate.quadedge.QuadEdge)1 QuadEdgeSubdivision (com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision)1 Vertex (com.vividsolutions.jts.triangulate.quadedge.Vertex)1 java.util (java.util)1