Ignore:
Timestamp:
2011-09-24T13:30:55+02:00 (13 years ago)
Author:
benshu
Message:
  • lanes:backward and lanes:forward as well as oneway=-1 are now honored (#josm6874)
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  
    6767    }
    6868   
    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    
    8369    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);
    8572       
    8673        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);
    9375        } 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;
    100101    }
    101102   
  • applications/editors/josm/plugins/turnlanes/src/org/openstreetmap/josm/plugins/turnlanes/model/Utils.java

    r26154 r26702  
    2020
    2121public 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")));
    2626   
    2727    public static boolean isRoad(Way w) {
     
    144144     *
    145145     * @param ways
    146      *          ways to be ordered
     146     *            ways to be ordered
    147147     * @param nodes
    148      *          start/end nodes
     148     *            start/end nodes
    149149     * @return
    150150     * @throws IllegalArgumentException
    151      *           if the ways can't be ordered
     151     *             if the ways can't be ordered
    152152     */
    153153    public static List<Route> orderWays(Iterable<Way> ways, Iterable<Node> nodes) {
     
    210210        for (Road r : via) {
    211211            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());
    213213           
    214214            for (Route.Segment s : segments) {
     
    223223        return result;
    224224    }
     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    }
    225239}
Note: See TracChangeset for help on using the changeset viewer.