Search in sources :

Example 1 with I18NString

use of org.opentripplanner.util.I18NString in project OpenTripPlanner by opentripplanner.

the class PlatformLinker method makePlatformEdges.

private void makePlatformEdges(Area area, OsmVertex from, OsmVertex to) {
    Coordinate[] coordinates = new Coordinate[] { from.getCoordinate(), to.getCoordinate() };
    GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
    LineString line = geometryFactory.createLineString(coordinates);
    double length = SphericalDistanceLibrary.distance(from.getCoordinate(), to.getCoordinate());
    StreetTraversalPermission areaPermissions = OSMFilter.getPermissionsForEntity(area.parent, StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);
    String labelFromTo = "way (area) " + area.parent.getId() + " from " + from.getLabel() + " to " + to.getLabel();
    I18NString nameFromTo = getNameForWay(area.parent, labelFromTo);
    factory.createEdge(from, to, line, nameFromTo, length, areaPermissions, true);
    String labelToFrom = "way (area) " + area.parent.getId() + " from " + to.getLabel() + " to " + from.getLabel();
    I18NString nameToFrom = getNameForWay(area.parent, labelToFrom);
    factory.createEdge(to, from, line, nameToFrom, length, areaPermissions, true);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) I18NString(org.opentripplanner.util.I18NString) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) StreetTraversalPermission(org.opentripplanner.routing.edgetype.StreetTraversalPermission) LineString(com.vividsolutions.jts.geom.LineString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) I18NString(org.opentripplanner.util.I18NString)

Example 2 with I18NString

use of org.opentripplanner.util.I18NString in project OpenTripPlanner by opentripplanner.

the class StreetVertex method getIntersectionName.

/**
 * Creates intersection name out of all outgoing names
 *
 * This can be:
 *  - name of the street if it is only 1
 *  - unnamedStreed (localized in requested language) if it doesn't have a name
 *  - corner of 0 and 1 (localized corner of zero and first street in the corner)
 *
 * @param locale Wanted locale
 * @return already localized street names and non-localized corner of x and unnamedStreet
 */
public I18NString getIntersectionName(Locale locale) {
    I18NString calculatedName = null;
    // generate names for corners when no name was given
    Set<String> uniqueNameSet = new HashSet<String>();
    for (Edge e : getOutgoing()) {
        if (e instanceof StreetEdge) {
            uniqueNameSet.add(e.getName(locale));
        }
    }
    List<String> uniqueNames = new ArrayList<String>(uniqueNameSet);
    if (uniqueNames.size() > 1) {
        calculatedName = new LocalizedString("corner", new String[] { uniqueNames.get(0), uniqueNames.get(1) });
    } else if (uniqueNames.size() == 1) {
        calculatedName = new NonLocalizedString(uniqueNames.get(0));
    } else {
        calculatedName = new LocalizedString("unnamedStreet", (String[]) null);
    }
    return calculatedName;
}
Also used : I18NString(org.opentripplanner.util.I18NString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) I18NString(org.opentripplanner.util.I18NString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) LocalizedString(org.opentripplanner.util.LocalizedString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 3 with I18NString

use of org.opentripplanner.util.I18NString 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 4 with I18NString

use of org.opentripplanner.util.I18NString 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 I18NString

use of org.opentripplanner.util.I18NString in project OpenTripPlanner by opentripplanner.

the class AlertsUpdateHandler method deBuffer.

/**
 * convert a protobuf TranslatedString to a OTP TranslatedString
 *
 * @return A TranslatedString containing the same information as the input
 */
private I18NString deBuffer(GtfsRealtime.TranslatedString input) {
    Map<String, String> translations = new HashMap<>();
    for (GtfsRealtime.TranslatedString.Translation translation : input.getTranslationList()) {
        String language = translation.getLanguage();
        String string = translation.getText();
        translations.put(language, string);
    }
    return translations.isEmpty() ? null : TranslatedString.getI18NString(translations);
}
Also used : TranslatedString(org.opentripplanner.util.TranslatedString) I18NString(org.opentripplanner.util.I18NString) TranslatedString(org.opentripplanner.util.TranslatedString)

Aggregations

I18NString (org.opentripplanner.util.I18NString)5 LineString (com.vividsolutions.jts.geom.LineString)3 StreetTraversalPermission (org.opentripplanner.routing.edgetype.StreetTraversalPermission)3 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)2 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)2 Point (com.vividsolutions.jts.geom.Point)2 OSMWithTags (org.opentripplanner.openstreetmap.model.OSMWithTags)2 NamedArea (org.opentripplanner.routing.edgetype.NamedArea)2 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)2 VLPoint (org.opentripplanner.visibility.VLPoint)2 Polygon (com.vividsolutions.jts.geom.Polygon)1 ArrayList (java.util.ArrayList)1 AreaEdge (org.opentripplanner.routing.edgetype.AreaEdge)1 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)1 Edge (org.opentripplanner.routing.graph.Edge)1 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)1 LocalizedString (org.opentripplanner.util.LocalizedString)1