Changeset 26702 in osm for applications/editors/josm/plugins/turnlanes/src/org/openstreetmap
- Timestamp:
- 2011-09-24T13:30:55+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Lane.java
r26192 r26702 67 67 } 68 68 69 private static int getCount(Way w) {70 final String countStr = w.get("lanes");71 72 if (countStr != null) {73 try {74 return Integer.parseInt(countStr);75 } catch (NumberFormatException e) {76 throw UnexpectedDataException.Kind.INVALID_TAG_FORMAT.chuck("lanes", countStr);77 }78 }79 80 throw UnexpectedDataException.Kind.MISSING_TAG.chuck("lanes");81 }82 83 69 static int getRegularCount(Way w, Node end) { 84 final int count = getCount(w); 70 final int count = Utils.parseIntTag(w, "lanes"); 71 final boolean forward = w.lastNode().equals(end); 85 72 86 73 if (w.hasDirectionKeys()) { 87 // TODO check for oneway=-1 88 if (w.lastNode().equals(end)) { 89 return count; 90 } else { 91 return 0; 92 } 74 return getRegularCountOneWay(w, forward, count); 93 75 } else { 94 if (w.lastNode().equals(end)) { 95 return (count + 1) / 2; // round up in direction of end 96 } else { 97 return count / 2; // round down in other direction 98 } 99 } 76 return getRegularCountTwoWay(w, forward, count); 77 } 78 } 79 80 private static int getRegularCountOneWay(Way w, boolean forward, final int count) { 81 if (forward ^ "-1".equals(w.get("oneway"))) { 82 return count; 83 } else { 84 return 0; 85 } 86 } 87 88 private static int getRegularCountTwoWay(Way w, boolean forward, final int count) { 89 if (w.get("lanes:backward") != null) { 90 final int backwardCount = Utils.parseIntTag(w, "lanes:backward"); 91 return forward ? count - backwardCount : backwardCount; 92 } 93 94 if (w.get("lanes:forward") != null) { 95 final int forwardCount = Utils.parseIntTag(w, "lanes:forward"); 96 return forward ? forwardCount : count - forwardCount; 97 } 98 99 // default: round up in forward direction... 100 return forward ? (count + 1) / 2 : count / 2; 100 101 } 101 102 -
applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Utils.java
r26154 r26702 20 20 21 21 public class Utils { 22 private static final Set<String> ROAD_HIGHWAY_VALUES = Collections.unmodifiableSet(new HashSet<String>(Arrays .asList(23 "motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary ", "secondary_link",24 "tertiary", "residential", "unclassified", "road", "living_street", "service ", "track", "pedestrian", "raceway",25 "services"))); 22 private static final Set<String> ROAD_HIGHWAY_VALUES = Collections.unmodifiableSet(new HashSet<String>(Arrays 23 .asList("motorway", "motorway_link", "trunk", "trunk_link", "primary", "primary_link", "secondary", 24 "secondary_link", "tertiary", "residential", "unclassified", "road", "living_street", "service", 25 "track", "pedestrian", "raceway", "services"))); 26 26 27 27 public static boolean isRoad(Way w) { … … 144 144 * 145 145 * @param ways 146 * ways to be ordered 146 * ways to be ordered 147 147 * @param nodes 148 * start/end nodes 148 * start/end nodes 149 149 * @return 150 150 * @throws IllegalArgumentException 151 * if the ways can't be ordered 151 * if the ways can't be ordered 152 152 */ 153 153 public static List<Route> orderWays(Iterable<Way> ways, Iterable<Node> nodes) { … … 210 210 for (Road r : via) { 211 211 final Iterable<Route.Segment> segments = r.getRoute().getFirstSegment().getWay().isFirstLastNode(n) ? r 212 .getRoute().getSegments() : CollectionUtils.reverse(r.getRoute().getSegments()); 212 .getRoute().getSegments() : CollectionUtils.reverse(r.getRoute().getSegments()); 213 213 214 214 for (Route.Segment s : segments) { … … 223 223 return result; 224 224 } 225 226 public static int parseIntTag(OsmPrimitive primitive, String tag) { 227 final String value = primitive.get(tag); 228 229 if (value != null) { 230 try { 231 return Integer.parseInt(value); 232 } catch (NumberFormatException e) { 233 throw UnexpectedDataException.Kind.INVALID_TAG_FORMAT.chuck(tag, value); 234 } 235 } 236 237 throw UnexpectedDataException.Kind.MISSING_TAG.chuck(tag); 238 } 225 239 }
Note:
See TracChangeset
for help on using the changeset viewer.