Changeset 32656 in osm for applications/editors/josm/plugins
- Timestamp:
- 2016-07-15T02:59:02+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/pt_assistant
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTRouteDataManager.java
r32522 r32656 182 182 } 183 183 184 /** 185 * Returns a PTStop that matches the given id. Returns null if not found 186 * 187 * @param id 188 * @return 189 */ 190 public PTStop getPTStop(long id) { 191 for (PTStop stop : this.ptstops) { 192 if (stop.getStopPosition() != null && stop.getStopPosition().getId() == id) { 193 return stop; 194 } 195 196 if (stop.getPlatform() != null && stop.getPlatform().getId() == id) { 197 return stop; 198 } 199 } 200 201 return null; 202 } 203 204 /** 205 * Returns a PTWay that matches the given id. Returns null if not found 206 * 207 * @param id 208 * @return 209 */ 210 public PTWay getPTWay(long id) { 211 for (PTWay ptway : this.ptways) { 212 for (Way way : ptway.getWays()) { 213 if (way.getId() == id) { 214 return ptway; 215 } 216 } 217 } 218 return null; 219 } 184 220 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/data/PTStop.java
r32585 r32656 5 5 import java.util.List; 6 6 7 import org.openstreetmap.josm.Main;8 7 import org.openstreetmap.josm.data.coor.LatLon; 9 8 import org.openstreetmap.josm.data.osm.BBox; … … 147 146 BBox platformBBox = new BBox(ax, ay, bx, by); 148 147 149 Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes(); 148 // Collection<Node> allNodes = Main.getLayerManager().getEditDataSet().getNodes(); 149 Collection<Node> allNodes = platform.getDataSet().getNodes(); 150 150 for (Node currentNode : allNodes) { 151 151 if (platformBBox.bounds(currentNode.getBBox()) && currentNode.hasTag("public_transport", "stop_position")) { -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/RouteUtils.java
r32647 r32656 239 239 240 240 if (isWaySuitableForBuses(way) || way.hasTag("railway", "tram") || way.hasTag("railway", "subway") 241 || way.hasTag("rai ilway", "subway") || way.hasTag("railway", "light_rail")242 || way.hasTag("railway", " train")) {241 || way.hasTag("railway", "subway") || way.hasTag("railway", "light_rail") 242 || way.hasTag("railway", "rail")) { 243 243 return true; 244 244 } -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/utils/StopToWayAssigner.java
r32303 r32656 1 1 package org.openstreetmap.josm.plugins.pt_assistant.utils; 2 2 3 import java.util.ArrayList; 4 import java.util.Collection; 3 5 import java.util.HashMap; 4 6 import java.util.List; 5 7 import java.util.Set; 8 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.osm.BBox; 6 11 import org.openstreetmap.josm.data.osm.Node; 7 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 8 13 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 14 import org.openstreetmap.josm.data.osm.Relation; 15 import org.openstreetmap.josm.data.osm.RelationMember; 9 16 import org.openstreetmap.josm.data.osm.Way; 10 17 import org.openstreetmap.josm.plugins.pt_assistant.data.PTStop; 11 18 import org.openstreetmap.josm.plugins.pt_assistant.data.PTWay; 19 import org.openstreetmap.josm.tools.Pair; 12 20 13 21 /** … … 23 31 /* contains assigned stops */ 24 32 private static HashMap<PTStop, PTWay> stopToWay = new HashMap<>(); 25 26 /* contains all PTWays of the route relation for which this assigner was created */ 33 34 /* 35 * contains all PTWays of the route relation for which this assigner was 36 * created 37 */ 27 38 private List<PTWay> ptways; 28 39 29 40 public StopToWayAssigner(List<PTWay> ptways) { 30 41 this.ptways = ptways; 31 42 } 32 43 44 /** 45 * Returns the PTWay for the given PTStop 46 * 47 * @param stop 48 * @return 49 */ 33 50 public PTWay get(PTStop stop) { 34 51 35 52 // 1) Search if this stop has already been assigned: 36 53 if (stopToWay.containsKey(stop)) { 37 54 return stopToWay.get(stop); 38 55 } 39 56 40 57 // 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; 58 PTWay ptwayOfStopPosition = findPtwayForNode(stop.getStopPosition()); 59 if (ptwayOfStopPosition != null) { 60 stopToWay.put(stop, ptwayOfStopPosition); 61 return ptwayOfStopPosition; 62 } 63 64 // 3) Search if the stop has a stop_area: 65 List<OsmPrimitive> stopElements = new ArrayList<>(2); 66 if (stop.getStopPosition() != null) { 67 stopElements.add(stop.getStopPosition()); 68 } 69 if (stop.getPlatform() != null) { 70 stopElements.add(stop.getPlatform()); 71 } 72 Set<Relation> parents = Node.getParentRelations(stopElements); 73 for (Relation parentRelation : parents) { 74 if (parentRelation.hasTag("public_transport", "stop_area")) { 75 for (RelationMember rm : parentRelation.getMembers()) { 76 if (rm.getMember().hasTag("public_transport", "stop_position")) { 77 PTWay rmPtway = this.findPtwayForNode(rm.getNode()); 78 if (rmPtway != null) { 79 stopToWay.put(stop, rmPtway); 80 return rmPtway; 53 81 } 54 82 } 55 83 } 56 84 } 57 85 } 86 87 // 4) Run the growing-bounding-boxes algorithm: 88 double searchRadius = 0.001; 89 while (searchRadius < 0.005) { 90 91 PTWay foundWay = this.findNearestWayInRadius(stop.getPlatform(), searchRadius); 92 if (foundWay != null) { 93 stopToWay.put(stop, foundWay); 94 return foundWay; 95 } 96 97 foundWay = this.findNearestWayInRadius(stop.getStopPosition(), searchRadius); 98 if (foundWay != null) { 99 stopToWay.put(stop, foundWay); 100 return foundWay; 101 } 102 103 searchRadius = searchRadius + 0.001; 104 } 105 106 return null; 107 } 108 109 /** 110 * Finds the PTWay of the given stop_position by looking at its referrers 111 * 112 * @param stopPosition 113 * @return 114 */ 115 private PTWay findPtwayForNode(Node stopPosition) { 116 117 if (stopPosition == null) { 118 return null; 119 } 120 121 // search in the referrers: 122 List<OsmPrimitive> referrers = stopPosition.getReferrers(); 123 for (OsmPrimitive referredPrimitive : referrers) { 124 if (referredPrimitive.getType().equals(OsmPrimitiveType.WAY)) { 125 Way referredWay = (Way) referredPrimitive; 126 for (PTWay ptway : ptways) { 127 if (ptway.getWays().contains(referredWay)) { 128 return ptway; 129 } 130 } 131 } 132 } 133 134 return null; 135 } 136 137 /** 138 * Finds the PTWay in the given radius of the OsmPrimitive. The PTWay has to 139 * belong to the route relation for which this StopToWayAssigner was 140 * created. If multiple PTWays were found, the closest one is chosen. 141 * 142 * @param platform 143 * @param searchRadius 144 * @return 145 */ 146 private PTWay findNearestWayInRadius(OsmPrimitive platform, double searchRadius) { 147 148 if (platform == null) { 149 return null; 150 } 151 152 LatLon platformCenter = platform.getBBox().getCenter(); 153 Double ax = platformCenter.getX() - searchRadius; 154 Double bx = platformCenter.getX() + searchRadius; 155 Double ay = platformCenter.getY() - searchRadius; 156 Double by = platformCenter.getY() + searchRadius; 157 BBox platformBBox = new BBox(ax, ay, bx, by); 158 159 List<Way> potentialWays = new ArrayList<>(); 160 161 Collection<Node> allNodes = platform.getDataSet().getNodes(); 162 for (Node currentNode : allNodes) { 163 if (platformBBox.bounds(currentNode.getBBox())) { 164 List<OsmPrimitive> referrers = currentNode.getReferrers(); 165 for (OsmPrimitive referrer : referrers) { 166 if (referrer.getType().equals(OsmPrimitiveType.WAY)) { 167 Way referrerWay = (Way) referrer; 168 for (PTWay ptway : this.ptways) { 169 if (ptway.getWays().contains(referrerWay)) { 170 potentialWays.add(referrerWay); 171 } 172 } 173 } 174 } 175 176 } 58 177 } 59 178 60 // 3) Run the growing-bounding-boxes algorithm: 61 // TODO 62 179 Node platformNode = null; 180 if (platform.getType().equals(OsmPrimitiveType.NODE)) { 181 platformNode = (Node) platform; 182 } else { 183 platformNode = new Node(platform.getBBox().getCenter()); 184 } 185 Way nearestWay = null; 186 Double minDistance = Double.MAX_VALUE; 187 for (Way potentialWay: potentialWays) { 188 double distance = this.calculateMinDistance(platformNode, potentialWay); 189 if (distance < minDistance) { 190 minDistance = distance; 191 nearestWay = potentialWay; 192 } 193 } 194 195 for (PTWay ptway: this.ptways) { 196 if (ptway.getWays().contains(nearestWay)) { 197 return ptway; 198 } 199 } 200 63 201 return null; 64 202 } 65 203 66 204 /** 67 * Remove a map entry 68 * FIXME: keys should be PTStop 69 * @param stopId 70 */ 71 public static void removeStopKey(Long stopId) { 72 Long id = new Long(stopId); 73 if (stopToWay.containsKey(id)) { 74 stopToWay.remove(id); 75 } 205 * Calculates the minimum distance between a node and a way 206 * @param node 207 * @param way 208 * @return 209 */ 210 private double calculateMinDistance(Node node, Way way) { 211 212 double minDistance = Double.MAX_VALUE; 213 214 List<Pair<Node, Node>> waySegments = way.getNodePairs(false); 215 for (Pair<Node, Node> waySegment : waySegments) { 216 if (waySegment.a != node && waySegment.b != node) { 217 double distanceToLine = this.calculateDistance(node, waySegment); 218 if (distanceToLine < minDistance) { 219 minDistance = distanceToLine; 220 } 221 } 222 } 223 224 return minDistance; 225 226 } 227 228 /** 229 * // * Calculates the distance from point to segment using formulas for 230 * triangle area. 231 * 232 * @param node 233 * @param waySegment 234 * @return 235 */ 236 private double calculateDistance(Node node, Pair<Node, Node> segment) { 237 238 /* 239 * Let a be the triangle edge between the point and the first node of 240 * the segment. Let b be the triangle edge between the point and the 241 * second node of the segment. Let c be the triangle edge which is the 242 * segment. 243 */ 244 245 double lengthA = node.getCoor().distance(segment.a.getCoor()); 246 double lengthB = node.getCoor().distance(segment.b.getCoor()); 247 double lengthC = segment.a.getCoor().distance(segment.b.getCoor()); 248 249 // calculate triangle area using Feron's formula: 250 double p = (lengthA + lengthB + lengthC) / 2.0; 251 double triangleArea = Math.sqrt(p * (p - lengthA) * (p - lengthB) * (p - lengthC)); 252 253 // calculate the distance from point to segment using the 0.5*c*h 254 // formula for triangle area: 255 return triangleArea * 2.0 / lengthC; 76 256 } 77 257 -
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java
r32650 r32656 87 87 } 88 88 } else if (relation.hasTag("route", "subway")) { 89 if (! relation.hasTag("railway", "subway")) {89 if (!way.hasTag("railway", "subway")) { 90 90 isCorrectRoadType = false; 91 91 } … … 94 94 } 95 95 } else if (relation.hasTag("route", "light_rail")) { 96 if (! relation.hasTag("raiilway", "subway")) {96 if (!way.hasTag("railway", "subway")) { 97 97 isCorrectRoadType = false; 98 98 } … … 101 101 } 102 102 } else if (relation.hasTag("route", "light_rail")) { 103 if (! relation.hasTag("railway", "light_rail")) {103 if (!way.hasTag("railway", "light_rail")) { 104 104 isCorrectRoadType = false; 105 105 } … … 108 108 } 109 109 } else if (relation.hasTag("route", "train")) { 110 if (! relation.hasTag("railway", "train")) {110 if (!way.hasTag("railway", "rail")) { 111 111 isCorrectRoadType = false; 112 112 }
Note:
See TracChangeset
for help on using the changeset viewer.