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);
}
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;
}
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;
}
}
}
}
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);
}
}
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);
}
Aggregations