Ticket #9311: ParkingNodeInParkingWay.2.diff

File ParkingNodeInParkingWay.2.diff, 11.6 KB (added by kalle, 11 years ago)

Version that does not warn if node has (capacity:disabled !=null && !"no") and way does not.

  • src/org/openstreetmap/josm/data/validation/OsmValidator.java

     
    5353import org.openstreetmap.josm.data.validation.tests.UntaggedWay;
    5454import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea;
    5555import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays;
     56import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay;
    5657import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5758import org.openstreetmap.josm.gui.layer.Layer;
    5859import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    114115        Addresses.class, // ID 2601 .. 2699
    115116        Highways.class, // ID 2701 .. 2799
    116117        BarriersEntrances.class, // ID 2801 .. 2899
    117         OpeningHourTest.class // 2901 .. 2999
     118        OpeningHourTest.class, // 2901 .. 2999
     119        ParkingNodeInParkingWay.class // 3000 .. 3999
    118120    };
    119121
    120122    /**
  • src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java

     
     1package org.openstreetmap.josm.data.validation.tests;
     2
     3import org.openstreetmap.josm.data.osm.Node;
     4import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.data.osm.Way;
     6import org.openstreetmap.josm.data.validation.Severity;
     7import org.openstreetmap.josm.data.validation.Test;
     8import org.openstreetmap.josm.data.validation.TestError;
     9import org.openstreetmap.josm.tools.Geometry;
     10
     11import java.util.*;
     12
     13import 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 */
     21public 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

     
    5353import org.openstreetmap.josm.data.validation.tests.UntaggedWay;
    5454import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea;
    5555import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays;
     56import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay;
    5657import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5758import org.openstreetmap.josm.gui.layer.Layer;
    5859import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    114115        Addresses.class, // ID 2601 .. 2699
    115116        Highways.class, // ID 2701 .. 2799
    116117        BarriersEntrances.class, // ID 2801 .. 2899
    117         OpeningHourTest.class // 2901 .. 2999
     118        OpeningHourTest.class, // 2901 .. 2999
     119        ParkingNodeInParkingWay.class // 3000 .. 3999
    118120    };
    119121
    120122    /**
  • src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java

     
     1package org.openstreetmap.josm.data.validation.tests;
     2
     3import org.openstreetmap.josm.data.osm.Node;
     4import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.data.osm.Way;
     6import org.openstreetmap.josm.data.validation.Severity;
     7import org.openstreetmap.josm.data.validation.Test;
     8import org.openstreetmap.josm.data.validation.TestError;
     9import org.openstreetmap.josm.tools.Geometry;
     10
     11import java.util.*;
     12
     13import 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 */
     21public 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

     
    5353import org.openstreetmap.josm.data.validation.tests.UntaggedWay;
    5454import org.openstreetmap.josm.data.validation.tests.WayConnectedToArea;
    5555import org.openstreetmap.josm.data.validation.tests.WronglyOrderedWays;
     56import org.openstreetmap.josm.data.validation.tests.ParkingNodeInParkingWay;
    5657import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    5758import org.openstreetmap.josm.gui.layer.Layer;
    5859import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    114115        Addresses.class, // ID 2601 .. 2699
    115116        Highways.class, // ID 2701 .. 2799
    116117        BarriersEntrances.class, // ID 2801 .. 2899
    117         OpeningHourTest.class // 2901 .. 2999
     118        OpeningHourTest.class, // 2901 .. 2999
     119        ParkingNodeInParkingWay.class // 3000 .. 3999
    118120    };
    119121
    120122    /**
  • src/org/openstreetmap/josm/data/validation/tests/ParkingNodeInParkingWay.java

     
     1package org.openstreetmap.josm.data.validation.tests;
     2
     3import org.openstreetmap.josm.data.osm.Node;
     4import org.openstreetmap.josm.data.osm.OsmPrimitive;
     5import org.openstreetmap.josm.data.osm.Way;
     6import org.openstreetmap.josm.data.validation.Severity;
     7import org.openstreetmap.josm.data.validation.Test;
     8import org.openstreetmap.josm.data.validation.TestError;
     9import org.openstreetmap.josm.tools.Geometry;
     10
     11import java.util.*;
     12
     13import 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 */
     21public 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}