This is just a rework of my earlier patch with the filter class renamed
so that there can be no doubt as to what it does.

As before, the rational behind this is to stop the DP filter from
deleting the end points of lines that have been introduced by either
the clipper or the polygon splitter (such lines are always horizontal
or vertical). Yes, it will also preserve horizontal and vertical lines
that occur in the OSM data. Whether that is good or bad, I do not know.

Mark


diff --git a/src/uk/me/parabola/mkgmap/build/MapBuilder.java b/src/uk/me/parabola/mkgmap/build/MapBuilder.java
index 1745286..d98dc2e 100644
--- a/src/uk/me/parabola/mkgmap/build/MapBuilder.java
+++ b/src/uk/me/parabola/mkgmap/build/MapBuilder.java
@@ -60,6 +60,7 @@ import uk.me.parabola.mkgmap.filters.LineSplitterFilter;
 import uk.me.parabola.mkgmap.filters.LineMergeFilter;
 import uk.me.parabola.mkgmap.filters.MapFilter;
 import uk.me.parabola.mkgmap.filters.MapFilterChain;
+import uk.me.parabola.mkgmap.filters.PreserveHorizontalAndVerticalLinesFilter;
 import uk.me.parabola.mkgmap.filters.PolygonSplitterFilter;
 import uk.me.parabola.mkgmap.filters.RemoveEmpty;
 import uk.me.parabola.mkgmap.filters.RoundCoordsFilter;
@@ -882,6 +883,7 @@ public class MapBuilder implements Configurable {
 
 		LayerFilterChain filters = new LayerFilterChain(config);
 		if (enableLineCleanFilters && (res < 24)) {
+			filters.addFilter(new PreserveHorizontalAndVerticalLinesFilter());
 			filters.addFilter(new RoundCoordsFilter());
 			filters.addFilter(new SizeFilter());
 			if(reducePointError > 0)
@@ -920,6 +922,7 @@ public class MapBuilder implements Configurable {
 		config.setResolution(res);
 		LayerFilterChain filters = new LayerFilterChain(config);
 		if (enableLineCleanFilters && (res < 24)) {
+			filters.addFilter(new PreserveHorizontalAndVerticalLinesFilter());
 			filters.addFilter(new RoundCoordsFilter());
 			filters.addFilter(new SizeFilter());
 			//DouglasPeucker behaves at the moment not really optimal at low zooms, but acceptable.
diff --git a/src/uk/me/parabola/mkgmap/filters/PreserveHorizontalAndVerticalLinesFilter.java b/src/uk/me/parabola/mkgmap/filters/PreserveHorizontalAndVerticalLinesFilter.java
new file mode 100644
index 0000000..3d98673
--- /dev/null
+++ b/src/uk/me/parabola/mkgmap/filters/PreserveHorizontalAndVerticalLinesFilter.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2007 Steve Ratcliffe
+ * 
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ * 
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ */
+package uk.me.parabola.mkgmap.filters;
+
+import uk.me.parabola.imgfmt.app.Coord;
+import uk.me.parabola.mkgmap.general.MapElement;
+import uk.me.parabola.mkgmap.general.MapLine;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class PreserveHorizontalAndVerticalLinesFilter implements MapFilter {
+
+	int shift;
+
+	public void init(FilterConfig config) {
+		shift = config.getShift();
+	}
+
+	/**
+	 * @param element A map element that will be a line or a polygon.
+	 * @param next This is used to pass the possibly transformed element onward.
+	 */
+	public void doFilter(MapElement element, MapFilterChain next) {
+		MapLine line = (MapLine) element;
+
+		if(shift != 0) {
+			// preserve the end points of horizontal and vertical lines
+			List<Coord> points = line.getPoints();
+			Coord first = points.get(0);
+			Coord prev = first;
+			Coord last = first;
+			for(int i = 1; i < points.size(); ++i) {
+				last = points.get(i);
+				if(last.getLatitude() == prev.getLatitude() ||
+				   last.getLongitude() == prev.getLongitude()) {
+					last.preserved(true);
+					prev.preserved(true);
+				}
+				prev = last;
+			}
+			// if the way has the same point at each end, make sure
+			// that if either is preserved, they both are
+			if(first.equals(last) && first.preserved() != last.preserved()) {
+				first.preserved(true);
+				last.preserved(true);
+			}
+		}
+
+		next.doFilter(line);
+	}
+}
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to