Hello there,

Few weeks ago I reported a bug about closed contour lines. Someone answered me that was an old error. I found the lost patch in the mailing list and I tested it on a huge file. It works both for lines and polygons.

All the best to the dev team,
David

Index: src/uk/me/parabola/mkgmap/filters/DouglasPeuckerFilter.java
===================================================================
--- src/uk/me/parabola/mkgmap/filters/DouglasPeuckerFilter.java (revision 1061)
+++ src/uk/me/parabola/mkgmap/filters/DouglasPeuckerFilter.java (working copy)
@@ -28,7 +28,7 @@
  */
 public class DouglasPeuckerFilter implements MapFilter {
 
-       private static final double ERROR_DISTANCE = 5.4 / 2;   //One unit is 
5.4 m, so error dist is 2.6m
+       private static final double ERROR_DISTANCE = 5.4 / 8;   //One unit is 
5.4 m, so error dist is 0.65m
                                                                                
                                        //Can be increased more, but may lead 
to artifacts on T-crossings
        private final double filterDistance;
        private double maxErrorDistance;
@@ -51,6 +51,8 @@
         * @param next This is used to pass the possibly transformed element 
onward.
         */
        public void doFilter(MapElement element, MapFilterChain next) {
+               boolean is_polygon = false;
+
                // First off we don't touch things if at the highest level of 
detail
                if (resolution == 24) {
                        // XXX 24 is not necessarily the highest level.
@@ -64,13 +66,14 @@
                int n = points.size()-1;
 
                // Create a new list to rewrite the points into. Don't alter 
the original one
-               List<Coord> coords = new ArrayList<Coord>(n);
+               List<Coord> coords = new ArrayList<Coord>(n+1);
                coords.addAll(points);
 
                // If the first point is identic with the last one (a polygon), 
drop it
                // Otherwise douglasPeucker will not work!
                while ((n > 0) && coords.get(0).equals(coords.get(n))) {
                        coords.remove(n);
+                       is_polygon = true; // remember that the point was 
removed for later
                        n--;
                }
 
@@ -105,6 +108,10 @@
 //#endif
                MapLine newline = line.copy();
 
+               // If it was a polygon add the last point again that was 
removed before the Douglas-Peucker algorithm
+               if (is_polygon)
+                       coords.add(coords.get(0));
+               
                newline.setPoints(coords);
                next.doFilter(newline);
        }
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to