| | 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 | } |