# [Tilecache] threshold

Schuyler Erle sderle at metacarta.com
Wed Mar 14 07:39:28 EDT 2007

```On Mon, 2007-03-12 at 10:16 -0800, Brent Pedersen wrote:

> anyhoo, a quick fix is to set threshold in __init__ as something like:
>
> self.threshold = math.abs(bbox[2]/10e4)
> or
> (bbox[2] - bbox[0])/10e4
>
> havent done enough testing to be sure this is the case, but it seems
> to have fixed the problems i was seeing.... and it makes sense.

Brent, thanks for looking at this. Doesn't 10e4 seem kind of arbitrary?
I think that what we really care about is: Is the difference between our
computed tile grid and the tile extents we are being asked for
significantly less than a pixel? Since resolution is measured in
map-units-per-pixel, why don't we just use the resolution at the current
zoom level (or some fraction of it) as our threshold? Can you all try
this patch and let me know if it works for any of you?

--- TileCache/Layer.py  (revision 1807)
+++ TileCache/Layer.py  (local)
@@ -134,15 +133,16 @@
x0 = (minx - self.bbox[0]) / (res * self.size[0])
y0 = (miny - self.bbox[1]) / (res * self.size[1])

-        x = int(x0 + self.threshold / 2)
-        y = int(y0 + self.threshold / 2)
+        threshold = res
+        x = int(x0 + threshold / 2)
+        y = int(y0 + threshold / 2)

if exact:
-            if abs(x - x0) > self.threshold:
+            if abs(x - x0) > threshold:
if self.debug:
warn("x (%f) - x0 (%f) = %f" % (x, x0, abs(x-x0)))
return None
-            if abs(y - y0) > self.threshold:
+            if abs(y - y0) > threshold:
if self.debug:
warn("y (%f) - y0 (%f) = %f" % (y, y0, abs(y-y0)))
return None

Debugging TileCache can be difficult, because there's both the client
and the server to consider. I hope that this will help sort out some of
the issues we've been seeing.

SDE

```