Search in sources :

Example 1 with VertexShapeError

use of org.opentripplanner.graph_builder.annotation.VertexShapeError in project OpenTripPlanner by opentripplanner.

the class CheckGeometryModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    for (Vertex gv : graph.getVertices()) {
        if (Double.isNaN(gv.getCoordinate().x) || Double.isNaN(gv.getCoordinate().y)) {
            LOG.warn("Vertex " + gv + " has NaN location; this will cause doom.");
            LOG.warn(graph.addBuilderAnnotation(new BogusVertexGeometry(gv)));
        }
        // TODO: This was filtered to EdgeNarratives before EdgeNarrative removal
        for (Edge e : gv.getOutgoing()) {
            Geometry g = e.getGeometry();
            if (g == null) {
                continue;
            }
            for (Coordinate c : g.getCoordinates()) {
                if (Double.isNaN(c.x) || Double.isNaN(c.y)) {
                    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
                }
            }
            if (e instanceof HopEdge) {
                Coordinate edgeStartCoord = e.getFromVertex().getCoordinate();
                Coordinate edgeEndCoord = e.getToVertex().getCoordinate();
                Coordinate[] geometryCoordinates = g.getCoordinates();
                if (geometryCoordinates.length < 2) {
                    LOG.warn(graph.addBuilderAnnotation(new BogusEdgeGeometry(e)));
                    continue;
                }
                Coordinate geometryStartCoord = geometryCoordinates[0];
                Coordinate geometryEndCoord = geometryCoordinates[geometryCoordinates.length - 1];
                if (SphericalDistanceLibrary.distance(edgeStartCoord, geometryStartCoord) > MAX_VERTEX_SHAPE_ERROR) {
                    LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
                } else if (SphericalDistanceLibrary.distance(edgeEndCoord, geometryEndCoord) > MAX_VERTEX_SHAPE_ERROR) {
                    LOG.warn(graph.addBuilderAnnotation(new VertexShapeError(e)));
                }
            }
        }
    }
}
Also used : BogusEdgeGeometry(org.opentripplanner.graph_builder.annotation.BogusEdgeGeometry) BogusVertexGeometry(org.opentripplanner.graph_builder.annotation.BogusVertexGeometry) Geometry(com.vividsolutions.jts.geom.Geometry) Vertex(org.opentripplanner.routing.graph.Vertex) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) Coordinate(com.vividsolutions.jts.geom.Coordinate) BogusEdgeGeometry(org.opentripplanner.graph_builder.annotation.BogusEdgeGeometry) VertexShapeError(org.opentripplanner.graph_builder.annotation.VertexShapeError) HopEdge(org.opentripplanner.routing.edgetype.HopEdge) Edge(org.opentripplanner.routing.graph.Edge) BogusVertexGeometry(org.opentripplanner.graph_builder.annotation.BogusVertexGeometry)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 BogusEdgeGeometry (org.opentripplanner.graph_builder.annotation.BogusEdgeGeometry)1 BogusVertexGeometry (org.opentripplanner.graph_builder.annotation.BogusVertexGeometry)1 VertexShapeError (org.opentripplanner.graph_builder.annotation.VertexShapeError)1 HopEdge (org.opentripplanner.routing.edgetype.HopEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 Vertex (org.opentripplanner.routing.graph.Vertex)1