[OSM-dev] [PATCH] make JOSM validator plugin detect empty ways
Dave Hansen
dave at sr71.net
Wed Aug 8 00:36:13 BST 2007
I've been working on some conversion scripts to make .osm files from
TIGER data. I screwed up in those scripts and ended up creating a bunch
of ways that have no segments in them. The web server correctly detects
these and won't let me upload them. You never have to worry about these
with downloaded data, but a plain opened OSM file might have them.
-- Dave
Index: src/org/openstreetmap/josm/plugins/validator/tests/EmptyWays.java
===================================================================
--- src/org/openstreetmap/josm/plugins/validator/tests/EmptyWays.java (revision 0)
+++ src/org/openstreetmap/josm/plugins/validator/tests/EmptyWays.java (revision 0)
@@ -0,0 +1,65 @@
+package org.openstreetmap.josm.plugins.validator.tests;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
+
+import java.awt.geom.Point2D;
+import java.util.*;
+
+import org.openstreetmap.josm.data.osm.*;
+import org.openstreetmap.josm.plugins.validator.*;
+import org.openstreetmap.josm.plugins.validator.util.Bag;
+import org.openstreetmap.josm.command.*;
+
+/**
+ * Checks for similar named ways, symptom of a possible typo. It uses the
+ * Levenshtein distance to check for similarity
+ *
+ * @author frsantos
+ */
+public class EmptyWays extends Test
+{
+ /**
+ * Constructor
+ */
+ public EmptyWays()
+ {
+ super(tr("Empty Ways."),
+ tr("This test checks for ways that have no segments in them."));
+ }
+
+ @Override
+ public Command fixError(TestError testError)
+ {
+ Way w = (Way)testError.getPrimitives().get(0);
+
+ List<Command> cmds = new ArrayList<Command>();
+ cmds.add(new DeleteCommand(testError.getPrimitives()));
+ return new SequenceCommand(tr("Delete Ways"), cmds);
+ }
+ @Override
+ public boolean isFixable(TestError testError)
+ {
+ return (testError.getTester() instanceof EmptyWays);
+ }
+
+ @Override
+ public void startTest()
+ {
+ }
+
+ @Override
+ public void endTest()
+ {
+ }
+
+ @Override
+ public void visit(Way w)
+ {
+ if( w.deleted )
+ return;
+ if (w.segments.size() > 0)
+ return;
+ errors.add(new TestError(this, Severity.WARNING, tr("Empty ways"), w));
+ }
+
+}
Index: src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java
===================================================================
--- src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java (revision 3894)
+++ src/org/openstreetmap/josm/plugins/validator/OSMValidatorPlugin.java (working copy)
@@ -53,6 +53,7 @@
ReusedSegment.class,
CrossingSegments.class,
SimilarNamedWays.class,
+ EmptyWays.class,
};
/**
More information about the dev
mailing list