Changeset 32353 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-06-21T20:51:36+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java
r32338 r32353 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.List; 5 6 6 7 import javax.swing.JOptionPane; … … 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.data.osm.Node; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 13 import org.openstreetmap.josm.data.osm.PrimitiveId; 11 14 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.data.osm.RelationMember; 12 16 import org.openstreetmap.josm.gui.io.DownloadPrimitivesWithReferrersTask; 13 17 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; … … 32 36 ArrayList<PrimitiveId> list = new ArrayList<>(); 33 37 34 // add all route relations that are of public_transport version 2: 38 // add all route relations that are of public_transport version 39 // 2: 35 40 Collection<Relation> allRelations = Main.getLayerManager().getEditDataSet().getRelations(); 36 41 for (Relation currentRelation : allRelations) { 37 42 if (RouteUtils.isTwoDirectionRoute(currentRelation)) { 38 43 list.add(currentRelation); 44 for (RelationMember rm : currentRelation.getMembers()) { 45 if (rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only") 46 || rm.hasRole("platform") || rm.hasRole("platform_entry_only") 47 || rm.hasRole("platform_exit_only")) { 48 List<OsmPrimitive> referrers = rm.getMember().getReferrers(); 49 for (OsmPrimitive referrer : referrers) { 50 if (referrer.getType().equals(OsmPrimitiveType.RELATION) 51 && referrer.hasTag("public_transport", "stop_area")) { 52 list.add(referrer); 53 // TODO: this may never be executed 54 // because the platform is an incomplete 55 // member yet. 56 } 57 } 58 } 59 } 39 60 } 40 61 } 41 62 42 63 // add all stop_positions: 43 64 Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes(); 44 for (Node currentNode : allNodes) {65 for (Node currentNode : allNodes) { 45 66 if (currentNode.hasTag("public_transport", "stop_position")) { 46 list.add(currentNode); 67 List<OsmPrimitive> referrers = currentNode.getReferrers(); 68 boolean parentWayExists = false; 69 for (OsmPrimitive referrer : referrers) { 70 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 71 parentWayExists = true; 72 break; 73 } 74 } 75 if (!parentWayExists) { 76 list.add(currentNode); 77 78 } 79 47 80 } 48 81 } 49 50 82 51 83 DownloadPrimitivesWithReferrersTask task = new DownloadPrimitivesWithReferrersTask(false, list, false, 52 84 true, null, null); -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32303 r32353 3 3 import java.util.ArrayList; 4 4 import java.util.List; 5 6 import javax.swing.JOptionPane; 5 7 6 8 import org.openstreetmap.josm.data.osm.Relation; … … 40 42 41 43 if (RouteUtils.isPTStop(member)) { 44 42 45 // check if there are consecutive elements that belong to the 43 46 // same stop: -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32303 r32353 1 1 package org.openstreetmap.josm.plugins.pt_assistant.data; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 import java.util.Set; 2 6 3 7 import org.openstreetmap.josm.data.osm.Node; … … 11 15 private Node stopPosition = null; 12 16 private OsmPrimitive platform = null; 13 private Relation stopArea = null;14 17 15 /* Name of this stop */16 18 private String name = ""; 17 19 … … 20 22 super(other); 21 23 22 if (other.getRole().equals("stop") && other.getType().equals(OsmPrimitiveType.NODE)) { 24 if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only"))&& other.getType().equals(OsmPrimitiveType.NODE)) { 25 23 26 this.stopPosition = other.getNode(); 27 this.name = stopPosition.get("name"); 28 24 29 } else if (other.getRole().equals("platform") || other.getRole().equals("platform_entry_only") 25 30 || other.getRole().equals("platform_exit_only")) { 31 26 32 this.platform = other.getMember(); 27 } else if (other.getRole().equals("stop_area") && other.getType().equals(OsmPrimitiveType.RELATION)) { 28 this.stopArea = other.getRelation(); 29 for (RelationMember rm: stopArea.getMembers()) { 30 if (rm.getRole().equals("stop") && rm.isNode()) { 31 this.stopPosition = rm.getNode(); 32 } 33 if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) { 34 this.platform = rm.getMember(); 35 } 36 } 33 this.name = platform.get("name"); 34 37 35 } else { 38 36 throw new IllegalArgumentException("The RelationMember type does not match its role"); 39 37 } 40 41 this.name = other.getMember().get("name");42 38 43 39 } … … 58 54 59 55 // add stop position: 60 if (member. getRole().equals("stop")) {56 if (member.hasRole("stop") || member.hasRole("stop_entry_only") || member.hasRole("stop_exit_only")) { 61 57 if (member.getType().equals(OsmPrimitiveType.NODE) && stopPosition == null) { 62 58 this.stopPosition = member.getNode(); … … 74 70 } 75 71 76 // add stop_area:77 if (member.getRole().equals("stop_area") && member.getType().equals(OsmPrimitiveType.RELATION)) {78 if (stopArea == null) {79 stopArea = member.getRelation();80 for (RelationMember rm: stopArea.getMembers()) {81 if (rm.getRole().equals("stop") && rm.isNode()) {82 this.stopPosition = rm.getNode();83 }84 if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")) {85 this.platform = rm.getMember();86 }87 }88 return true;89 }90 }91 92 72 return false; 93 73 94 74 } 95 75 76 /** 77 * Returns the stop_position for this PTstop. If the stop_position is not 78 * available directly, the method searches for a stop_area relation 79 * 80 * @return 81 */ 96 82 public Node getStopPosition() { 83 84 // List<OsmPrimitive> referrers = platform.getReferrers(); 85 // List<Relation> stopAreaRelations = new ArrayList<>(); 86 // for (OsmPrimitive referrer: referrers) { 87 // if (referrer.getType().equals(OsmPrimitiveType.RELATION) && 88 // referrer.hasTag("public_tranport", "stop_area")) { 89 // stopAreaRelations.add((Relation)referrer); 90 // } 91 // } 92 // 93 // for (Relation stopArea: stopAreaRelations) { 94 // for (RelationMember rm: stopArea.getMembers()) { 95 // if (rm.hasRole("stop") && rm.getType().equals(OsmPrimitiveType.NODE)) 96 // { 97 // this.stopPosition = rm.getNode(); 98 // } 99 // } 100 // } 101 97 102 return this.stopPosition; 98 103 } 99 104 100 105 /** 101 106 * Returns platform (including platform_entry_only and platform_exit_only) 107 * 102 108 * @return 103 109 */ … … 106 112 } 107 113 108 public Relation getStopArea() {109 return this.stopArea;110 }111 112 114 public String getName() { 113 115 return this.name; 114 116 } 115 117 118 public void setStopPosition(Node newStopPosition) { 119 120 this.stopPosition = newStopPosition; 121 122 } 123 124 /** 125 * Finds potential stop_positions of the platform of this PTStop. It only 126 * makes sense to call this method if the stop_position attribute is null. 127 * The stop_positions are potential because they may refer to a different 128 * route, which this method does not check. 129 * 130 * @return List of potential stop_positions for this PTStop 131 */ 132 public List<Node> findPotentialStopPositions() { 133 134 ArrayList<Node> potentialStopPositions = new ArrayList<>(); 135 136 if (platform == null) { 137 return potentialStopPositions; 138 } 139 140 // 1) Look for any stop_area relations that this platform 141 // belongs to: 142 ArrayList<OsmPrimitive> platformList = new ArrayList<OsmPrimitive>(1); 143 platformList.add(platform); 144 Set<Relation> platformParentRelations = OsmPrimitive.getParentRelations(platformList); 145 ArrayList<Relation> stopAreaList = new ArrayList<Relation>(); 146 for (Relation platformParentRelation : platformParentRelations) { 147 if (platformParentRelation.hasTag("public_transport", "stop_area")) { 148 stopAreaList.add(platformParentRelation); 149 } 150 } 151 152 // 2) Get all potential stop_positions from those stop_area relations: 153 for (Relation stopArea : stopAreaList) { 154 for (RelationMember rm : stopArea.getMembers()) { 155 if ((rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only"))&& rm.getType().equals(OsmPrimitiveType.NODE) 156 && rm.getNode().hasTag("public_transport", "stop_position")) { 157 potentialStopPositions.add(rm.getNode()); 158 } 159 } 160 } 161 162 return potentialStopPositions; 163 } 164 116 165 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java
r32303 r32353 84 84 return false; 85 85 } 86 86 87 87 88 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32299 r32353 61 61 62 62 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 63 return true; 63 64 if (rm.getNode().hasTag("public_transport", "stop_position") 65 || rm.getNode().hasTag("public_transport", "platform") 66 || rm.getNode().hasTag("public_transport", "platform_entry_only") 67 || rm.getNode().hasTag("public_transport", "platform_exit_only") 68 || rm.getNode().hasTag("highway", "platform") 69 || rm.getNode().hasTag("highway", "platform_entry_only") 70 || rm.getNode().hasTag("highway", "platform_exit_only") 71 || rm.getNode().hasTag("railway", "platform") 72 || rm.getNode().hasTag("railway", "platform_entry_only") 73 || rm.getNode().hasTag("railway", "platform_exit_only")) { 74 return true; 75 } 76 64 77 } 65 78 66 if (rm.getType().equals(OsmPrimitiveType.RELATION)) { 67 if (rm.getRole().equals("stop_area")) { 79 if (rm.getType().equals(OsmPrimitiveType.WAY)) { 80 if (rm.getWay().hasTag("public_transport", "platform") 81 || rm.getWay().hasTag("public_transport", "platform_entry_only") 82 || rm.getWay().hasTag("public_transport", "platform_exit_only") 83 || rm.getWay().hasTag("highway", "platform") || rm.getWay().hasTag("highway", "platform_entry_only") 84 || rm.getWay().hasTag("highway", "platform_exist_only") || rm.getWay().hasTag("railway", "platform") 85 || rm.getWay().hasTag("railway", "platform_entry_only") 86 || rm.getWay().hasTag("railway", "platform_exit_only")) { 68 87 return true; 69 } else if (rm.getRole().equals("platform") || rm.getRole().equals("platform_entry_only") || rm.getRole().equals("platform_exit_only")){70 return true;71 } else {72 return false;73 88 } 74 }75 76 Way w = rm.getWay();77 78 if (w.hasTag("public_transport", "platform") || w.hasTag("highway", "platform")79 || w.hasTag("railway", "platform") || w.hasTag("public_transport", "platform_entry_only")80 || w.hasTag("highway", "platform_entry_only") || w.hasTag("railway", "platform_entry_only")81 || w.hasTag("public_transport", "platform_exit_only") || w.hasTag("highway", "platform_exit_only")82 || w.hasTag("railway", "platform_exit_only")) {83 return true;84 89 } 85 90 … … 101 106 102 107 return !isPTStop(rm); 108 103 109 } 104 110 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32338 r32353 43 43 @Override 44 44 public void visit(Relation r) { 45 45 46 46 47 if (!RouteUtils.isTwoDirectionRoute(r)) { 47 48 return; 48 49 } 50 49 51 50 52 // Download incomplete members. If the download does not work, finish. … … 55 57 } 56 58 } 59 60 if (r.hasIncompleteMembers()) { 61 return; 62 } 57 63 58 64 // Check individual ways using the oneway direction test and the road … … 60 66 WayChecker wayChecker = new WayChecker(r, this); 61 67 this.errors.addAll(wayChecker.getErrors()); 68 62 69 63 70 if (this.errors.isEmpty()) { … … 89 96 t.wait(); 90 97 } catch (InterruptedException e) { 98 // TODO: give the user a message that testing stops 91 99 return false; 92 100 } … … 184 192 185 193 private void proceedAfterSorting(Relation r) { 186 // TODO 187 performDummyTest(r); 194 195 196 197 SegmentChecker segmentChecker = new SegmentChecker(r, this); 198 segmentChecker.performFirstStopTest(); 199 segmentChecker.performLastStopTest(); 200 // TODO: perform segment test 201 this.errors.addAll(segmentChecker.getErrors()); 202 // performDummyTest(r); 188 203 } 189 204 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32303 r32353 6 6 import java.util.List; 7 7 8 import org.openstreetmap.josm.data.osm.Node; 8 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 10 import org.openstreetmap.josm.data.osm.Relation; … … 39 40 40 41 super(relation, test); 41 42 42 43 this.manager = new PTRouteDataManager(relation); 43 44 this.assigner = new StopToWayAssigner(manager.getPTWays()); 44 45 45 46 } 46 47 … … 58 59 59 60 private void performEndStopTest(PTStop endStop) { 60 if (manager.getPTStopCount() < 2) { 61 // it does not make sense to check a route that has less than 262 // stops63 return;64 }61 62 /* 63 * This test checks: (1) that a stop position exists; (2) that it is the 64 * first or last node of its parent ways which belong to this route. 65 */ 65 66 66 67 if (endStop.getStopPosition() == null) { 67 List<Relation> primitives = new ArrayList<>(1);68 primitives.add(relation);69 List<OsmPrimitive> highlighted = new ArrayList<>(1);70 highlighted.add(endStop.getPlatform());71 TestError e = new TestError(this.test, Severity.WARNING,72 tr("PT: Route should start and end with a stop_position"),73 PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted);74 this.errors.add(e);75 return;76 }77 68 78 PTWay endWay = assigner.get(endStop); 69 List<Node> potentialStopPositionList = endStop.findPotentialStopPositions(); 70 List<Node> stopPositionsOfThisRoute = new ArrayList<>(); 71 boolean containsAtLeastOneStopPositionAsFirstOrLastNode = false; 79 72 80 boolean found = false; 81 List<Way> primitivesOfEndWay = endWay.getWays(); 82 for (Way primitiveWay : primitivesOfEndWay) { 83 if (primitiveWay.firstNode() == endStop.getStopPosition() 84 || primitiveWay.lastNode() == endStop.getStopPosition()) { 85 found = true; 73 for (Node potentialStopPosition : potentialStopPositionList) { 74 75 int belongsToWay = belongsToAWayOfThisRoute(potentialStopPosition); 76 77 if (belongsToWay == 0) { 78 stopPositionsOfThisRoute.add(potentialStopPosition); 79 containsAtLeastOneStopPositionAsFirstOrLastNode = true; 80 } 81 82 if (belongsToWay == 1) { 83 stopPositionsOfThisRoute.add(potentialStopPosition); 84 } 86 85 } 87 86 88 } 87 if (stopPositionsOfThisRoute.isEmpty()) { 88 List<Relation> primitives = new ArrayList<>(1); 89 primitives.add(relation); 90 List<OsmPrimitive> highlighted = new ArrayList<>(1); 91 highlighted.add(endStop.getPlatform()); 92 TestError e = new TestError(this.test, Severity.WARNING, 93 tr("PT: Route should start and end with a stop_position"), 94 PTAssitantValidatorTest.ERROR_CODE_END_STOP, primitives, highlighted); 95 this.errors.add(e); 96 return; 97 } 98 99 if (stopPositionsOfThisRoute.size() == 1) { 100 endStop.setStopPosition(stopPositionsOfThisRoute.get(0)); 101 } 89 102 90 if (!found) { 91 List<Relation> primitives = new ArrayList<>(1); 92 primitives.add(relation); 93 List<OsmPrimitive> highlighted = new ArrayList<>(); 94 for (Way w : endWay.getWays()) { 95 if (w.getNodes().contains(endStop.getStopPosition())) { 96 highlighted.add(w); 97 } 103 // At this point, there is at least one stop_position for this 104 // endStop: 105 if (!containsAtLeastOneStopPositionAsFirstOrLastNode) { 106 List<Relation> primitives = new ArrayList<>(1); 107 primitives.add(relation); 108 List<OsmPrimitive> highlighted = new ArrayList<>(); 109 highlighted.addAll(stopPositionsOfThisRoute); 110 111 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 112 PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 113 this.errors.add(e); 98 114 } 99 TestError e = new TestError(this.test, Severity.WARNING, 100 tr("PT: First or last way needs to be split"), 101 PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 102 this.errors.add(e); 115 116 } else { 117 118 // if the stop_position is known: 119 int belongsToWay = this.belongsToAWayOfThisRoute(endStop.getStopPosition()); 120 121 if (belongsToWay == 1) { 122 123 List<Relation> primitives = new ArrayList<>(1); 124 primitives.add(relation); 125 List<OsmPrimitive> highlighted = new ArrayList<>(); 126 highlighted.add(endStop.getStopPosition()); 127 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: First or last way needs to be split"), 128 PTAssitantValidatorTest.ERROR_CODE_SPLIT_WAY, primitives, highlighted); 129 this.errors.add(e); 130 } 103 131 } 104 132 … … 109 137 } 110 138 139 /** 140 * Checks if the given node belongs to the ways of this route. 141 * 142 * @param node 143 * Node to be checked 144 * @return 1 if belongs only as an inner node, 0 if belongs as a first or 145 * last node for at least one way, -1 if does not belong to any way. 146 */ 147 private int belongsToAWayOfThisRoute(Node node) { 148 149 boolean contains = false; 150 151 List<PTWay> ptways = manager.getPTWays(); 152 for (PTWay ptway : ptways) { 153 List<Way> ways = ptway.getWays(); 154 for (Way way : ways) { 155 if (way.containsNode(node)) { 156 157 if (way.firstNode().equals(node) || way.lastNode().equals(node)) { 158 return 0; 159 } 160 161 contains = true; 162 } 163 } 164 } 165 166 if (contains) { 167 return 1; 168 } 169 170 return -1; 171 } 172 111 173 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32299 r32353 30 30 super(relation, test); 31 31 32 this.performDirectionTest(); 33 this.performRoadTypeTest(); 32 if (!relation.hasIncompleteMembers()) { 33 this.performDirectionTest(); 34 this.performRoadTypeTest(); 35 } 36 34 37 35 38 } 36 39 37 40 private void performRoadTypeTest() { 38 41 39 42 if (!relation.hasTag("route", "bus") && !relation.hasTag("route", "trolleybus") 40 43 && !relation.hasTag("route", "share_taxi")) {
Note:
See TracChangeset
for help on using the changeset viewer.