cur.execute("select minlat,minlon,maxlat,maxlon from tracks where filename=?" , (filename.decode('UTF-8'),))
minlat,minlon,maxlat,maxlon=cur.fetchone()
queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom)
+
+def deg2num(lat_deg, lon_deg, zoom):
+ lat_rad = math.radians(lat_deg)
+ n = 2.0 ** zoom
+ xtile = int((lon_deg + 180.0) / 360.0 * n)
+ ytile = int((1.0 - math.log(math.tan(lat_rad) + (1 / math.cos(lat_rad))) / math.pi) / 2.0 * n)
+ return (xtile, ytile)
def queue_tiles(db,minlat,minlon,maxlat,maxlon,forced_max_zoom=None):
# определяем примерный стартовый зум
minzoom=8
+
if forced_max_zoom:
maxzoom=forced_max_zoom
else:
- maxzoom=16
+ maxzoom=minzoom
+ while True:
+ minx,miny=deg2num(minlat,minlon,maxzoom)
+ maxx,maxy=deg2num(maxlat,maxlon,maxzoom)
+ print maxzoom,':',minx,'-',maxx,'/',miny,'-',maxy
+ if (maxx-minx>32) or (maxy-miny>24) or (maxzoom==16):
+ break
+ else:
+ maxzoom=maxzoom+1
ins = conn.cursor()
print minlat,maxlat,minlon,maxlon,minzoom,maxzoom