Hi Felix, Please try the attached patch on the original tile and see if it fixes the problem.
Cheers, Mark
diff --git a/src/uk/me/parabola/imgfmt/app/trergn/LinePreparer.java b/src/uk/me/parabola/imgfmt/app/trergn/LinePreparer.java index 122d811..9fb07a2 100644 --- a/src/uk/me/parabola/imgfmt/app/trergn/LinePreparer.java +++ b/src/uk/me/parabola/imgfmt/app/trergn/LinePreparer.java @@ -68,7 +68,7 @@ class LinePreparer { * * @return A class containing the writen byte stream. */ - public BitWriter makeBitStream() { + public BitWriter makeBitStream(int minPointsRequired) { assert xBase >= 0 && yBase >= 0; @@ -117,12 +117,15 @@ class LinePreparer { if (extraBit) bw.put1(false); + int numPointsEncoded = 1; for (int i = 0; i < deltas.length; i+=2) { int dx = deltas[i]; int dy = deltas[i + 1]; if (dx == 0 && dy == 0) continue; + ++numPointsEncoded; + if (log.isDebugEnabled()) log.debug("x delta", dx, "~", xbits); assert dx >> xbits == 0 || dx >> xbits == -1; @@ -154,6 +157,10 @@ class LinePreparer { if (log.isDebugEnabled()) log.debug(bw); + + if(numPointsEncoded < minPointsRequired) + return null; + return bw; } diff --git a/src/uk/me/parabola/imgfmt/app/trergn/Polyline.java b/src/uk/me/parabola/imgfmt/app/trergn/Polyline.java index b52774c..66a913c 100644 --- a/src/uk/me/parabola/imgfmt/app/trergn/Polyline.java +++ b/src/uk/me/parabola/imgfmt/app/trergn/Polyline.java @@ -78,17 +78,17 @@ public class Polyline extends MapObject { * @param file A reference to the file that should be written to. */ public void write(ImgFileWriter file) { - // If there is nothing to do, then do nothing. - if (points.size() < 2) { - log.debug("less than two points, not writing"); - return; - } // Prepare for writing by doing all the required calculations. // Prepare the information that we need. LinePreparer w = new LinePreparer(this); - BitWriter bw = w.makeBitStream(); + int minPointsRequired = (this instanceof Polygon)? 3 : 2; + BitWriter bw = w.makeBitStream(minPointsRequired); + if(bw == null) { + log.warn("Encoded " + ((this instanceof Polygon)? "polygon" : "polyline") + " has less than " + minPointsRequired + " points, discarding"); + return; + } // The type of feature, also contains a couple of flags hidden inside. byte b1 = (byte) getType(); @@ -149,6 +149,18 @@ public class Polyline extends MapObject { int labelOff = getLabel().getOffset(); byte[] extraBytes = getExtTypeExtraBytes(); + // need to prepare line info before outputing lat/lon + LinePreparer w = new LinePreparer(this); + int minPointsRequired = (this instanceof Polygon)? 3 : 2; + BitWriter bw = w.makeBitStream(minPointsRequired); + if(bw == null) { + log.warn("Encoded " + ((this instanceof Polygon)? "polygon" : "polyline") + " has less than " + minPointsRequired + " points, discarding"); + return; + } + int blen = bw.getLength(); + assert blen > 1 : "zero length bitstream"; + assert blen < 0x10000 : "bitstream too long " + blen; + if(labelOff != 0) type |= 0x20; // has label if(extraBytes != null) @@ -156,13 +168,6 @@ public class Polyline extends MapObject { stream.write(type >> 8); stream.write(type); - // need to prepare line info before outputing lat/lon - LinePreparer w = new LinePreparer(this); - BitWriter bw = w.makeBitStream(); - int blen = bw.getLength(); - assert blen > 1 : "zero length bitstream"; - assert blen < 0x10000 : "bitstream too long " + blen; - int deltaLong = getDeltaLong(); int deltaLat = getDeltaLat(); stream.write(deltaLong);
_______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev