Index: src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java
===================================================================
--- src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java	(Revision 920)
+++ src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java	(Arbeitskopie)
@@ -60,6 +60,7 @@
 	private final String[] nameTagList;
 
 	private final MapCollector collector;
+	private final int maxSimplifyError;
 
 	private Clipper clipper = Clipper.NULL_CLIPPER;
 	private Area bbox = null;
@@ -88,8 +89,9 @@
 		}
 	};
 
-	public StyledConverter(Style style, MapCollector collector) {
+	public StyledConverter(Style style, MapCollector collector, int maxSimplifyError) {
 		this.collector = collector;
+		this.maxSimplifyError = maxSimplifyError;
 
 		nameTagList = style.getNameTagList();
 		wayRules = style.getWayRules();
@@ -215,6 +217,7 @@
 	}
 
 	private void addLine(Way way, GType gt) {
+		simplifyWay(way);
 		MapLine line = new MapLine();
 		elementSetup(line, gt, way);
 		line.setPoints(way.getPoints());
@@ -358,11 +361,14 @@
 	}
 
 	void addRoadWithoutLoops(Way way, GType gt) {
+		simplifyWay(way);
 		List<Integer> nodeIndices = new ArrayList<Integer>();
 		List<Coord> points = way.getPoints();
 		Way trailingWay = null;
 
 		// make sure the way has nodes at each end
+//Comment out nodes?
+//Saves 5% in file size
 		points.get(0).incHighwayCount();
 		points.get(points.size() - 1).incHighwayCount();
 
@@ -622,6 +628,77 @@
 		}
 	}
 
+	void simplifyWay(Way way) 
+	{
+		List<Coord> points = way.getPoints();
+
+		// For now simplify all points, which are not nodes
+		// and no start and no end point
+		// Loop runs downwards, as the list length gets modified while running
+		int endIndex = points.size()-1;
+		for(int i = endIndex-1; i > 0; i--) {
+			Coord p = points.get(i);
+			int highwayCount = p.getHighwayCount();
+			
+			// This was the first attemp, it reduces the map maximal,
+			// but gives sometimes crazy maps, as all segemnts gets straightened.
+			//if(highwayCount <= 1) {
+			//	points.remove(i);
+
+			// This uses the douglas peucker algorithm
+			if (highwayCount > 1) {
+				douglasPeucker(points, i, endIndex, maxSimplifyError);
+				endIndex = i;
+				i--;
+			}
+		}
+	}
+
+	
+	/**
+	 * Reduces point density by Douglas-Peucker algorithm
+	 *
+	 * @param relation The relation to convert.
+	 * returns number of rmeoved points.
+	 */
+	void douglasPeucker(List<Coord> points, int startIndex, int endIndex, double allowedError) 
+	{
+		if (startIndex >= endIndex+1)
+			return;
+
+		double maxDistance = 0;		//Highest distance	
+		int maxIndex = endIndex;	//Index of highest distance
+
+		Coord a = points.get(startIndex);
+		Coord b = points.get(endIndex);
+		double ab = a.distance(b);
+
+		// Find point with highest distance.
+		// Loop runs downwards, as the list length gets modified while running
+		for(int i = endIndex-1; i > startIndex; i--) {
+			Coord p = points.get(i);
+			double ap = p.distance(a);
+			double bp = p.distance(b);
+			double abpa = (ab+ap+bp)/2;
+			double distance = 2 * Math.sqrt(abpa * (abpa-ab) * (abpa-ap) * (abpa-bp)) / ab;
+			if (distance > maxDistance) {
+				maxDistance = distance;
+				maxIndex = i;
+			}
+		}
+		if (maxDistance > allowedError) {
+			// Call recursive for both parts
+			douglasPeucker(points, maxIndex, endIndex, allowedError);		
+			douglasPeucker(points, startIndex, maxIndex, allowedError);		
+		}
+		else {
+			// All points in tolerance, delete all of them.
+			for(int i = endIndex-1; i > startIndex; i--) {
+				points.remove(i);
+			}
+		}
+	}
+
 	int getSpeedIdx(String tag)
 	{
 		double kmh = 0.0;
Index: src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5MapDataSource.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5MapDataSource.java	(Revision 920)
+++ src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5MapDataSource.java	(Arbeitskopie)
@@ -32,6 +32,7 @@
 import uk.me.parabola.mkgmap.osmstyle.eval.SyntaxException;
 import uk.me.parabola.mkgmap.reader.osm.OsmConverter;
 import uk.me.parabola.mkgmap.reader.osm.Style;
+import uk.me.parabola.util.EnhancedProperties;
 
 import org.xml.sax.SAXException;
 
@@ -102,7 +103,7 @@
 	 */
 	private OsmConverter createStyler() {
 
-		Properties props = getConfig();
+		EnhancedProperties props = getConfig();
 		String loc = props.getProperty("style-file");
 		if (loc == null)
 			loc = props.getProperty("map-features");
@@ -111,6 +112,8 @@
 		if (loc == null && name == null)
 			name = "default";
 
+		int maxSimplifyError = props.getProperty("reduce-point-density", 0);	//Default error 0 means simplify off.
+
 		OsmConverter converter;
 		try {
 			// TODO: Move this routine, so that Style implementation reference is outside this package
@@ -118,7 +121,7 @@
 			style.applyOptionOverride(props);
 			setStyle(style);
 
-			converter = new StyledConverter(style, mapper);
+			converter = new StyledConverter(style, mapper, maxSimplifyError);
 		} catch (SyntaxException e) {
 			System.err.println("Error in style: " + e.getMessage());
 			throw new ExitException("Could not open style " + name);
Index: src/uk/me/parabola/mkgmap/CommandArgs.java
===================================================================
--- src/uk/me/parabola/mkgmap/CommandArgs.java	(Revision 920)
+++ src/uk/me/parabola/mkgmap/CommandArgs.java	(Arbeitskopie)
@@ -175,6 +175,13 @@
 		return cp;
 	}
 
+	/**
+	 * Gets the maximum error allowed for symplifying ways
+	 */
+	public int getMaxSymplifyError() {
+		return get("reduce-point-density", 0);
+	}
+
 	public boolean isForceUpper() {
 		return arglist.getProperty("lower-case") == null;
 	}
Index: resources/help/en/options
===================================================================
--- resources/help/en/options	(Revision 920)
+++ resources/help/en/options	(Arbeitskopie)
@@ -76,6 +76,11 @@
 	in the device. See customisation help. The default is the equivalent
 	of: "0=24, 1=22, 2=21, 3=19, 4=18, 5=16" although this may change. 
 
+--reduce-point-density=num
+	Simplifies the ways with the douglas peucker algorithm.
+	num is the maximal allowed error distance, by which the resulting
+	way may differ from the original one.
+
 --name-tag-list
 	Get the tag that will be used to supply the name.  Useful for language
 	variations.  You can supply a list and the first one will be used.
gailj@ubuntu:.../mkgmap>

