[4682] | 1 | package org.openstreetmap.josm.data.validation.tests;
|
---|
| 2 |
|
---|
| 3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 4 |
|
---|
| 5 | import java.util.Arrays;
|
---|
[4950] | 6 | import java.util.List;
|
---|
[4682] | 7 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 9 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
| 10 | import org.openstreetmap.josm.data.osm.Way;
|
---|
| 11 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
| 12 | import org.openstreetmap.josm.data.validation.Test;
|
---|
| 13 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
| 14 | import org.openstreetmap.josm.gui.mappaint.ElemStyles;
|
---|
| 15 |
|
---|
| 16 | public class WayConnectedToArea extends Test {
|
---|
| 17 |
|
---|
| 18 | public WayConnectedToArea() {
|
---|
[4806] | 19 | super(tr("Way connected to Area"), tr("Checks for ways connected to areas."));
|
---|
[4682] | 20 | }
|
---|
| 21 |
|
---|
| 22 | @Override
|
---|
| 23 | public void visit(Way w) {
|
---|
| 24 | if (!w.isUsable() || w.isClosed() || !w.hasKey("highway")) {
|
---|
| 25 | return;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[4950] | 28 | boolean hasway = false;
|
---|
| 29 | List<OsmPrimitive> r = w.firstNode().getReferrers();
|
---|
| 30 | for (OsmPrimitive p : r) {
|
---|
| 31 | if(p != w && p.hasKey("highway")) {
|
---|
| 32 | hasway = true;
|
---|
| 33 | break;
|
---|
| 34 | }
|
---|
[4682] | 35 | }
|
---|
[4950] | 36 | if(!hasway)
|
---|
| 37 | {
|
---|
| 38 | for (OsmPrimitive p : r) {
|
---|
| 39 | testForError(w, w.firstNode(), p);
|
---|
| 40 | }
|
---|
[4682] | 41 | }
|
---|
[4950] | 42 | hasway = false;
|
---|
| 43 | r = w.lastNode().getReferrers();
|
---|
| 44 | for (OsmPrimitive p : r) {
|
---|
| 45 | if(p != w && p.hasKey("highway")) {
|
---|
| 46 | hasway = true;
|
---|
| 47 | break;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 | if(!hasway) {
|
---|
| 51 | for (OsmPrimitive p : r) {
|
---|
| 52 | testForError(w, w.lastNode(), p);
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
[4682] | 55 | }
|
---|
| 56 |
|
---|
| 57 | private void testForError(Way w, Node wayNode, OsmPrimitive p) {
|
---|
[4704] | 58 | if (isArea(p)) {
|
---|
[4682] | 59 | addError(w, wayNode, p);
|
---|
| 60 | } else {
|
---|
| 61 | for (OsmPrimitive r : p.getReferrers()) {
|
---|
| 62 | if (r instanceof Relation
|
---|
| 63 | && r.hasTag("type", "multipolygon")
|
---|
[4704] | 64 | && isArea(r)) {
|
---|
[4682] | 65 | addError(w, wayNode, p);
|
---|
| 66 | break;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[4704] | 72 | private boolean isArea(OsmPrimitive p) {
|
---|
| 73 | return (p.hasKey("landuse") || p.hasKey("natural"))
|
---|
| 74 | && ElemStyles.hasAreaElemStyle(p, false);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[4682] | 77 | private void addError(Way w, Node wayNode, OsmPrimitive p) {
|
---|
| 78 | errors.add(new TestError(this, Severity.WARNING,
|
---|
| 79 | tr("Way terminates on Area"), 2301,
|
---|
| 80 | Arrays.asList(w, p),
|
---|
| 81 | Arrays.asList(wayNode)));
|
---|
| 82 | }
|
---|
| 83 | }
|
---|