Ticket #9311: ParkingNodeInParkingWay.2.diff
File ParkingNodeInParkingWay.2.diff, 11.6 KB (added by , 11 years ago) |
---|
-
src/org/openstreetmap/josm/data/validation/OsmValidator.java
53 53 import org.openstreetmap.josm.data.validation.tests.UntaggedWay; 54 54 import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea; 55 55 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 56 import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay; 56 57 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 57 58 import org.openstreetmap.josm.gui.layer.Layer; 58 59 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 114 115 Addresses.class, // ID 2601 .. 2699 115 116 Highways.class, // ID 2701 .. 2799 116 117 BarriersEntrances.class, // ID 2801 .. 2899 117 OpeningHourTest.class // 2901 .. 2999 118 OpeningHourTest.class, // 2901 .. 2999 119 ParkingNodeInParkingWay.class // 3000 .. 3999 118 120 }; 119 121 120 122 /** -
src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java
1 package org.openstreetmap.josm.data.validation.tests; 2 3 import org.openstreetmap.josm.data.osm.Node; 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.data.osm.Way; 6 import org.openstreetmap.josm.data.validation.Severity; 7 import org.openstreetmap.josm.data.validation.Test; 8 import org.openstreetmap.josm.data.validation.TestError; 9 import org.openstreetmap.josm.tools.Geometry; 10 11 import java.util.*; 12 13 import static org.openstreetmap.josm.tools.I18n.tr; 14 15 /** 16 * Finds nodes tagged with amenity=parking located inside of ways also tagged with amenity=parking. 17 * 18 * @author kalle 19 * @since 2013-11-14 05:14 20 */ 21 public class ParkingNodeInParkingWay extends Test { 22 23 public ParkingNodeInParkingWay() { 24 super(tr("Parking ways"), 25 tr("This test checks that a no enclosed way tagged as amenity=parking " 26 + "contains a node tagged as amenity=parking.")); 27 28 } 29 30 private static final int ERROR_CODE = 3001; 31 32 private Set<Node> nodes = new HashSet<Node>(); 33 private Set<Way> ways = new HashSet<Way>(); 34 35 /** 36 * @param way Way to be inspected 37 * @return True if parameter way is a polygon, i.e. that it begin and end at the same geographical position. 38 */ 39 private boolean isEnclosed(Way way) { 40 return way.getNodes() != null 41 && way.getNodes().size() > 2 42 && (way.getNodes().get(0).equals(way.getNodes().get(way.getNodes().size() -1)) 43 || way.getNodes().get(0).getEastNorth().equals(way.getNodes().get(way.getNodes().size() -1).getEastNorth())); 44 } 45 46 private boolean isParking(OsmPrimitive osmPrimitive) { 47 return ("parking".equals(osmPrimitive.get("amenity"))); 48 } 49 50 @Override 51 public void visit(Way way) { 52 if (isParking(way) && isEnclosed(way)) { 53 ways.add(way); 54 } 55 } 56 57 @Override 58 public void visit(Node node) { 59 if (isParking(node)) { 60 nodes.add(node); 61 } 62 } 63 64 @Override 65 public void endTest() { 66 for (Way way : ways) { 67 for (Node node : nodes) { 68 if (Geometry.nodeInsidePolygon(node, way.getNodes())) { 69 errors.add(new TestError(this, Severity.WARNING, tr("Node with amenity=parking found inside of way with amenity=parking"), ERROR_CODE, Arrays.asList(way, node), Arrays.asList(node))); 70 } 71 } 72 } 73 } 74 } -
src/org/openstreetmap/josm/data/validation/OsmValidator.java
53 53 import org.openstreetmap.josm.data.validation.tests.UntaggedWay; 54 54 import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea; 55 55 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 56 import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay; 56 57 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 57 58 import org.openstreetmap.josm.gui.layer.Layer; 58 59 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 114 115 Addresses.class, // ID 2601 .. 2699 115 116 Highways.class, // ID 2701 .. 2799 116 117 BarriersEntrances.class, // ID 2801 .. 2899 117 OpeningHourTest.class // 2901 .. 2999 118 OpeningHourTest.class, // 2901 .. 2999 119 ParkingNodeInParkingWay.class // 3000 .. 3999 118 120 }; 119 121 120 122 /** -
src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java
1 package org.openstreetmap.josm.data.validation.tests; 2 3 import org.openstreetmap.josm.data.osm.Node; 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.data.osm.Way; 6 import org.openstreetmap.josm.data.validation.Severity; 7 import org.openstreetmap.josm.data.validation.Test; 8 import org.openstreetmap.josm.data.validation.TestError; 9 import org.openstreetmap.josm.tools.Geometry; 10 11 import java.util.*; 12 13 import static org.openstreetmap.josm.tools.I18n.tr; 14 15 /** 16 * Finds nodes tagged with amenity=parking located inside of ways also tagged with amenity=parking. 17 * 18 * @author kalle 19 * @since 2013-11-14 05:14 20 */ 21 public class ParkingNodeInParkingWay extends Test { 22 23 public ParkingNodeInParkingWay() { 24 super(tr("Parking ways"), 25 tr("This test checks that a no enclosed way tagged as amenity=parking " 26 + "contains a node tagged as amenity=parking.")); 27 28 } 29 30 private static final int ERROR_CODE = 3001; 31 32 private Set<Node> nodes = new HashSet<Node>(); 33 private Set<Way> ways = new HashSet<Way>(); 34 35 /** 36 * @param way Way to be inspected 37 * @return True if parameter way is a polygon, i.e. that it begin and end at the same geographical position. 38 */ 39 private boolean isEnclosed(Way way) { 40 return way.getNodes() != null 41 && way.getNodes().size() > 2 42 && (way.getNodes().get(0).equals(way.getNodes().get(way.getNodes().size() -1)) 43 || way.getNodes().get(0).getEastNorth().equals(way.getNodes().get(way.getNodes().size() -1).getEastNorth())); 44 } 45 46 private boolean isDisabled(OsmPrimitive osmPrimitive) { 47 String value = osmPrimitive.get("capacity:disabled"); 48 return (value == null || !"no".equalsIgnoreCase(value)); 49 } 50 51 private boolean isParking(OsmPrimitive osmPrimitive) { 52 return ("parking".equals(osmPrimitive.get("amenity"))); 53 } 54 55 @Override 56 public void visit(Way way) { 57 if (isParking(way) && isEnclosed(way)) { 58 ways.add(way); 59 } 60 } 61 62 @Override 63 public void visit(Node node) { 64 if (isParking(node)) { 65 nodes.add(node); 66 } 67 } 68 69 @Override 70 public void endTest() { 71 for (Way way : ways) { 72 for (Node node : nodes) { 73 if (Geometry.nodeInsidePolygon(node, way.getNodes())) { 74 if (isDisabled(node) && !isDisabled(way)) { 75 errors.add(new TestError(this, Severity.WARNING, tr("Node with amenity=parking found inside of way with amenity=parking"), ERROR_CODE, Arrays.asList(way, node), Arrays.asList(node))); 76 } 77 } 78 } 79 } 80 } 81 } -
src/org/openstreetmap/josm/data/validation/OsmValidator.java
53 53 import org.openstreetmap.josm.data.validation.tests.UntaggedWay; 54 54 import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea; 55 55 import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays; 56 import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay; 56 57 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 57 58 import org.openstreetmap.josm.gui.layer.Layer; 58 59 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 114 115 Addresses.class, // ID 2601 .. 2699 115 116 Highways.class, // ID 2701 .. 2799 116 117 BarriersEntrances.class, // ID 2801 .. 2899 117 OpeningHourTest.class // 2901 .. 2999 118 OpeningHourTest.class, // 2901 .. 2999 119 ParkingNodeInParkingWay.class // 3000 .. 3999 118 120 }; 119 121 120 122 /** -
src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java
1 package org.openstreetmap.josm.data.validation.tests; 2 3 import org.openstreetmap.josm.data.osm.Node; 4 import org.openstreetmap.josm.data.osm.OsmPrimitive; 5 import org.openstreetmap.josm.data.osm.Way; 6 import org.openstreetmap.josm.data.validation.Severity; 7 import org.openstreetmap.josm.data.validation.Test; 8 import org.openstreetmap.josm.data.validation.TestError; 9 import org.openstreetmap.josm.tools.Geometry; 10 11 import java.util.*; 12 13 import static org.openstreetmap.josm.tools.I18n.tr; 14 15 /** 16 * Finds nodes tagged with amenity=parking located inside of ways also tagged with amenity=parking. 17 * 18 * @author kalle 19 * @since 2013-11-14 05:14 20 */ 21 public class ParkingNodeInParkingWay extends Test { 22 23 public ParkingNodeInParkingWay() { 24 super(tr("Parking ways"), 25 tr("This test checks that a no enclosed way tagged as amenity=parking " 26 + "contains a node tagged as amenity=parking.")); 27 28 } 29 30 private static final int ERROR_CODE = 3001; 31 32 private Set<Node> nodes = new HashSet<Node>(); 33 private Set<Way> ways = new HashSet<Way>(); 34 35 /** 36 * @param way Way to be inspected 37 * @return True if parameter way is a polygon, i.e. that it begin and end at the same geographical position. 38 */ 39 private boolean isEnclosed(Way way) { 40 return way.getNodes() != null 41 && way.getNodes().size() > 2 42 && (way.getNodes().get(0).equals(way.getNodes().get(way.getNodes().size() -1)) 43 || way.getNodes().get(0).getEastNorth().equals(way.getNodes().get(way.getNodes().size() -1).getEastNorth())); 44 } 45 46 private boolean isDisabled(OsmPrimitive osmPrimitive) { 47 String value = osmPrimitive.get("capacity:disabled"); 48 return value != null && !"no".equalsIgnoreCase(value); 49 } 50 51 private boolean isParking(OsmPrimitive osmPrimitive) { 52 return ("parking".equals(osmPrimitive.get("amenity"))); 53 } 54 55 @Override 56 public void visit(Way way) { 57 if (isParking(way) && isEnclosed(way)) { 58 ways.add(way); 59 } 60 } 61 62 @Override 63 public void visit(Node node) { 64 if (isParking(node)) { 65 nodes.add(node); 66 } 67 } 68 69 @Override 70 public void endTest() { 71 for (Way way : ways) { 72 for (Node node : nodes) { 73 if (Geometry.nodeInsidePolygon(node, way.getNodes())) { 74 if (isDisabled(node) && !isDisabled(way)) { 75 errors.add(new TestError(this, Severity.WARNING, tr("Node with amenity=parking found inside of way with amenity=parking"), ERROR_CODE, Arrays.asList(way, node), Arrays.asList(node))); 76 } 77 } 78 } 79 } 80 } 81 }