From: Roman Bazalevsky Date: Thu, 31 Jul 2014 10:29:23 +0000 (+0400) Subject: OSM tile rendering queue added X-Git-Url: https://git.rvb.name/pyrungps.git/commitdiff_plain/b8e66f213d0df36cb584685a34276d8c45882e71?ds=sidebyside;hp=042560b8c13519340e3a53006adcb8186136cf7d OSM tile rendering queue added --- diff --git a/render_tiles.py b/render_tiles.py new file mode 100644 index 0000000..1c57b0b --- /dev/null +++ b/render_tiles.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# coding: UTF-8 + +import sqlite3 + +import math + +def queue_render(db,filename): + + conn = sqlite3.connect(db) + cur = conn.cursor() + + cur.execute("select minlat,minlon,maxlat,maxlon from tracks where filename=?" , (filename.decode('UTF-8'),)) + + minlat,minlon,maxlat,maxlon=cur.fetchone() + + # определяем примерный стартовый зум + + minlatrad = math.radians(minlat) + maxlatrad = math.radians(maxlat) + + minx = (minlon + 180.0)/360.0 + maxx = (maxlon + 180.0)/360.0 + + miny = (1.0 - math.log(math.tan(minlatrad) + (1 / math.cos(minlatrad))) / math.pi) / 2.0 + maxy = (1.0 - math.log(math.tan(maxlatrad) + (1 / math.cos(maxlatrad))) / math.pi) / 2.0 + + if minx>maxx: + minx,maxx = maxx,minx + + if miny>maxy: + miny,maxy = maxy,miny + + for zoom in range(9,16): + + n = 2 ** zoom + + minxt = int(minx * n) + minyt = int(miny * n) + maxxt = int(maxx * n) + maxyt = int(maxy * n) + + ins = conn.cursor() + print zoom,minxt,maxxt,minyt,maxyt + ins.execute('insert into render_queue(zoom,minx,maxx,miny,maxy) values(?,?,?,?,?)',(zoom,minxt,maxxt,minyt,maxyt)) + + if (maxxt-minxt>16) or (maxyt-minyt>12): + conn.commit() + break + + conn.commit() + \ No newline at end of file