Permalink
Browse files

Merge branch 'incrementLevels' into TStopLinking

Conflicts:
	opentripplanner-graph-builder/src/main/java/org/opentripplanner/graph_builder/impl/osm/OpenStreetMapGraphBuilderImpl.java
  • Loading branch information...
2 parents 78b55e1 + b92f967 commit 6398c2a476876523782a0ac6cb63a667bcee511d @abyrd abyrd committed Feb 28, 2012
@@ -28,6 +28,7 @@
import org.opentripplanner.common.TurnRestrictionType;
import org.opentripplanner.common.model.P2;
import org.opentripplanner.graph_builder.model.osm.OSMLevel;
+import org.opentripplanner.graph_builder.model.osm.OSMLevel.Source;
import org.opentripplanner.graph_builder.model.osm.OSMNode;
import org.opentripplanner.graph_builder.model.osm.OSMRelation;
import org.opentripplanner.graph_builder.model.osm.OSMRelationMember;
@@ -465,9 +466,8 @@ private void getLevelsForWay(OSMWay way) {
levelName = way.getTag("layer");
source = OSMLevel.Source.LAYER_TAG;
}
-// if (noZeroLevels && intLevel >= 0) ...
if (levelName != null) {
- level = OSMLevel.fromString(levelName, source);
+ level = OSMLevel.fromString(levelName, source, noZeroLevels);
}
wayLevels.put(way, level);
}
@@ -763,7 +763,7 @@ private void processRestriction(OSMRelation relation) {
* @param relation
*/
private void processLevelMap(OSMRelation relation) {
- Map<String, OSMLevel> levels = OSMLevel.mapFromSpecList(relation.getTag("levels"));
+ Map<String, OSMLevel> levels = OSMLevel.mapFromSpecList(relation.getTag("levels"), Source.LEVEL_MAP, true);
for (OSMRelationMember member : relation.getMembers()) {
if ("way".equals(member.getType()) && _ways.containsKey(member.getRef())) {
OSMWay way = _ways.get(member.getRef());
@@ -28,12 +28,12 @@
private static Logger _log = LoggerFactory.getLogger(OSMLevel.class);
public static final Pattern RANGE_PATTERN = Pattern.compile("^[0-9]+\\-[0-9]+$");
- public static final float METERS_PER_FLOOR = 3;
- public static final OSMLevel DEFAULT = fromString("", Source.NONE);
- public final int floorNumber;
- public final float altitudeMeters;
- public final String shortName;
- public final String longName;
+ public static final double METERS_PER_FLOOR = 3;
+ public static final OSMLevel DEFAULT = fromString("", Source.NONE, false);
+ public final int floorNumber; // 0-based
+ public final double altitudeMeters;
+ public final String shortName; // localized (potentially 1-based)
+ public final String longName; // localized (potentially 1-based)
public final Source source;
public enum Source {
@@ -44,7 +44,7 @@
NONE
}
- public OSMLevel(int floorNumber, float altitudeMeters, String shortName, String longName, Source source) {
+ public OSMLevel(int floorNumber, double altitudeMeters, String shortName, String longName, Source source) {
this.floorNumber = floorNumber;
this.altitudeMeters = altitudeMeters;
this.shortName = shortName;
@@ -56,17 +56,15 @@ public OSMLevel(int floorNumber, float altitudeMeters, String shortName, String
* makes an OSMLevel from one of the semicolon-separated fields in an OSM
* level map relation's levels= tag.
*/
- public static OSMLevel fromString (String spec, Source source) {
+ public static OSMLevel fromString (String spec, Source source, boolean incrementNonNegative) {
/* extract any altitude information after the @ character */
- float altitude = 0;
+ Double altitude = null;
int lastIndexAt = spec.lastIndexOf('@');
if (lastIndexAt != -1) {
try {
- altitude = Integer.parseInt(spec.substring(lastIndexAt + 1));
- } catch (NumberFormatException e3) {
- altitude = 0;
- }
+ altitude = Double.parseDouble(spec.substring(lastIndexAt + 1));
+ } catch (NumberFormatException e) {}
spec = spec.substring(0, lastIndexAt);
}
@@ -82,25 +80,52 @@ public static OSMLevel fromString (String spec, Source source) {
shortName = longName = spec;
}
- /* try to parse a floor number out of names and altitude */
- int floorNumber = 0;
+ /* try to parse a floor number out of names */
+ Integer floorNumber = null;
try {
+ floorNumber = Integer.parseInt(longName);
+ if (incrementNonNegative) {
+ if (source == Source.LEVEL_MAP) {
+ if (floorNumber >= 1)
+ floorNumber -= 1; // level maps are localized, floor numbers are 0-based
+ } else {
+ if (floorNumber >= 0)
+ longName = Integer.toString(floorNumber + 1); // level and layer tags are 0-based
+ }
+ }
+ } catch (NumberFormatException e) {}
+ try {
+ // short name takes precedence over long name for floor numbering
floorNumber = Integer.parseInt(shortName);
- } catch (NumberFormatException e) {
- try {
- floorNumber = Integer.parseInt(longName);
- } catch (NumberFormatException e2) {
- _log.warn("Could not determine ordinality of layer {}. " +
- "Elevators will work, but costing may be incorrect. " +
- "A level map should be used in this situation.", spec);
- floorNumber = (int)(altitude); // / METERS_PER_FLOOR);
+ if (incrementNonNegative) {
+ if (source == Source.LEVEL_MAP) {
+ if (floorNumber >= 1)
+ floorNumber -= 1; // level maps are localized, floor numbers are 0-based
+ } else {
+ if (floorNumber >= 0)
+ shortName = Integer.toString(floorNumber + 1); // level and layer tags are 0-based
+ }
}
- }
+ } catch (NumberFormatException e) {}
+ /* fall back on altitude when necessary */
+ if (floorNumber == null && altitude != null) {
+ floorNumber = (int)(altitude / METERS_PER_FLOOR);
+ _log.warn("Could not determine floor number for layer {}. Guessed {} (0-based) from altitude.", spec, floorNumber);
+ }
+
+ /* set default values when parsing failed */
+ if (altitude == null) {
+ altitude = 0.0;
+ }
+ if (floorNumber == null) {
+ floorNumber = 0;
+ _log.warn("Could not infer floor number for layer '{}'. Vertical movement will still be possible, but elevator cost might be incorrect. Consider an OSM level map.", spec);
+ }
return new OSMLevel(floorNumber, altitude, shortName, longName, source);
}
- public static List<OSMLevel> fromSpecList (String specList) {
+ public static List<OSMLevel> fromSpecList (String specList, Source source, boolean incrementNonNegative) {
List<String> levelSpecs = new ArrayList<String>();
@@ -121,14 +146,14 @@ public static OSMLevel fromString (String spec, Source source) {
/* build an OSMLevel for each level spec in the list */
List<OSMLevel> levels = new ArrayList<OSMLevel>();
for (String spec : levelSpecs) {
- levels.add(fromString(spec, Source.LEVEL_MAP));
+ levels.add(fromString(spec, source, incrementNonNegative));
}
return levels;
}
- public static Map<String, OSMLevel> mapFromSpecList (String specList) {
+ public static Map<String, OSMLevel> mapFromSpecList (String specList, Source source, boolean incrementNonNegative) {
Map<String, OSMLevel> map = new HashMap<String, OSMLevel>();
- for (OSMLevel level : fromSpecList(specList)) {
+ for (OSMLevel level : fromSpecList(specList, source, incrementNonNegative)) {
map.put(level.shortName, level);
}
return map;

0 comments on commit 6398c2a

Please sign in to comment.