Search in sources :

Example 1 with OSMWithTags

use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.

the class TestTemplateLibrary method testTemplate.

public void testTemplate() {
    OSMWithTags osmTags = new OSMWithTags();
    osmTags.addTag("note", "Note EN");
    osmTags.addTag("description:fr", "Description FR");
    osmTags.addTag("wheelchair:description", "Wheelchair description EN");
    osmTags.addTag("wheelchair:description:fr", "Wheelchair description FR");
    assertEquals(null, TemplateLibrary.generate(null, osmTags));
    assertEquals("", TemplateLibrary.generate("", osmTags));
    assertEquals("Static text", TemplateLibrary.generate("Static text", osmTags));
    assertEquals("Note: Note EN", TemplateLibrary.generate("Note: {note}", osmTags));
    assertEquals("Inexistant: ", TemplateLibrary.generate("Inexistant: {foobar:description}", osmTags));
    assertEquals("Wheelchair note: Wheelchair description EN", TemplateLibrary.generate("Wheelchair note: {wheelchair:description}", osmTags));
    assertEquals(null, TemplateLibrary.generateI18N(null, osmTags));
    Map<String, String> expected = new HashMap<>();
    expected.put(null, "");
    assertEquals(expected, TemplateLibrary.generateI18N("", osmTags));
    expected.clear();
    expected.put(null, "Note: Note EN");
    assertEquals(expected, TemplateLibrary.generateI18N("Note: {note}", osmTags));
    expected.clear();
    expected.put(null, "Desc: Description FR");
    expected.put("fr", "Desc: Description FR");
    assertEquals(expected, TemplateLibrary.generateI18N("Desc: {description}", osmTags));
    expected.clear();
    expected.put(null, "Note: Note EN, Wheelchair description EN");
    expected.put("fr", "Note: Note EN, Wheelchair description FR");
    assertEquals(expected, TemplateLibrary.generateI18N("Note: {note}, {wheelchair:description}", osmTags));
    expected.clear();
    expected.put(null, "Note: Note EN, Wheelchair description EN, ");
    expected.put("fr", "Note: Note EN, Wheelchair description FR, ");
    assertEquals(expected, TemplateLibrary.generateI18N("Note: {note}, {wheelchair:description}, {foobar:description}", osmTags));
}
Also used : HashMap(java.util.HashMap) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags)

Example 2 with OSMWithTags

use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createSegments.

