Changeset 32303 in osm for applications/editors/josm/plugins/pt_assistant
- Timestamp:
- 2016-06-18T01:16:36+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32299 r32303 6 6 import org.openstreetmap.josm.data.osm.Relation; 7 7 import org.openstreetmap.josm.data.osm.RelationMember; 8 import org.openstreetmap.josm.data.osm.Way; 8 9 import org.openstreetmap.josm.plugins.pt_assistant.utils.RouteUtils; 9 10 … … 61 62 } 62 63 64 /** 65 * Assigns the given way to a PTWay of this route relation. 66 * @param inputWay Way to be assigned to a PTWAy of this route relation 67 * @return PTWay that contains the geometry of the inputWay, null if not found 68 */ 69 public PTWay getPTWay(Way inputWay) { 70 71 for (PTWay curr: ptways) { 72 73 if (curr.isWay() && curr.getWays().get(0) == inputWay) { 74 return curr; 75 } 76 77 if (curr.isRelation()) { 78 for (RelationMember rm: curr.getRelation().getMembers()) { 79 Way wayInNestedRelation = rm.getWay(); 80 if (wayInNestedRelation == inputWay) { 81 return curr; 82 } 83 } 84 } 85 } 86 87 return null; // if not found 88 } 89 63 90 public List<PTStop> getPTStops() { 64 91 return this.ptstops; -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32299 r32303 20 20 super(other); 21 21 22 if (other.getRole().equals("stop _position") && other.getType().equals(OsmPrimitiveType.NODE)) {22 if (other.getRole().equals("stop") && other.getType().equals(OsmPrimitiveType.NODE)) { 23 23 this.stopPosition = other.getNode(); 24 24 } else if (other.getRole().equals("platform") || other.getRole().equals("platform_entry_only") … … 27 27 } else if (other.getRole().equals("stop_area") && other.getType().equals(OsmPrimitiveType.RELATION)) { 28 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 } 29 37 } else { 30 38 throw new IllegalArgumentException("The RelationMember type does not match its role"); … … 50 58 51 59 // add stop position: 52 if (member.getRole().equals("stop _position")) {60 if (member.getRole().equals("stop")) { 53 61 if (member.getType().equals(OsmPrimitiveType.NODE) && stopPosition == null) { 54 62 this.stopPosition = member.getNode(); … … 70 78 if (stopArea == null) { 71 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 } 72 88 return true; 73 89 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTWay.java
r32299 r32303 63 63 return this.ways; 64 64 } 65 66 67 /** 68 * Determines if this PTWay is modeled by an OsmPrimitiveType.WAY 69 */ 70 public boolean isWay() { 71 if (this.getType().equals(OsmPrimitiveType.WAY)) { 72 return true; 73 } 74 return false; 75 } 76 77 /** 78 * Determines if this PTWay is modeled by an OsmPrimitieType.RELATION (i.e. this is a nested relation) 79 */ 80 public boolean isRelation() { 81 if (this.getType().equals(OsmPrimitiveType.RELATION)) { 82 return true; 83 } 84 return false; 85 } 65 86 66 87 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/StopToWayAssigner.java
r32299 r32303 1 1 package org.openstreetmap.josm.plugins.pt_assistant.utils; 2 2 3 import java.util.ArrayList;4 3 import java.util.HashMap; 5 4 import java.util.List; … … 8 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 8 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 10 import org.openstreetmap.josm.data.osm.Relation;11 9 import org.openstreetmap.josm.data.osm.Way; 10 import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop; 11 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 12 12 13 13 /** … … 19 19 * 20 20 */ 21 public finalclass StopToWayAssigner {21 public class StopToWayAssigner { 22 22 23 private static HashMap<Long, Way> stopToWay = new HashMap<>(); 24 25 private StopToWayAssigner(Relation r) { 26 // Hide default constructor for utils classes 23 /* contains assigned stops */ 24 private static HashMap<PTStop, PTWay> stopToWay = new HashMap<>(); 25 26 /* contains all PTWays of the route relation for which this assigner was created */ 27 private List<PTWay> ptways; 28 29 public StopToWayAssigner(List<PTWay> ptways) { 30 this.ptways = ptways; 27 31 } 28 32 29 public static Way getWay(OsmPrimitive stop, Relation route) { 30 if (stopToWay.containsKey(stop.getId())) { 31 return stopToWay.get(stop.getId()); 33 public PTWay get(PTStop stop) { 34 35 // 1) Search if this stop has already been assigned: 36 if (stopToWay.containsKey(stop)) { 37 return stopToWay.get(stop); 32 38 } 33 34 if (stop.getType().equals(OsmPrimitiveType.NODE)) { 35 List<OsmPrimitive> referrers = stop.getReferrers(); 36 List<Way> referredWays = new ArrayList<>(); 37 for (OsmPrimitive referrer : referrers) { 38 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 39 referredWays.add((Way) referrer); 39 40 // 2) Search if the stop has a stop position: 41 Node stopPosition = stop.getStopPosition(); 42 if (stopPosition != null) { 43 44 // search in the referrers: 45 List<OsmPrimitive> referrers = stopPosition.getReferrers(); 46 for (OsmPrimitive referredPrimitive: referrers) { 47 if (referredPrimitive.getType().equals(OsmPrimitiveType.WAY)) { 48 Way referredWay = (Way) referredPrimitive; 49 for (PTWay ptway: ptways) { 50 if (ptway.getWays().contains(referredWay)) { 51 stopToWay.put(stop, ptway); 52 return ptway; 53 } 54 } 40 55 } 41 56 } 42 if (stop.hasTag("public_transport", "stop_position")) { 43 // TODO 44 Node n = (Node) stop; 45 } 57 46 58 } 59 60 // 3) Run the growing-bounding-boxes algorithm: 61 // TODO 47 62 48 // TODO: algorithm with growing bounding boxes49 // TODO: if found, add to50 63 return null; 51 64 } … … 53 66 /** 54 67 * Remove a map entry 55 * 68 * FIXME: keys should be PTStop 56 69 * @param stopId 57 70 */ 58 public static void removeStopKey( long stopId) {71 public static void removeStopKey(Long stopId) { 59 72 Long id = new Long(stopId); 60 73 if (stopToWay.containsKey(id)) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java
r32277 r32303 32 32 public static final int ERROR_CODE_ROAD_TYPE = 3721; 33 33 public static final int ERROR_CODE_DIRECTION = 3731; 34 public static final int ERROR_CODE_END_STOP = 3141; 35 public static final int ERROR_CODE_SPLIT_WAY = 3142; 34 36 35 37 public PTAssitantValidatorTest() { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java
r32299 r32303 1 1 package org.openstreetmap.josm.plugins.pt_assistant.validation; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.ArrayList; 4 6 import java.util.List; 5 7 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 6 9 import org.openstreetmap.josm.data.osm.Relation; 7 import org.openstreetmap.josm.data.osm.RelationMember; 10 import org.openstreetmap.josm.data.osm.Way; 11 import org.openstreetmap.josm.data.validation.Severity; 8 12 import org.openstreetmap.josm.data.validation.Test; 13 import org.openstreetmap.josm.data.validation.TestError; 9 14 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteDataManager; 10 15 import org.openstreetmap.josm.plugins.pt_assistant.data.PTRouteSegment; 11 16 import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop; 12 17 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 13 import org.openstreetmap.josm.plugins.pt_assistant.utils. RouteUtils;18 import org.openstreetmap.josm.plugins.pt_assistant.utils.StopToWayAssigner; 14 19 15 20 /** … … 22 27 public class SegmentChecker extends Checker { 23 28 24 /* 25 * PTRouteSegments that have been validated and are correct. They need to 26 * accessible 27 */ 29 /* PTRouteSegments that have been validated and are correct */ 28 30 private static List<PTRouteSegment> correctSegments = new ArrayList<PTRouteSegment>(); 29 31 32 /* Manager of the PTStops and PTWays of the current route */ 30 33 private PTRouteDataManager manager; 34 35 /* Assigns PTStops to nearest PTWays and stores that correspondense */ 36 private StopToWayAssigner assigner; 31 37 32 38 public SegmentChecker(Relation relation, Test test) { 33 39 34 40 super(relation, test); 35 41 36 42 this.manager = new PTRouteDataManager(relation); 43 this.assigner = new StopToWayAssigner(manager.getPTWays()); 37 44 38 45 } 39 46 40 private void performEndstopTest() { 41 47 public void performFirstStopTest() { 48 49 performEndStopTest(manager.getFirstStop()); 50 51 } 52 53 public void performLastStopTest() { 54 55 performEndStopTest(manager.getLastStop()); 56 57 } 58 59 private void performEndStopTest(PTStop endStop) { 42 60 if (manager.getPTStopCount() < 2) { 43 // it does not make sense to check a route that has less than 2 stops 61 // it does not make sense to check a route that has less than 2 62 // stops 44 63 return; 45 64 } 46 47 PTStop firstStop = manager.getFirstStop(); 48 PTStop lastStop = manager.getLastStop(); 49 50 // TODO: we need the stops to be assigned to routes. 65 66 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 78 PTWay endWay = assigner.get(endStop); 79 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; 86 } 87 88 } 89 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 } 98 } 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); 103 } 104 51 105 } 52 106
Note:
See TracChangeset
for help on using the changeset viewer.