Changeset 32367 in osm for applications/editors
- Timestamp:
- 2016-06-23T00:23:53+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/IncompleteMembersDownloadThread.java
r32353 r32367 42 42 if (RouteUtils.isTwoDirectionRoute(currentRelation)) { 43 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 } 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 // } 54 // } 55 // } 56 // } 60 57 } 61 58 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32353 r32367 6 6 import javax.swing.JOptionPane; 7 7 8 import org.openstreetmap.josm.data.coor.LatLon; 8 9 import org.openstreetmap.josm.data.osm.Relation; 9 10 import org.openstreetmap.josm.data.osm.RelationMember; … … 29 30 private List<PTWay> ptways = new ArrayList<>(); 30 31 31 public PTRouteDataManager(Relation relation) { 32 /* 33 * Stores relation members that could not be created because they are not 34 * expected in the model for public_transport version 2 35 */ 36 private List<RelationMember> failedMembers = new ArrayList<>(); 37 38 public PTRouteDataManager(Relation relation) throws IllegalArgumentException { 32 39 33 40 // It is assumed that the relation is a route. Build in a check here 34 41 // (e.g. from class RouteUtils) if you want to invoke this constructor 35 42 // from outside the pt_assitant SegmentChecker) 36 43 37 44 this.relation = relation; 38 45 39 46 PTStop prev = null; // stores the last created PTStop 40 47 … … 42 49 43 50 if (RouteUtils.isPTStop(member)) { 44 45 // check if there are consecutive elements that belong to the 46 // same stop: 47 if (prev != null && prev.getName().equalsIgnoreCase(member.getMember().get("name"))) { 48 // this PTStop already exists, so just add a new element: 51 52 // First, check if the stop already exists (i.e. there are 53 // consecutive elements that belong to the same stop: 54 boolean stopExists = false; 55 56 if (prev != null) { 57 if (prev.getName() == null || prev.getName().equals("") || member.getMember().get("name") == null 58 || member.getMember().get("name").equals("")) { 59 60 // if there is no name, check by proximity: 61 // Squared distance of 0.000004 corresponds to 62 // around 100 m 63 if (this.calculateDistanceSq(member, prev) < 0.000004) { 64 65 stopExists = true; 66 } 67 } else { 68 69 // if there is a name, check by name comparison: 70 if (prev.getName().equalsIgnoreCase(member.getMember().get("name"))) { 71 72 stopExists = true; 73 } 74 } 75 } 76 77 // check if there are consecutive elements that belong to 78 // the same stop: 79 if (stopExists) { 80 // this PTStop already exists, so just add a new 81 // element: 49 82 prev.addStopElement(member); 50 // TODO: something may need to be done if adding the element 51 // did not succeed. The failure is a result of the same stop 83 // TODO: something may need to be done if adding the 84 // element 85 // did not succeed. The failure is a result of the same 86 // stop 52 87 // having >1 stop_position, platform or stop_area. 53 88 } else { … … 58 93 } 59 94 60 } else { 95 } else if (RouteUtils.isPTWay(member)) { 96 61 97 PTWay ptway = new PTWay(member); 62 98 ptways.add(ptway); 99 100 } else { 101 this.failedMembers.add(member); 63 102 } 103 64 104 } 65 105 } 66 106 107 /** 108 * Calculates the squared distance between the centers of bounding boxes of 109 * two relation members (which are supposed to be platforms or 110 * stop_positions) 111 * 112 * @param member1 113 * @param member2 114 * @return Squared distance between the centers of the bounding boxes of the 115 * given relation members 116 */ 117 private double calculateDistanceSq(RelationMember member1, RelationMember member2) { 118 LatLon coord1 = member1.getMember().getBBox().getCenter(); 119 LatLon coord2 = member2.getMember().getBBox().getCenter(); 120 return coord1.distanceSq(coord2); 121 } 122 67 123 /** 68 124 * Assigns the given way to a PTWay of this route relation. 69 * @param inputWay Way to be assigned to a PTWAy of this route relation 70 * @return PTWay that contains the geometry of the inputWay, null if not found 125 * 126 * @param inputWay 127 * Way to be assigned to a PTWAy of this route relation 128 * @return PTWay that contains the geometry of the inputWay, null if not 129 * found 71 130 */ 72 131 public PTWay getPTWay(Way inputWay) { 73 74 for (PTWay curr : ptways) {75 132 133 for (PTWay curr : ptways) { 134 76 135 if (curr.isWay() && curr.getWays().get(0) == inputWay) { 77 136 return curr; 78 137 } 79 138 80 139 if (curr.isRelation()) { 81 for (RelationMember rm : curr.getRelation().getMembers()) {140 for (RelationMember rm : curr.getRelation().getMembers()) { 82 141 Way wayInNestedRelation = rm.getWay(); 83 142 if (wayInNestedRelation == inputWay) { … … 87 146 } 88 147 } 89 148 90 149 return null; // if not found 91 150 } 92 151 93 152 public List<PTStop> getPTStops() { 94 153 return this.ptstops; 95 154 } 96 155 97 156 public List<PTWay> getPTWays() { 98 157 return this.ptways; 99 158 } 100 159 101 160 public int getPTStopCount() { 102 161 return ptstops.size(); 103 162 } 104 163 105 164 public int getPTWayCount() { 106 165 return this.ptways.size(); 107 166 } 108 167 109 168 public PTStop getFirstStop() { 110 169 if (this.ptstops.isEmpty()) { … … 113 172 return this.ptstops.get(0); 114 173 } 115 174 116 175 public PTStop getLastStop() { 117 176 if (this.ptstops.isEmpty()) { 118 177 return null; 119 178 } 120 return this.ptstops.get(ptstops.size()-1); 179 return this.ptstops.get(ptstops.size() - 1); 180 } 181 182 public List<RelationMember> getFailedMembers() { 183 return this.failedMembers; 121 184 } 122 185 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32353 r32367 2 2 3 3 import java.util.ArrayList; 4 import java.util.Collection; 4 5 import java.util.List; 5 import java.util.Set;6 6 7 import org.openstreetmap.josm.Main; 8 import org.openstreetmap.josm.data.coor.LatLon; 9 import org.openstreetmap.josm.data.osm.BBox; 7 10 import org.openstreetmap.josm.data.osm.Node; 8 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 12 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 import org.openstreetmap.josm.data.osm.Relation;11 13 import org.openstreetmap.josm.data.osm.RelationMember; 12 14 … … 15 17 private Node stopPosition = null; 16 18 private OsmPrimitive platform = null; 17 19 18 20 private String name = ""; 19 21 … … 22 24 super(other); 23 25 24 if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only"))&& other.getType().equals(OsmPrimitiveType.NODE)) { 26 if ((other.hasRole("stop") || other.hasRole("stop_entry_only") || other.hasRole("stop_exit_only")) 27 && other.getType().equals(OsmPrimitiveType.NODE)) { 25 28 26 29 this.stopPosition = other.getNode(); … … 34 37 35 38 } else { 36 throw new IllegalArgumentException("The RelationMember type does not match its role ");39 throw new IllegalArgumentException("The RelationMember type does not match its role " + other.getMember().getName()); 37 40 } 38 41 … … 82 85 public Node getStopPosition() { 83 86 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 102 87 return this.stopPosition; 103 88 } … … 111 96 return this.platform; 112 97 } 113 98 114 99 public String getName() { 115 100 return this.name; … … 138 123 } 139 124 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); 125 // Look for a stop position within 100 m (around 0.002 degrees) of this platform: 126 127 LatLon platformCenter = platform.getBBox().getCenter(); 128 Double ax = platformCenter.getX() - 0.002; 129 Double bx = platformCenter.getX() + 0.002; 130 Double ay = platformCenter.getY() - 0.002; 131 Double by = platformCenter.getY() + 0.002; 132 BBox platformBBox = new BBox(ax, ay, bx, by); 133 134 Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes(); 135 for (Node currentNode : allNodes) { 136 if (platformBBox.bounds(currentNode.getBBox()) && currentNode.hasTag("public_transport", "stop_position")) { 137 potentialStopPositions.add(currentNode); 149 138 } 150 139 } 151 140 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 } 141 // // 1) Look for any stop_area relations that this platform 142 // // belongs to: 143 // ArrayList<OsmPrimitive> platformList = new 144 // ArrayList<OsmPrimitive>(1); 145 // platformList.add(platform); 146 // Set<Relation> platformParentRelations = 147 // OsmPrimitive.getParentRelations(platformList); 148 // ArrayList<Relation> stopAreaList = new ArrayList<Relation>(); 149 // for (Relation platformParentRelation : platformParentRelations) { 150 // if (platformParentRelation.hasTag("public_transport", "stop_area")) { 151 // stopAreaList.add(platformParentRelation); 152 // } 153 // } 154 // 155 // // 2) Get all potential stop_positions from those stop_area 156 // relations: 157 // for (Relation stopArea : stopAreaList) { 158 // for (RelationMember rm : stopArea.getMembers()) { 159 // if ((rm.hasRole("stop") || rm.hasRole("stop_entry_only") || 160 // rm.hasRole("stop_exit_only"))&& 161 // rm.getType().equals(OsmPrimitiveType.NODE) 162 // && rm.getNode().hasTag("public_transport", "stop_position")) { 163 // potentialStopPositions.add(rm.getNode()); 164 // } 165 // } 166 // } 161 167 162 168 return potentialStopPositions; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java
r32353 r32367 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.OsmPrimitiveType; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32353 r32367 62 62 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 63 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; 64 if (rm.hasRole("stop") || rm.hasRole("stop_entry_only") || rm.hasRole("stop_exit_only") 65 || rm.hasRole("platform") || rm.hasRole("platform_entry_only") 66 || rm.hasRole("platform_exit_only")) { 67 68 if (rm.getNode().hasTag("public_transport", "stop_position") 69 || rm.getNode().hasTag("highway", "bus_stop") 70 || rm.getNode().hasTag("public_transport", "platform") 71 || rm.getNode().hasTag("public_transport", "platform_entry_only") 72 || rm.getNode().hasTag("public_transport", "platform_exit_only") 73 || rm.getNode().hasTag("highway", "platform") 74 || rm.getNode().hasTag("highway", "platform_entry_only") 75 || rm.getNode().hasTag("highway", "platform_exit_only") 76 || rm.getNode().hasTag("railway", "platform") 77 || rm.getNode().hasTag("railway", "platform_entry_only") 78 || rm.getNode().hasTag("railway", "platform_exit_only")) { 79 return true; 80 } 75 81 } 76 77 82 } 78 83 … … 105 110 public static boolean isPTWay(RelationMember rm) { 106 111 107 return !isPTStop(rm); 112 if (rm.getType().equals(OsmPrimitiveType.NODE)) { 113 return false; 114 } 108 115 116 if (rm.getType().equals(OsmPrimitiveType.WAY)) { 117 return true; 118 } 119 120 Relation nestedRelation = rm.getRelation(); 121 122 for (RelationMember nestedRelationMember : nestedRelation.getMembers()) { 123 if (!nestedRelationMember.getType().equals(OsmPrimitiveType.WAY)) { 124 return false; 125 } 126 } 127 128 return true; 109 129 } 110 130 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32353 r32367 34 34 public static final int ERROR_CODE_END_STOP = 3141; 35 35 public static final int ERROR_CODE_SPLIT_WAY = 3142; 36 36 public static final int ERROR_CODE_RELAITON_MEMBER_ROLES = 3143; 37 37 38 public PTAssitantValidatorTest() { 38 39 super(tr("Public Transport Assistant tests"), … … 43 44 @Override 44 45 public void visit(Relation r) { 45 46 46 47 47 if (!RouteUtils.isTwoDirectionRoute(r)) { 48 48 return; 49 49 } 50 51 50 52 51 // Download incomplete members. If the download does not work, finish. … … 57 56 } 58 57 } 59 58 60 59 if (r.hasIncompleteMembers()) { 61 60 return; … … 66 65 WayChecker wayChecker = new WayChecker(r, this); 67 66 this.errors.addAll(wayChecker.getErrors()); 68 69 67 70 68 if (this.errors.isEmpty()) { … … 124 122 } 125 123 126 127 124 ProceedDialog proceedDialog = new ProceedDialog(r.getId(), numberOfDirectionErrors, numberOfRoadTypeErrors); 128 125 int userInput = proceedDialog.getUserSelection(); … … 149 146 150 147 } 151 152 148 153 149 /** 154 150 * Carries out the second stage of the testing: sorting 151 * 155 152 * @param r 156 153 */ 157 154 private void proceedWithSorting(Relation r) { 158 155 159 156 // Check if the relation is correct, or only has a wrong sorting order: 160 157 RouteChecker routeChecker = new RouteChecker(r, this); 161 158 List<TestError> routeCheckerErrors = routeChecker.getErrors(); 162 159 163 160 /*- At this point, there are 3 variants: 164 161 * … … 170 167 * 171 168 * */ 172 173 169 174 170 if (!routeCheckerErrors.isEmpty()) { 175 171 // Variant 2 … … 178 174 return; 179 175 } 180 176 181 177 if (!routeChecker.getHasGap()) { 182 178 // Variant 1 183 // TODO: add the segments of this route to the list correct route segments 184 } 185 179 // TODO: add the segments of this route to the list correct route 180 // segments 181 } 182 186 183 // Variant 3: 187 184 proceedAfterSorting(r); 188 189 190 } 191 192 185 186 } 187 193 188 private void proceedAfterSorting(Relation r) { 194 195 196 189 197 190 SegmentChecker segmentChecker = new SegmentChecker(r, this); 191 192 // Check if the creation of the route data model in the segment checker 193 // worked. If it did not, it means the roles in the route relation do 194 // not match the tags of the route members. 195 if (!segmentChecker.getErrors().isEmpty()) { 196 this.errors.addAll(segmentChecker.getErrors()); 197 } 198 198 199 segmentChecker.performFirstStopTest(); 199 200 segmentChecker.performLastStopTest(); 201 200 202 // TODO: perform segment test 201 203 this.errors.addAll(segmentChecker.getErrors()); … … 249 251 private void fixErrorFromPlugin(List<TestError> testErrors) { 250 252 251 252 // run fix task asynchronously 253 FixTask fixTask = new FixTask(testErrors); 254 // Main.worker.submit(fixTask); 255 256 Thread t = new Thread(fixTask); 257 t.start(); 258 try { 259 t.join(); 260 errors.removeAll(testErrors); 261 262 } catch (InterruptedException e) { 263 JOptionPane.showMessageDialog(null, "Error occurred during fixing"); 264 } 265 266 253 // run fix task asynchronously 254 FixTask fixTask = new FixTask(testErrors); 255 // Main.worker.submit(fixTask); 256 257 Thread t = new Thread(fixTask); 258 t.start(); 259 try { 260 t.join(); 261 errors.removeAll(testErrors); 262 263 } catch (InterruptedException e) { 264 JOptionPane.showMessageDialog(null, "Error occurred during fixing"); 265 } 267 266 268 267 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32353 r32367 9 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 10 import org.openstreetmap.josm.data.osm.Relation; 11 import org.openstreetmap.josm.data.osm.RelationMember; 11 12 import org.openstreetmap.josm.data.osm.Way; 12 13 import org.openstreetmap.josm.data.validation.Severity; … … 34 35 private PTRouteDataManager manager; 35 36 36 /* Assigns PTStops to nearest PTWays and stores that corresponden se */37 /* Assigns PTStops to nearest PTWays and stores that correspondence */ 37 38 private StopToWayAssigner assigner; 38 39 … … 40 41 41 42 super(relation, test); 43 44 this.manager = new PTRouteDataManager(relation); 42 45 43 this.manager = new PTRouteDataManager(relation); 46 for (RelationMember rm: manager.getFailedMembers()) { 47 List<Relation> primitives = new ArrayList<>(1); 48 primitives.add(relation); 49 List<OsmPrimitive> highlighted = new ArrayList<>(1); 50 highlighted.add(rm.getMember()); 51 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Relation member roles do not match tags"), 52 PTAssitantValidatorTest.ERROR_CODE_RELAITON_MEMBER_ROLES, primitives, highlighted); 53 this.errors.add(e); 54 } 55 56 57 44 58 this.assigner = new StopToWayAssigner(manager.getPTWays()); 45 59 46 60 } 47 61 … … 59 73 60 74 private void performEndStopTest(PTStop endStop) { 75 76 if (endStop == null) { 77 return; 78 } 61 79 62 80 /* … … 96 114 return; 97 115 } 98 116 99 117 if (stopPositionsOfThisRoute.size() == 1) { 100 118 endStop.setStopPosition(stopPositionsOfThisRoute.get(0)); … … 115 133 116 134 } else { 117 135 118 136 // if the stop_position is known: 119 137 int belongsToWay = this.belongsToAWayOfThisRoute(endStop.getStopPosition()); 120 138 121 139 if (belongsToWay == 1) { 122 140 123 141 List<Relation> primitives = new ArrayList<>(1); 124 142 primitives.add(relation);
Note:
See TracChangeset
for help on using the changeset viewer.