Changeset 33433 in osm


Ignore:
Timestamp:
2017-07-10T11:06:12+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm14977 - unnamed stops handled

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SortPTStopsAction.java

    r33432 r33433  
    5151        for (int i = 0; i < members.size(); i++) {
    5252            RelationMember rm = members.get(i);
    53             String role = rm.getRole();
    54             if (role != null && (role.startsWith("platform") || role.startsWith("stop")))
     53            if (PTStop.isPTPlatform(rm) || PTStop.isPTStopPosition(rm))
    5554                stops.add(rm);
    5655            else {
     
    6261
    6362        Map<String, PTStop> stopsByName = new HashMap<>();
     63        List<PTStop> unnamed = new ArrayList<>();
    6464        stops.forEach(rm -> {
    6565            String name = getStopName(rm.getMember());
     
    6969                else
    7070                    stopsByName.get(name).addStopElement(rm);
     71            } else {
     72                unnamed.add(new PTStop(rm));
    7173            }
    7274        });
     
    7678        Map<Way, List<PTStop>> wayStop = new HashMap<>();
    7779        ptstops.forEach(stop -> {
     80            Way way = assigner.get(stop);
     81            if (!wayStop.containsKey(way))
     82                wayStop.put(way, new ArrayList<PTStop>());
     83            wayStop.get(way).add(stop);
     84        });
     85
     86        unnamed.forEach(stop -> {
    7887            Way way = assigner.get(stop);
    7988            if (!wayStop.containsKey(way))
     
    103112    private static String getStopName(OsmPrimitive p) {
    104113        for (Relation ref : Utils.filteredCollection(p.getReferrers(), Relation.class)) {
    105             if (ref.hasTag("type", "public_transport") && ref.hasTag("public_transport", "stop_area") && ref.getName() != null) {
     114            if (ref.hasTag("type", "public_transport")
     115                    && ref.hasTag("public_transport", "stop_area")
     116                    && ref.getName() != null) {
    106117                return ref.getName();
    107118            }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java

    r33432 r33433  
    4242     *             used in the plugin
    4343     */
    44     public PTStop(RelationMember other) throws IllegalArgumentException {
     44    public PTStop(RelationMember other) {
    4545
    4646        super(other);
    4747
    48         // if ((other.hasRole("stop") || other.hasRole("stop_entry_only") ||
    49         // other.hasRole("stop_exit_only"))
    50         // && other.getType().equals(OsmPrimitiveType.NODE)) {
    51 
    52         if (other.getMember().hasTag("public_transport", "stop_position")) {
    53 
    54             this.stopPosition = other.getNode();
    55             this.name = stopPosition.get("name");
    56             setStopPositionRM(other);
    57             // } else if (other.getRole().equals("platform") ||
    58             // other.getRole().equals("platform_entry_only")
    59             // || other.getRole().equals("platform_exit_only")) {
    60         } else if (other.getMember().hasTag("highway", "bus_stop")
    61                 || other.getMember().hasTag("public_transport", "platform")
    62                 || other.getMember().hasTag("highway", "platform") || other.getMember().hasTag("railway", "platform")) {
    63 
    64             this.platform = other.getMember();
    65             this.name = platform.get("name");
    66             setPlatformRM(other);
    67 
     48        if (isPTStopPosition(other)) {
     49            stopPosition = other.getNode();
     50            name = stopPosition.get("name");
     51            setStopPositionRM(new RelationMember("stop", other.getMember()));
     52        } else if (isPTPlatform(other)) {
     53            platform = other.getMember();
     54            name = platform.get("name");
     55            setPlatformRM(new RelationMember("platform", other.getMember()));
    6856        } else {
    6957            throw new IllegalArgumentException(
    7058                    "The RelationMember type does not match its role " + other.getMember().getName());
    7159        }
    72 
    7360    }
    7461
     
    8572    public boolean addStopElement(RelationMember member) {
    8673
    87         // each element is only allowed once per stop
    88 
    89         // add stop position:
    90         // if (member.hasRole("stop") || member.hasRole("stop_entry_only") ||
    91         // member.hasRole("stop_exit_only")) {
    92         if (member.getMember().hasTag("public_transport", "stop_position")) {
    93             if (member.getType().equals(OsmPrimitiveType.NODE) && stopPosition == null) {
    94                 this.stopPosition = member.getNode();
    95                 stopPositionRM = member;
    96                 return true;
    97             }
    98         }
    99 
    100         // add platform:
    101         // if (member.getRole().equals("platform") ||
    102         // member.getRole().equals("platform_entry_only")
    103         // || member.getRole().equals("platform_exit_only")) {
    104         if (member.getMember().hasTag("highway", "bus_stop")
    105                 || member.getMember().hasTag("public_transport", "platform")
    106                 || member.getMember().hasTag("highway", "platform")
    107                 || member.getMember().hasTag("railway", "platform")) {
    108             if (platform == null) {
    109                 platform = member.getMember();
    110                 platformRM = member;
    111                 return true;
    112             }
     74        if (stopPosition == null && isPTStopPosition(member)) {
     75            this.stopPosition = member.getNode();
     76            stopPositionRM = new RelationMember("stop", member.getMember());
     77            return true;
     78        } else if (platform == null && isPTPlatform(member)) {
     79            platform = member.getMember();
     80            platformRM = new RelationMember("platform", member.getMember());
     81            return true;
    11382        }
    11483
    11584        return false;
    116 
    11785    }
    11886
     
    210178        }
    211179
    212         if (this.platform != null
    213                 && (this.platform == other.getPlatform() || this.platform == other.getStopPosition())) {
    214             return true;
    215         }
    216 
    217         return false;
     180        return this.platform != null
     181                && (this.platform == other.getPlatform()
     182                    || this.platform == other.getStopPosition());
     183    }
     184
     185    /**
     186     * checks whether the given relation member matches a Stop Position or not
     187     * @param rm member to check
     188     * @return true if it matches, false otherwise
     189     */
     190    public static boolean isPTStopPosition(RelationMember rm) {
     191        return rm.getMember().hasTag("public_transport", "stop_position")
     192                && rm.getType().equals(OsmPrimitiveType.NODE);
     193    }
     194
     195    /**
     196     * checks whether the given relation member matches a Platform or not
     197     * @param rm member to check
     198     * @return true if it matches, false otherwise
     199     */
     200    public static boolean isPTPlatform(RelationMember rm) {
     201        return rm.getMember().hasTag("highway", "bus_stop")
     202                || rm.getMember().hasTag("public_transport", "platform")
     203                || rm.getMember().hasTag("highway", "platform")
     204                || rm.getMember().hasTag("railway", "platform");
    218205    }
    219206
     
    233220        this.stopPositionRM = stopPositionRM;
    234221    }
    235 
    236222}
Note: See TracChangeset for help on using the changeset viewer.