Index: src/uk/me/parabola/splitter/AreaSplitter.java
===================================================================
--- src/uk/me/parabola/splitter/AreaSplitter.java	(revision 25)
+++ src/uk/me/parabola/splitter/AreaSplitter.java	(working copy)
@@ -40,7 +40,8 @@
 	 */
 	public AreaList split(SubArea area, int max) {
 		LinkedList<SubArea> l = new LinkedList<SubArea>();
-
+        double maxDegrees = 45.0;
+		
 		l.add(area);
 
 		boolean notDone = true;
@@ -55,24 +56,32 @@
 					continue;
 				}
 
+				Area bounds = workarea.getBounds();
 				int size = map.size();
-				System.out.println("comparing size " + workarea.getSize());
-				if (size < max) {
+				SubArea[] sub;
+
+				if (bounds.getWidth() > maxDegrees) {
+					System.out.println("Need to split width");
+					sub = splitWidth(workarea);
+				} else if (bounds.getHeight() > maxDegrees) {
+					System.out.println("Need to split height");
+					sub = splitHeight(workarea);					
+				} else  if (size >= max) {
+					System.out.println("Need to split due to size " + workarea.getSize());
+					int height = bounds.getHeight();
+					int width1 = (int) (bounds.getWidth() * Math.cos(Math.toRadians(Utils.toDegrees(bounds.getMinLat()))));
+					int width2 = (int) (bounds.getWidth() * Math.cos(Math.toRadians(Utils.toDegrees(bounds.getMaxLat()))));
+					int width = Math.max(width1,width2);
+					if (height > width)
+						sub = splitVert(workarea);
+					else
+						sub = splitHoriz(workarea);
+				} else {
 					workarea.clear();
 					continue;
 				}
-				System.out.println("Need to split");
-
+				
 				notDone = true;
-				Area bounds = workarea.getBounds();
-				int height = bounds.getHeight();
-				int width = (int) (bounds.getWidth() * Math.cos(Math.toRadians(Utils.toDegrees(bounds.getMinLat()))));
-				SubArea[] sub;
-				if (height > width)
-					sub = splitVert(workarea);
-				else
-					sub = splitHoriz(workarea);
-
 				it.set(sub[0]);
 				it.add(sub[1]);
 				workarea.clear();
@@ -182,6 +191,87 @@
 		return new SubArea[]{a1, a2};
 	}
 
+	private SubArea[] splitWidth(SubArea base) {
+		Area bounds = base.getBounds();
+		int left = bounds.getMinLong();
+		int right = bounds.getMaxLong();
+		int width = bounds.getWidth();
+		System.out.println("split width size=" + width);
+		System.out.println("left = " + left);
+		System.out.println("right = " + right);
+
+		SplitIntMap baseCoords = base.getCoords();
+
+		int mid = limit(left, right, width/2 );
+		System.out.println("mid = " + mid);
+
+		System.out.println("in " + bounds);
+		Area b1 = new Area(bounds.getMinLat(), bounds.getMinLong(), bounds.getMaxLat(), mid);
+		Area b2 = new Area(bounds.getMinLat(), mid, bounds.getMaxLat(), bounds.getMaxLong());
+
+		System.out.println("out 1 " + b1);
+		System.out.println("out 2 " + b2);
+
+		SubArea a1 = new SubArea(b1);
+		SubArea a2 = new SubArea(b2);
+
+		Iterator<IntIntMap.Entry> it = baseCoords.fastIterator();
+		it = baseCoords.fastDeletingIterator();
+		while (it.hasNext()) {
+			IntIntMap.Entry entry = it.next();
+			int key = entry.getKey();
+			int co = entry.getValue();
+			if (extractLongitude(co) < mid) {
+				a1.put(key, co);
+			} else {
+				a2.put(key, co);
+			}
+		}
+
+		System.out.println("split sizes " + a1.getSize() +", " + a2.getSize());
+		return new SubArea[]{a1, a2};
+	}
+
+	private SubArea[] splitHeight(SubArea base) {
+		System.out.println("split height");
+		Area bounds = base.getBounds();
+		int top = bounds.getMaxLat();
+		int bot = bounds.getMinLat();
+		int height = bounds.getHeight();
+
+		SplitIntMap caseCoords = base.getCoords();
+
+		int mid = limit(bot, top, height/2);
+		System.out.println("bot = " + bot);
+		System.out.println("top = " + top);
+		System.out.println("mid = " + mid);
+
+		Area b1 = new Area(bounds.getMinLat(), bounds.getMinLong(), mid, bounds.getMaxLong());
+		Area b2 = new Area(mid, bounds.getMinLong(), bounds.getMaxLat(), bounds.getMaxLong());
+
+		SubArea a1 = new SubArea(b1);
+		SubArea a2 = new SubArea(b2);
+
+		caseCoords = base.getCoords();
+
+		Iterator<IntIntMap.Entry> it = caseCoords.fastIterator();
+		it = caseCoords.fastDeletingIterator();
+		while (it.hasNext()) {
+			IntIntMap.Entry entry = it.next();
+			int key = entry.getKey();
+			int co = entry.getValue();
+			if (extractLatitude(co) <= mid) {
+				a1.put(key, co);
+			} else {
+				a2.put(key, co);
+			}
+		}
+
+		System.out.println("split sizes " + a1.getSize() +", " + a2.getSize());
+
+		return new SubArea[]{a1, a2};
+	}
+	
 	private int extractLatitude(Integer value) {
 		return ((value & 0xffff0000) >> 8);
 	}
