Changeset 10907 in osm for applications/editors/josm/plugins
- Timestamp:
- 2008-09-25T19:25:23+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/UnclosedWays.java
r10490 r10907 8 8 import java.util.List; 9 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 import org.openstreetmap.josm.data.osm.OsmUtils; 11 13 import org.openstreetmap.josm.data.osm.Way; 12 import org.openstreetmap.josm.data.osm.OsmUtils;13 import org.openstreetmap.josm.data.coor.LatLon;14 14 import org.openstreetmap.josm.plugins.validator.Severity; 15 15 import org.openstreetmap.josm.plugins.validator.Test; … … 22 22 * @author stoecker 23 23 */ 24 public class UnclosedWays extends Test 25 26 24 public class UnclosedWays extends Test { 25 /** The already detected errors */ 26 Bag<Way, Way> _errorWays; 27 27 28 /** 29 * Constructor 30 */ 31 public UnclosedWays() 32 { 33 super(tr("Unclosed Ways."), 34 tr("This tests if ways which should be circular are closed.")); 35 } 28 /** 29 * Constructor 30 */ 31 public UnclosedWays() { 32 super(tr("Unclosed Ways."), tr("This tests if ways which should be circular are closed.")); 33 } 36 34 37 @Override 38 public void startTest() 39 { 40 _errorWays = new Bag<Way, Way>(); 41 } 35 @Override 36 public void startTest() { 37 _errorWays = new Bag<Way, Way>(); 38 } 42 39 43 @Override 44 public void endTest() 45 { 46 _errorWays = null; 47 } 40 @Override 41 public void endTest() { 42 _errorWays = null; 43 } 48 44 49 private String type; 50 private String etype; 51 private int mode; 52 private boolean force; 53 public void set(boolean f, int m, String text, String desc) 54 { 55 etype = MessageFormat.format(text, desc); 56 type = tr(text, tr(desc)); 57 mode = m; 58 force = f; 59 } 60 public void set(boolean f, int m, String text) 61 { 62 etype = text; 63 type = tr(text); 64 mode = m; 65 force = f; 66 } 45 private String type; 46 private String etype; 47 private int mode; 48 private boolean force; 67 49 68 @Override 69 public void visit(Way w) 70 { 71 String test; 72 force = false; /* force even if end-to-end distance is long */ 73 type = etype = null; 74 mode = 0; 50 public void set(boolean f, int m, String text, String desc) { 51 etype = MessageFormat.format(text, desc); 52 type = tr(text, tr(desc)); 53 mode = m; 54 force = f; 55 } 75 56 76 if( w.deleted || w.incomplete ) 77 return; 57 public void set(boolean f, int m, String text) { 58 etype = text; 59 type = tr(text); 60 mode = m; 61 force = f; 62 } 78 63 79 test = w.get("natural"); 80 if(test != null) 81 set(!"coastline".equals(test), 1101, marktr("natural type {0}"), test); 82 test = w.get("landuse"); 83 if(test != null) 84 set(true, 1102, marktr("landuse type {0}"), test); 85 test = w.get("amenities"); 86 if(test != null) 87 set(true, 1103, marktr("amenities type {0}"), test); 88 test = w.get("sport"); 89 if(test != null && !test.equals("water_slide")) 90 set(true, 1104, marktr("sport type {0}"), test); 91 test = w.get("tourism"); 92 if(test != null) 93 set(true, 1105, marktr("tourism type {0}"), test); 94 test = w.get("shop"); 95 if(test != null) 96 set(true, 1106, marktr("shop type {0}"), test); 97 test = w.get("leisure"); 98 if(test != null) 99 set(true, 1107, marktr("leisure type {0}"), test); 100 test = w.get("waterway"); 101 if(test != null && test.equals("riverbank")) 102 set(true, 1108, marktr("waterway type {0}"), test); 103 Boolean btest = OsmUtils.getOsmBoolean(w.get("building")); 104 if (btest != null && btest) 105 set(true, 1120, marktr("building")); 106 btest = OsmUtils.getOsmBoolean(w.get("area")); 107 if (btest != null && btest) 108 set(true, 1130, marktr("area")); 64 @Override 65 public void visit(Way w) { 66 String test; 67 force = false; /* force even if end-to-end distance is long */ 68 type = etype = null; 69 mode = 0; 109 70 110 if(type != null) 111 { 112 LatLon s = w.nodes.get(0).coor; 113 LatLon e = w.nodes.get(w.nodes.size()-1).coor; 114 /* take unclosed ways with end-to-end-distance below 10 km */ 115 if(s != e && (force || s.greatCircleDistance(e) < 10000)) 116 { 117 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 118 primitives.add(w); 119 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), type, etype, mode, primitives)); 120 _errorWays.add(w,w); 121 } 122 } 123 } 71 if (w.deleted || w.incomplete) 72 return; 73 74 test = w.get("natural"); 75 if (test != null) 76 set(!"coastline".equals(test), 1101, marktr("natural type {0}"), test); 77 test = w.get("landuse"); 78 if (test != null) 79 set(true, 1102, marktr("landuse type {0}"), test); 80 test = w.get("amenities"); 81 if (test != null) 82 set(true, 1103, marktr("amenities type {0}"), test); 83 test = w.get("sport"); 84 if (test != null && !test.equals("water_slide")) 85 set(true, 1104, marktr("sport type {0}"), test); 86 test = w.get("tourism"); 87 if (test != null) 88 set(true, 1105, marktr("tourism type {0}"), test); 89 test = w.get("shop"); 90 if (test != null) 91 set(true, 1106, marktr("shop type {0}"), test); 92 test = w.get("leisure"); 93 if (test != null) 94 set(true, 1107, marktr("leisure type {0}"), test); 95 test = w.get("waterway"); 96 if (test != null && test.equals("riverbank")) 97 set(true, 1108, marktr("waterway type {0}"), test); 98 Boolean btest = OsmUtils.getOsmBoolean(w.get("building")); 99 if (btest != null && btest) 100 set(true, 1120, marktr("building")); 101 btest = OsmUtils.getOsmBoolean(w.get("area")); 102 if (btest != null && btest) 103 set(true, 1130, marktr("area")); 104 105 if (type != null) { 106 LatLon s = w.nodes.get(0).coor; 107 LatLon e = w.nodes.get(w.nodes.size() - 1).coor; 108 /* take unclosed ways with end-to-end-distance below 10 km */ 109 if (s != e && (force || s.greatCircleDistance(e) < 10000)) { 110 List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(); 111 List<OsmPrimitive> highlight = new ArrayList<OsmPrimitive>(); 112 primitives.add(w); 113 // The important parts of an unclosed way are the first and 114 // the last node which should be connected, therefore we highlight them 115 highlight.add(w.nodes.get(0)); 116 highlight.add(w.nodes.get(w.nodes.size() - 1)); 117 errors.add(new TestError(this, Severity.WARNING, tr("Unclosed way"), type, etype, mode, primitives, 118 highlight)); 119 _errorWays.add(w, w); 120 } 121 } 122 } 124 123 }
Note:
See TracChangeset
for help on using the changeset viewer.