private void createSegments(OSMNode fromNode, OSMNode toNode, IntersectionVertex startEndpoint, IntersectionVertex endEndpoint, Collection<Area> areas, AreaEdgeList edgeList, Set<Edge> edges) {
    List<Area> intersects = new ArrayList<Area>();
    Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    LineString line = geometryFactory.createLineString(coordinates);
    for (Area area : areas) {
        MultiPolygon polygon = area.toJTSMultiPolygon();
        Geometry intersection = polygon.intersection(line);
        if (intersection.getLength() > 0.000001) {
            intersects.add(area);
        }
    }
    if (intersects.size() == 0) {
        // apparently our intersection here was bogus
        return;
    }
    // do we need to recurse?
    if (intersects.size() == 1) {
        Area area = intersects.get(0);
        OSMWithTags areaEntity = area.parent;
        StreetTraversalPermission areaPermissions = OSMFilter.getPermissionsForEntity(areaEntity, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
        float carSpeed = wayPropertySet.getCarSpeedForWay(areaEntity, false);
        double length = SphericalDistanceLibrary.distance(startEndpoint.getCoordinate(), endEndpoint.getCoordinate());
        int cls = StreetEdge.CLASS_OTHERPATH;
        cls |= OSMFilter.getStreetClasses(areaEntity);
        String label = "way (area) " + areaEntity.getId() + " from " + startEndpoint.getLabel() + " to " + endEndpoint.getLabel();
        I18NString name = __handler.getNameForWay(areaEntity, label);
        AreaEdge street = edgeFactory.createAreaEdge(startEndpoint, endEndpoint, line, name, length, areaPermissions, false, edgeList);
        street.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            street.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            street.setWheelchairAccessible(false);
        }
        street.setStreetClass(cls);
        edges.add(street);
        label = "way (area) " + areaEntity.getId() + " from " + endEndpoint.getLabel() + " to " + startEndpoint.getLabel();
        name = __handler.getNameForWay(areaEntity, label);
        AreaEdge backStreet = edgeFactory.createAreaEdge(endEndpoint, startEndpoint, (LineString) line.reverse(), name, length, areaPermissions, true, edgeList);
        backStreet.setCarSpeed(carSpeed);
        if (!areaEntity.hasTag("name") && !areaEntity.hasTag("ref")) {
            backStreet.setHasBogusName(true);
        }
        if (areaEntity.isTagFalse("wheelchair")) {
            backStreet.setWheelchairAccessible(false);
        }
        backStreet.setStreetClass(cls);
        edges.add(backStreet);
        WayProperties wayData = wayPropertySet.getDataForWay(areaEntity);
        __handler.applyWayProperties(street, backStreet, wayData, areaEntity);
    } else {
        // take the part that intersects with the start vertex
        Coordinate startCoordinate = startEndpoint.getCoordinate();
        Point startPoint = geometryFactory.createPoint(startCoordinate);
        for (Area area : intersects) {
            MultiPolygon polygon = area.toJTSMultiPolygon();
            if (!(polygon.intersects(startPoint) || polygon.getBoundary().intersects(startPoint)))
                continue;
            Geometry lineParts = line.intersection(polygon);
            if (lineParts.getLength() > 0.000001) {
                Coordinate edgeCoordinate = null;
                // this is either a LineString or a MultiLineString (we hope)
                if (lineParts instanceof MultiLineString) {
                    MultiLineString mls = (MultiLineString) lineParts;
                    boolean found = false;
                    for (int i = 0; i < mls.getNumGeometries(); ++i) {
                        LineString segment = (LineString) mls.getGeometryN(i);
                        if (found) {
                            edgeCoordinate = segment.getEndPoint().getCoordinate();
                            break;
                        }
                        if (segment.contains(startPoint) || segment.getBoundary().contains(startPoint)) {
                            found = true;
                            if (segment.getLength() > 0.000001) {
                                edgeCoordinate = segment.getEndPoint().getCoordinate();
                                break;
                            }
                        }
                    }
                } else if (lineParts instanceof LineString) {
                    edgeCoordinate = ((LineString) lineParts).getEndPoint().getCoordinate();
                } else {
                    continue;
                }
                IntersectionVertex newEndpoint = areaBoundaryVertexForCoordinate.get(edgeCoordinate);
                if (newEndpoint == null) {
                    newEndpoint = new IntersectionVertex(graph, "area splitter at " + edgeCoordinate, edgeCoordinate.x, edgeCoordinate.y);
                    areaBoundaryVertexForCoordinate.put(edgeCoordinate, newEndpoint);
                }
                createSegments(fromNode, toNode, startEndpoint, newEndpoint, Arrays.asList(area), edgeList, edges);
                createSegments(fromNode, toNode, newEndpoint, endEndpoint, intersects, edgeList, edges);
                break;
            }
        }
    }
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) I18NString(org.opentripplanner.util.I18NString) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) LineString(com.vividsolutions.jts.geom.LineString) I18NString(org.opentripplanner.util.I18NString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Geometry(com.vividsolutions.jts.geom.Geometry) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission)

Example 3 with OSMWithTags

use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method buildWithVisibility.

