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.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.Main;
|
---|
8 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
9 | import org.openstreetmap.josm.data.osm.Way;
|
---|
10 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
11 | import org.openstreetmap.josm.data.validation.Test;
|
---|
12 | import org.openstreetmap.josm.data.validation.TestError;
|
---|
13 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Checks for untagged ways
|
---|
17 | *
|
---|
18 | * @since 8320
|
---|
19 | */
|
---|
20 | public class LongSegment extends Test {
|
---|
21 |
|
---|
22 | /** Long segment error */
|
---|
23 | protected static final int LONG_SEGMENT = 3501;
|
---|
24 | /** Maximum segment length for this test */
|
---|
25 | protected int maxlength;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Constructor
|
---|
29 | */
|
---|
30 | public LongSegment() {
|
---|
31 | super(tr("Long segments"),
|
---|
32 | tr("This tests for long way segments, which are usually errors."));
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public void visit(Way w) {
|
---|
37 | if (w.hasTag("route", "ferry")) {
|
---|
38 | return;
|
---|
39 | }
|
---|
40 | Double length = w.getLongestSegmentLength();
|
---|
41 | if (length > maxlength) {
|
---|
42 | length /= 1000.0;
|
---|
43 | errors.add(TestError.builder(this, Severity.WARNING, LONG_SEGMENT)
|
---|
44 | .message(tr("Long segments"), marktr("Very long segment of {0} kilometers"), length.intValue())
|
---|
45 | .primitives(w)
|
---|
46 | .build());
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public void startTest(ProgressMonitor monitor) {
|
---|
52 | super.startTest(monitor);
|
---|
53 | maxlength = Main.pref.getInteger("validator.maximum.segment.length", 15_000);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public boolean isPrimitiveUsable(OsmPrimitive p) {
|
---|
58 | return p.isUsable() && p instanceof Way && ((Way) p).getNodesCount() > 1; // test only Ways with at least 2 nodes
|
---|
59 | }
|
---|
60 | }
|
---|