1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.Way;
|
---|
7 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
8 | import org.openstreetmap.josm.data.validation.Test;
|
---|
9 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
10 | import org.openstreetmap.josm.tools.Geometry;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Check cyclic ways for errors
|
---|
14 | *
|
---|
15 | * @author jrreid
|
---|
16 | */
|
---|
17 | public class WronglyOrderedWays extends Test {
|
---|
18 |
|
---|
19 | // CHECKSTYLE.OFF: SingleSpaceSeparator
|
---|
20 | protected static final int WRONGLY_ORDERED_COAST = 1001;
|
---|
21 | protected static final int WRONGLY_ORDERED_LAND = 1003;
|
---|
22 | // CHECKSTYLE.ON: SingleSpaceSeparator
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructor
|
---|
26 | */
|
---|
27 | public WronglyOrderedWays() {
|
---|
28 | super(tr("Wrongly Ordered Ways"),
|
---|
29 | tr("This test checks the direction of water, land and coastline ways."));
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public void visit(Way w) {
|
---|
34 |
|
---|
35 | if (!w.isUsable() || !w.isClosed())
|
---|
36 | return;
|
---|
37 |
|
---|
38 | String natural = w.get("natural");
|
---|
39 | if (natural == null)
|
---|
40 | return;
|
---|
41 | else if ("coastline".equals(natural) && Geometry.isClockwise(w)) {
|
---|
42 | reportError(w, tr("Reversed coastline: land not on left side"), WRONGLY_ORDERED_COAST);
|
---|
43 | } else if ("land".equals(natural) && Geometry.isClockwise(w)) {
|
---|
44 | reportError(w, tr("Reversed land: land not on left side"), WRONGLY_ORDERED_LAND);
|
---|
45 | } else
|
---|
46 | return;
|
---|
47 |
|
---|
48 | }
|
---|
49 |
|
---|
50 | private void reportError(Way w, String msg, int type) {
|
---|
51 | errors.add(TestError.builder(this, Severity.WARNING, type)
|
---|
52 | .message(msg)
|
---|
53 | .primitives(w)
|
---|
54 | .build());
|
---|
55 | }
|
---|
56 | }
|
---|