public void buildWithVisibility(AreaGroup group, boolean platformEntriesLinking) {
    Set<OSMNode> startingNodes = new HashSet<OSMNode>();
    Set<Vertex> startingVertices = new HashSet<Vertex>();
    Set<Edge> edges = new HashSet<Edge>();
    // create polygon and accumulate nodes for area
    for (Ring ring : group.outermostRings) {
        AreaEdgeList edgeList = new AreaEdgeList();
        // the points corresponding to concave or hole vertices
        // or those linked to ways
        ArrayList<VLPoint> visibilityPoints = new ArrayList<VLPoint>();
        ArrayList<OSMNode> visibilityNodes = new ArrayList<OSMNode>();
        HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
        // and to avoid the numerical problems that they tend to cause
        for (Area area : group.areas) {
            // parameter is true
            if (platformEntriesLinking && "platform".equals(area.parent.getTag("public_transport"))) {
                continue;
            }
            if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
                continue;
            }
            // Add stops from public transit relations into the area
            Collection<OSMNode> nodes = osmdb.getStopsInArea(area.parent);
            if (nodes != null) {
                for (OSMNode node : nodes) {
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
            }
            for (Ring outerRing : area.outermostRings) {
                for (int i = 0; i < outerRing.nodes.size(); ++i) {
                    OSMNode node = outerRing.nodes.get(i);
                    createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
                    addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                }
                for (Ring innerRing : outerRing.holes) {
                    for (int j = 0; j < innerRing.nodes.size(); ++j) {
                        OSMNode node = innerRing.nodes.get(j);
                        createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
                        addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
                    }
                }
            }
        }
        List<OSMNode> nodes = new ArrayList<OSMNode>();
        List<VLPoint> vertices = new ArrayList<VLPoint>();
        accumulateRingNodes(ring, nodes, vertices);
        VLPolygon polygon = makeStandardizedVLPolygon(vertices, nodes, false);
        accumulateVisibilityPoints(ring.nodes, polygon, visibilityPoints, visibilityNodes, false);
        ArrayList<VLPolygon> polygons = new ArrayList<VLPolygon>();
        polygons.add(polygon);
        // holes
        for (Ring innerRing : ring.holes) {
            ArrayList<OSMNode> holeNodes = new ArrayList<OSMNode>();
            vertices = new ArrayList<VLPoint>();
            accumulateRingNodes(innerRing, holeNodes, vertices);
            VLPolygon hole = makeStandardizedVLPolygon(vertices, holeNodes, true);
            accumulateVisibilityPoints(innerRing.nodes, hole, visibilityPoints, visibilityNodes, true);
            nodes.addAll(holeNodes);
            polygons.add(hole);
        }
        Environment areaEnv = new Environment(polygons);
        // areas to prevent way explosion
        if (visibilityPoints.size() > MAX_AREA_NODES) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is too complicated (" + visibilityPoints.size() + " > " + MAX_AREA_NODES);
            continue;
        }
        if (!areaEnv.is_valid(VISIBILITY_EPSILON)) {
            LOG.warn("Area " + group.getSomeOSMObject() + " is not epsilon-valid (epsilon = " + VISIBILITY_EPSILON + ")");
            continue;
        }
        edgeList.setOriginalEdges(ring.toJtsPolygon());
        createNamedAreas(edgeList, ring, group.areas);
        OSMWithTags areaEntity = group.getSomeOSMObject();
        for (int i = 0; i < visibilityNodes.size(); ++i) {
            OSMNode nodeI = visibilityNodes.get(i);
            VisibilityPolygon visibilityPolygon = new VisibilityPolygon(visibilityPoints.get(i), areaEnv, VISIBILITY_EPSILON);
            Polygon poly = toJTSPolygon(visibilityPolygon);
            for (int j = 0; j < visibilityNodes.size(); ++j) {
                OSMNode nodeJ = visibilityNodes.get(j);
                P2<OSMNode> nodePair = new P2<OSMNode>(nodeI, nodeJ);
                if (alreadyAddedEdges.contains(nodePair))
                    continue;
                IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(nodeI, areaEntity);
                IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nodeJ, areaEntity);
                Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
                GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
                LineString line = geometryFactory.createLineString(coordinates);
                if (poly != null && poly.contains(line)) {
                    createSegments(nodeI, nodeJ, startEndpoint, endEndpoint, group.areas, edgeList, edges);
                    if (startingNodes.contains(nodeI)) {
                        startingVertices.add(startEndpoint);
                    }
                    if (startingNodes.contains(nodeJ)) {
                        startingVertices.add(endEndpoint);
                    }
                }
            }
        }
    }
    pruneAreaEdges(startingVertices, edges);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) VLPoint(org.opentripplanner.visibility.VLPoint) OSMNode(org.opentripplanner.openstreetmap.model.OSMNode) VLPolygon(org.opentripplanner.visibility.VLPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) HashSet(java.util.HashSet) P2(org.opentripplanner.common.model.P2) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LinearRing(com.vividsolutions.jts.geom.LinearRing) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) AreaEdgeList(org.opentripplanner.routing.edgetype.AreaEdgeList) VLPolygon(org.opentripplanner.visibility.VLPolygon) Environment(org.opentripplanner.visibility.Environment) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) AreaEdge(org.opentripplanner.routing.edgetype.AreaEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 4 with OSMWithTags

use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.

the class WalkableAreaBuilder method createNamedAreas.

private void createNamedAreas(AreaEdgeList edgeList, Ring ring, Collection<Area> areas) {
    Polygon containingArea = ring.toJtsPolygon();
    for (Area area : areas) {
        Geometry intersection = containingArea.intersection(area.toJTSMultiPolygon());
        if (intersection.getArea() == 0) {
            continue;
        }
        NamedArea namedArea = new NamedArea();
        OSMWithTags areaEntity = area.parent;
        int cls = StreetEdge.CLASS_OTHERPATH;
        cls |= OSMFilter.getStreetClasses(areaEntity);
        namedArea.setStreetClass(cls);
        String id = "way (area) " + areaEntity.getId() + " (splitter linking)";
        I18NString name = __handler.getNameForWay(areaEntity, id);
        namedArea.setName(name);
        WayProperties wayData = wayPropertySet.getDataForWay(areaEntity);
        Double safety = wayData.getSafetyFeatures().first;
        namedArea.setBicycleSafetyMultiplier(safety);
        namedArea.setOriginalEdges(intersection);
        StreetTraversalPermission permission = OSMFilter.getPermissionsForEntity(areaEntity, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
        namedArea.setPermission(permission);
        edgeList.addArea(namedArea);
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) I18NString(org.opentripplanner.util.I18NString) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) NamedArea(org.opentripplanner.routing.edgetype.NamedArea) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) LineString(com.vividsolutions.jts.geom.LineString) I18NString(org.opentripplanner.util.I18NString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) VLPolygon(org.opentripplanner.visibility.VLPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) VisibilityPolygon(org.opentripplanner.visibility.VisibilityPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point) VLPoint(org.opentripplanner.visibility.VLPoint)

Example 5 with OSMWithTags

use of org.opentripplanner.openstreetmap.model.OSMWithTags in project OpenTripPlanner by opentripplanner.

the class TestOpenStreetMapGraphBuilder method testCreativeNaming.

@Test
public void testCreativeNaming() {
    OSMWithTags way = new OSMWay();
    way.addTag("highway", "footway");
    way.addTag("cycleway", "lane");
    way.addTag("access", "no");
    CreativeNamer namer = new CreativeNamer();
    namer.setCreativeNamePattern("Highway with cycleway {cycleway} and access {access} and morx {morx}");
    assertEquals("Highway with cycleway lane and access no and morx ", namer.generateCreativeName(way).toString());
}
Also used : OSMWay(org.opentripplanner.openstreetmap.model.OSMWay) OSMWithTags(org.opentripplanner.openstreetmap.model.OSMWithTags) Test(org.junit.Test)

Aggregations

OSMWithTags (org.opentripplanner.openstreetmap.model.OSMWithTags)7 LineString (com.vividsolutions.jts.geom.LineString)3 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Point (com.vividsolutions.jts.geom.Point)3 Test (org.junit.Test)3 NamedArea (org.opentripplanner.routing.edgetype.NamedArea)3 VLPoint (org.opentripplanner.visibility.VLPoint)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 Polygon (com.vividsolutions.jts.geom.Polygon)2 ArrayList (java.util.ArrayList)2 OSMWay (org.opentripplanner.openstreetmap.model.OSMWay)2 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)2 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)2 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)2 I18NString (org.opentripplanner.util.I18NString)2 VLPolygon (org.opentripplanner.visibility.VLPolygon)2 VisibilityPolygon (org.opentripplanner.visibility.VisibilityPolygon)2